@@ -466,3 +466,64 @@ class Settings(object):
466466
467467conf = Settings()
468468```
469+
470+
471+ ## Example 4 from django-angular
472+ [ django-angular] ( https://github.com/jrief/django-angular )
473+ ([ project examples website] ( https://django-angular.awesto.com/classic_form/ ) )
474+ is a library with helper code to make it easier to use
475+ [ Angular] ( /angular.html ) as the front-end to [ Django] ( /django.html ) projects.
476+ The code for django-angular is
477+ [ open source under the MIT license] ( https://github.com/jrief/django-angular/blob/master/LICENSE.txt ) .
478+
479+ The following example shows how to check if an Django app is specified
480+ under ` INSTALLED_APPS ` and if not, throw an exception to let the developer
481+ know their project is not properly configured.
482+
483+ [ ** django-angular / djng / forms / fields.py** ] ( https://github.com/jrief/django-angular/blob/master/djng/forms/fields.py )
484+
485+ ``` python
486+ # -*- coding: utf-8 -*-
487+ from __future__ import unicode_literals
488+
489+ import re
490+ import mimetypes
491+
492+ ~~ from django.conf import settings
493+ from django.contrib.staticfiles.storage import staticfiles_storage
494+ from django.core import signing
495+ from django.core.exceptions import ImproperlyConfigured, ValidationError
496+ from django.core.files.storage import default_storage
497+ from django.core.files.uploadedfile import InMemoryUploadedFile, TemporaryUploadedFile
498+ from django.urls import reverse_lazy
499+ from django.forms import fields, models as model_fields, widgets
500+ from django.utils.html import format_html
501+ from django.utils.module_loading import import_string
502+ from django.utils.safestring import mark_safe
503+ from django.utils.translation import ugettext_lazy as _, ungettext_lazy
504+
505+ # # ... source code lines cut here for brevity ...
506+
507+
508+ class ImageField (FileFieldMixin , fields .ImageField ):
509+ storage = app_settings.upload_storage
510+ signer = signing.Signer()
511+
512+ def __init__ (self , * args , ** kwargs ):
513+ ~~ if ' easy_thumbnails' not in settings.INSTALLED_APPS :
514+ ~~ raise ImproperlyConfigured(" 'djng.forms.fields.ImageField' \
515+ ~~ requires 'easy-thubnails' to be installed" )
516+ accept = kwargs.pop(' accept' , ' image/*' )
517+ fileupload_url = kwargs.pop(' fileupload_url' ,
518+ reverse_lazy(' fileupload' ))
519+ area_label = kwargs.pop(' area_label' ,
520+ _(" Drop image here or click to upload" ))
521+ attrs = {
522+ ' accept' : accept,
523+ ' ngf-pattern' : accept,
524+ }
525+ kwargs.update(widget = DropImageWidget(area_label,
526+ fileupload_url,
527+ attrs = attrs))
528+ super (ImageField, self ).__init__ (* args, ** kwargs)
529+ ```
0 commit comments