Skip to content

Commit 362ab8e

Browse files
committed
add new settings example
1 parent 8467443 commit 362ab8e

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

content/pages/examples/django/django-code-examples.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ The code for django-angular is
7474

7575
Code from django-angular is shown on:
7676

77+
* [django.conf settings](/django-conf-settings-examples.html)
7778
* [django.utils.html format_html](/django-utils-html-format-html-examples.html)
7879
* [django.urls.exceptions NoReverseMatch](/django-urls-exceptions-noreversematch-examples.html)
7980

content/pages/examples/django/django-conf-settings-examples.markdown

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,64 @@ class Settings(object):
466466

467467
conf = 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+
```

content/pages/examples/django/django-urls-exceptions-noreversematch.markdown

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ is a library with helper code to make it easier to use
3131
The code for django-angular is
3232
[open source under the MIT license](https://github.com/jrief/django-angular/blob/master/LICENSE.txt).
3333

34-
3534
[**django-angular / djng / core / urlresolvers.py**](https://github.com/jrief/django-angular/blob/master/djng/core/urlresolvers.py)
3635

37-
3836
```python
3937
# -*- coding: utf-8 -*-
4038
from __future__ import unicode_literals

0 commit comments

Comments
 (0)