├── .pypirc ├── tests ├── __init__.py └── test_fields.py ├── MANIFEST.in ├── drf_extra_fields ├── __init__.py ├── runtests │ ├── __init__.py │ ├── urls.py │ ├── runtests.py │ └── settings.py ├── geo_fields.py └── fields.py ├── requirements.txt ├── .gitignore ├── tox.ini ├── .travis.yml ├── setup.py ├── README.md └── LICENSE /.pypirc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md -------------------------------------------------------------------------------- /drf_extra_fields/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /drf_extra_fields/runtests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Django >= 1.4 2 | djangorestframework >= 3.0.1 3 | pillow -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | !.gitignore 3 | dist/ 4 | env/ 5 | dist/ 6 | *.egg-info 7 | .idea 8 | .pypirc 9 | .tox/ 10 | -------------------------------------------------------------------------------- /drf_extra_fields/runtests/urls.py: -------------------------------------------------------------------------------- 1 | """ 2 | Blank URLConf just to keep runtests.py happy. 3 | """ 4 | from rest_framework.compat import patterns 5 | 6 | urlpatterns = patterns('', 7 | ) 8 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27,py34 3 | 4 | [testenv] 5 | deps = 6 | django 7 | djangorestframework>=3.0 8 | Pillow 9 | commands = {envpython} {toxinidir}/drf_extra_fields/runtests/runtests.py 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | env: 4 | - TESTENV=py27 5 | - TESTENV=py34 6 | 7 | install: 8 | - pip install tox 9 | 10 | script: 11 | - tox -e $TESTENV 12 | 13 | notifications: 14 | email: false 15 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | from setuptools import setup 3 | 4 | with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme: 5 | README = readme.read() 6 | 7 | # allow setup.py to be run from any path 8 | os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) 9 | 10 | setup( 11 | name='django-extra-fields', 12 | version='0.3', 13 | packages=['drf_extra_fields', 14 | 'drf_extra_fields.runtests', 15 | ], 16 | include_package_data=True, 17 | license='License', # example license 18 | description='Additional fields for Django Rest Framework.', 19 | long_description=README, 20 | author='hipo', 21 | author_email='pypi@hipolabs.com', 22 | classifiers=[ 23 | 'Environment :: Web Environment', 24 | 'Framework :: Django', 25 | 'Intended Audience :: Developers', 26 | 'Operating System :: OS Independent', 27 | 'Programming Language :: Python', 28 | 'Topic :: Internet :: WWW/HTTP', 29 | 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /drf_extra_fields/runtests/runtests.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | sys.path.append(os.path.join(os.path.dirname(__file__), 5 | os.pardir, os.pardir)) 6 | os.environ['DJANGO_SETTINGS_MODULE'] = 'drf_extra_fields.runtests.settings' 7 | 8 | import django 9 | from django.conf import settings 10 | from django.test.utils import get_runner 11 | 12 | 13 | def usage(): 14 | return """ 15 | Usage: python runtests.py [UnitTestClass].[method] 16 | 17 | You can pass the Class name of the `UnitTestClass` you want to test. 18 | 19 | Append a method name if you only want to test a specific method of 20 | that class. 21 | """ 22 | 23 | 24 | def main(): 25 | try: 26 | django.setup() 27 | except AttributeError: 28 | pass 29 | TestRunner = get_runner(settings) 30 | 31 | test_runner = TestRunner() 32 | if len(sys.argv) == 2: 33 | test_case = '.' + sys.argv[1] 34 | elif len(sys.argv) == 1: 35 | test_case = '' 36 | else: 37 | print(usage()) 38 | sys.exit(1) 39 | test_module_name = 'tests' 40 | if django.VERSION[0] == 1 and django.VERSION[1] < 6: 41 | test_module_name = 'drf_extra_fields.runtests' 42 | 43 | failures = test_runner.run_tests([test_module_name + test_case]) 44 | 45 | sys.exit(failures) 46 | 47 | if __name__ == '__main__': 48 | main() 49 | -------------------------------------------------------------------------------- /drf_extra_fields/geo_fields.py: -------------------------------------------------------------------------------- 1 | import json 2 | from django.contrib.gis.geos import GEOSGeometry 3 | from django.utils.encoding import smart_str 4 | from django.utils import six 5 | from django.utils.translation import ugettext_lazy as _ 6 | 7 | from rest_framework import serializers 8 | 9 | EMPTY_VALUES = (None, '', [], (), {}) 10 | 11 | 12 | class PointField(serializers.Field): 13 | """ 14 | A field for handling GeoDjango Point fields as a json format. 15 | Expected input format: 16 | { 17 | "latitude": 49.8782482189424, 18 | "longitude": 24.452545489 19 | } 20 | 21 | """ 22 | type_name = 'PointField' 23 | type_label = 'point' 24 | 25 | default_error_messages = { 26 | 'invalid': _('Location field has wrong format.' 27 | ' Use {"latitude": 45.67294621, "longitude": 26.43156}'), 28 | } 29 | 30 | def to_internal_value(self, value): 31 | """ 32 | Parse json data and return a point object 33 | """ 34 | if value in EMPTY_VALUES: 35 | return None 36 | 37 | if isinstance(value, six.string_types): 38 | try: 39 | value = value.replace("'", '"') 40 | value = json.loads(value) 41 | except ValueError: 42 | msg = self.error_messages['invalid'] 43 | raise serializers.ValidationError(msg) 44 | 45 | if value and type(value) is dict: 46 | latitude = value.get("latitude") 47 | longitude = value.get("longitude") 48 | if latitude and longitude: 49 | point_object = GEOSGeometry( 50 | 'POINT(%(longitude)s %(latitude)s)' % { 51 | "longitude": longitude, 52 | "latitude": latitude, 53 | }) 54 | return point_object 55 | else: 56 | msg = self.error_messages['invalid'] 57 | raise serializers.ValidationError(msg) 58 | 59 | def to_representation(self, value): 60 | """ 61 | Transform POINT object to json. 62 | """ 63 | if value is None: 64 | return value 65 | 66 | if isinstance(value, GEOSGeometry): 67 | value = { 68 | "latitude": smart_str(value.y), 69 | "longitude": smart_str(value.x) 70 | } 71 | return value 72 | -------------------------------------------------------------------------------- /drf_extra_fields/fields.py: -------------------------------------------------------------------------------- 1 | import base64 2 | import binascii 3 | import imghdr 4 | import uuid 5 | import sys 6 | from django.core.exceptions import ValidationError 7 | from django.core.files.base import ContentFile 8 | from django.utils import six 9 | from django.utils.translation import ugettext_lazy as _ 10 | 11 | from rest_framework.fields import ImageField 12 | 13 | 14 | DEFAULT_CONTENT_TYPE = "application/octet-stream" 15 | ALLOWED_IMAGE_TYPES = ( 16 | "jpeg", 17 | "jpg", 18 | "png", 19 | "gif" 20 | ) 21 | 22 | EMPTY_VALUES = (None, '', [], (), {}) 23 | 24 | # Python 3 Compatibility 25 | # Issue: basestring in Python3 raises a NameError exception! 26 | import types 27 | try: 28 | unicode = unicode 29 | except NameError: 30 | # 'unicode' is undefined, must be Python 3 31 | str = str 32 | unicode = str 33 | bytes = bytes 34 | basestring = (str,bytes) 35 | else: 36 | # 'unicode' exists, must be Python 2 37 | str = str 38 | unicode = unicode 39 | bytes = str 40 | basestring = basestring 41 | 42 | class Base64ImageField(ImageField): 43 | """ 44 | A django-rest-framework field for handling image-uploads through raw post data. 45 | It uses base64 for en-/decoding the contents of the file. 46 | """ 47 | def to_internal_value(self, base64_data): 48 | # Check if this is a base64 string 49 | if base64_data in EMPTY_VALUES: 50 | return None 51 | 52 | if isinstance(base64_data, six.string_types): 53 | # Try to decode the file. Return validation error if it fails. 54 | try: 55 | decoded_file = base64.b64decode(base64_data) 56 | except (TypeError, binascii.Error): 57 | raise ValidationError(_("Please upload a valid image.")) 58 | # Generate file name: 59 | file_name = str(uuid.uuid4())[:12] # 12 characters are more than enough. 60 | # Get the file name extension: 61 | file_extension = self.get_file_extension(file_name, decoded_file) 62 | if file_extension not in ALLOWED_IMAGE_TYPES: 63 | raise ValidationError(_("The type of the image couldn't been determined.")) 64 | complete_file_name = file_name + "." + file_extension 65 | data = ContentFile(decoded_file, name=complete_file_name) 66 | return super(Base64ImageField, self).to_internal_value(data) 67 | raise ValidationError(_('This is not an base64 string')) 68 | 69 | def to_representation(self, value): 70 | # Return url including domain name. 71 | return value.name 72 | 73 | def get_file_extension(self, filename, decoded_file): 74 | extension = imghdr.what(filename, decoded_file) 75 | extension = "jpg" if extension == "jpeg" else extension 76 | return extension 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DRF-EXTRA-FIELDS 2 | ================ 3 | 4 | Extra Fields for Django Rest Framework 5 | 6 | ![https://travis-ci.org/Hipo/drf-extra-fields.svg?branch=master](https://travis-ci.org/Hipo/drf-extra-fields.svg?branch=master) 7 | 8 | Usage 9 | ================ 10 | 11 | install the package 12 | 13 | ```bash 14 | pip install django-extra-fields 15 | ``` 16 | 17 | **Note:** 18 | - Install version 0.1 for Django Rest Framework 2.* 19 | - Install version 0.3 for Django Rest Framework 3.* 20 | 21 | 22 | Fields: 23 | ---------------- 24 | 25 | 26 | ## Base64ImageField 27 | 28 | An image representation for Base64ImageField 29 | 30 | Intherited by `ImageField` 31 | 32 | 33 | **Signature:** `Base64ImageField()` 34 | 35 | - It takes a base64 image as a string. 36 | - a base64 image: `data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7` 37 | - Base64ImageField accepts only the part after base64, `R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7` 38 | 39 | 40 | **Example:** 41 | 42 | ```python 43 | # serializer 44 | 45 | from drf_extra_fields.fields import Base64ImageField 46 | 47 | class UploadedBase64ImageSerializer(serializers.Serializer): 48 | file = serializers.Base64ImageField(required=False) 49 | created = serializers.DateTimeField() 50 | 51 | # use the serializer 52 | file = 'R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' 53 | serializer = UploadedBase64ImageSerializer(data={'created': now, 'file': file}) 54 | ``` 55 | 56 | 57 | ## PointField 58 | 59 | Point field for GeoDjango 60 | 61 | 62 | **Signature:** `PointField()` 63 | 64 | - It takes a dictionary contains latitude and longitude keys like below 65 | 66 | { 67 | "latitude": 49.8782482189424, 68 | "longitude": 24.452545489 69 | } 70 | 71 | **Example:** 72 | 73 | ```python 74 | # serializer 75 | 76 | from drf_extra_fields.geo_fields import PointField 77 | 78 | class PointFieldSerializer(serializers.Serializer): 79 | point = PointField(required=False) 80 | created = serializers.DateTimeField() 81 | 82 | # use the serializer 83 | point = { 84 | "latitude": 49.8782482189424, 85 | "longitude": 24.452545489 86 | } 87 | serializer = PointFieldSerializer(data={'created': now, 'point': point}) 88 | ``` 89 | 90 | CONTRIBUTION 91 | ================= 92 | 93 | *TESTS* 94 | - Make sure that you add the test for contributed field to test/test_fields.py 95 | and run with command before sending a pull request: 96 | 97 | ```bash 98 | $ pip install tox # if not already installed 99 | $ tox 100 | ``` 101 | 102 | *README* 103 | - Make sure that you add the documentation for the field added to README.md 104 | 105 | 106 | LICENSE 107 | ==================== 108 | 109 | Copyright DRF EXTRA FIELDS HIPO 110 | 111 | Licensed under the Apache License, Version 2.0 (the "License"); 112 | you may not use this file except in compliance with the License. 113 | You may obtain a copy of the License at 114 | 115 | http://www.apache.org/licenses/LICENSE-2.0 116 | 117 | Unless required by applicable law or agreed to in writing, software 118 | distributed under the License is distributed on an "AS IS" BASIS, 119 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 120 | See the License for the specific language governing permissions and 121 | limitations under the License. 122 | -------------------------------------------------------------------------------- /tests/test_fields.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | from django.test import TestCase 3 | from rest_framework import serializers 4 | from drf_extra_fields.geo_fields import PointField 5 | from drf_extra_fields.fields import Base64ImageField 6 | 7 | 8 | class UploadedBase64Image(object): 9 | def __init__(self, file=None, created=None): 10 | self.file = file 11 | self.created = created or datetime.datetime.now() 12 | 13 | 14 | class UploadedBase64ImageSerializer(serializers.Serializer): 15 | file = Base64ImageField(required=False) 16 | created = serializers.DateTimeField() 17 | 18 | def update(self, instance, validated_data): 19 | instance.file = validated_data['file'] 20 | return instance 21 | 22 | def create(self, validated_data): 23 | return UploadedBase64Image(**validated_data) 24 | 25 | 26 | class Base64ImageSerializerTests(TestCase): 27 | 28 | def test_create(self): 29 | """ 30 | Test for creating Base64 image in the server side 31 | """ 32 | now = datetime.datetime.now() 33 | file = 'R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' 34 | serializer = UploadedBase64ImageSerializer(data={'created': now, 'file': file}) 35 | uploaded_image = UploadedBase64Image(file=file, created=now) 36 | self.assertTrue(serializer.is_valid()) 37 | self.assertEqual(serializer.validated_data['created'], uploaded_image.created) 38 | self.assertFalse(serializer.validated_data is uploaded_image) 39 | 40 | def test_validation_error_with_non_file(self): 41 | """ 42 | Passing non-base64 should raise a validation error. 43 | """ 44 | now = datetime.datetime.now() 45 | errmsg = "Please upload a valid image." 46 | serializer = UploadedBase64ImageSerializer(data={'created': now, 47 | 'file': 'abc'}) 48 | self.assertFalse(serializer.is_valid()) 49 | self.assertEqual(serializer.errors, {'file': [errmsg]}) 50 | 51 | def test_remove_with_empty_string(self): 52 | """ 53 | Passing empty string as data should cause image to be removed 54 | """ 55 | now = datetime.datetime.now() 56 | file = 'R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' 57 | uploaded_image = UploadedBase64Image(file=file, created=now) 58 | serializer = UploadedBase64ImageSerializer(instance=uploaded_image, data={'created': now, 'file': ''}) 59 | self.assertTrue(serializer.is_valid()) 60 | self.assertEqual(serializer.validated_data['created'], uploaded_image.created) 61 | self.assertIsNone(serializer.validated_data['file']) 62 | 63 | 64 | class SavePoint(object): 65 | def __init__(self, point=None, created=None): 66 | self.point = point 67 | self.created = created or datetime.datetime.now() 68 | 69 | 70 | class PointSerializer(serializers.Serializer): 71 | point = PointField(required=False) 72 | created = serializers.DateTimeField() 73 | 74 | def update(self, instance, validated_data): 75 | instance.point = validated_data['point'] 76 | return instance 77 | 78 | def create(self, validated_data): 79 | return SavePoint(**validated_data) 80 | 81 | 82 | class PointSerializerTest(TestCase): 83 | 84 | def test_create(self): 85 | """ 86 | Test for creating Point field in the server side 87 | """ 88 | now = datetime.datetime.now() 89 | point = { 90 | "latitude": 49.8782482189424, 91 | "longitude": 24.452545489 92 | } 93 | serializer = PointSerializer(data={'created': now, 'point': point}) 94 | saved_point = SavePoint(point=point, created=now) 95 | self.assertTrue(serializer.is_valid()) 96 | self.assertEqual(serializer.validated_data['created'], saved_point.created) 97 | self.assertFalse(serializer.validated_data is saved_point) 98 | 99 | def test_validation_error_with_non_file(self): 100 | """ 101 | Passing non-dict contains latitude and longitude should raise a validation error. 102 | """ 103 | now = datetime.datetime.now() 104 | serializer = PointSerializer(data={'created': now, 'point': '123'}) 105 | self.assertFalse(serializer.is_valid()) 106 | 107 | def test_remove_with_empty_string(self): 108 | """ 109 | Passing empty string as data should cause point to be removed 110 | """ 111 | now = datetime.datetime.now() 112 | point = { 113 | "latitude": 49.8782482189424, 114 | "longitude": 24.452545489 115 | } 116 | saved_point = SavePoint(point=point, created=now) 117 | serializer = PointSerializer(data={'created': now, 'point': ''}) 118 | self.assertTrue(serializer.is_valid()) 119 | self.assertEqual(serializer.validated_data['created'], saved_point.created) 120 | self.assertIsNone(serializer.validated_data['point']) 121 | -------------------------------------------------------------------------------- /drf_extra_fields/runtests/settings.py: -------------------------------------------------------------------------------- 1 | # Django settings for testproject project. 2 | 3 | DEBUG = True 4 | TEMPLATE_DEBUG = DEBUG 5 | DEBUG_PROPAGATE_EXCEPTIONS = True 6 | 7 | ALLOWED_HOSTS = ['*'] 8 | 9 | ADMINS = ( 10 | # ('Your Name', 'your_email@domain.com'), 11 | ) 12 | 13 | MANAGERS = ADMINS 14 | 15 | DATABASES = { 16 | 'default': { 17 | 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 18 | 'NAME': 'sqlite.db', # Or path to database file if using sqlite3. 19 | 'USER': '', # Not used with sqlite3. 20 | 'PASSWORD': '', # Not used with sqlite3. 21 | 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 22 | 'PORT': '', # Set to empty string for default. Not used with sqlite3. 23 | } 24 | } 25 | 26 | CACHES = { 27 | 'default': { 28 | 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 29 | } 30 | } 31 | 32 | # Local time zone for this installation. Choices can be found here: 33 | # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name 34 | # although not all choices may be available on all operating systems. 35 | # On Unix systems, a value of None will cause Django to use the same 36 | # timezone as the operating system. 37 | # If running in a Windows environment this must be set to the same as your 38 | # system time zone. 39 | TIME_ZONE = 'Europe/London' 40 | 41 | # Language code for this installation. All choices can be found here: 42 | # http://www.i18nguy.com/unicode/language-identifiers.html 43 | LANGUAGE_CODE = 'en-uk' 44 | 45 | SITE_ID = 1 46 | 47 | # If you set this to False, Django will make some optimizations so as not 48 | # to load the internationalization machinery. 49 | USE_I18N = True 50 | 51 | # If you set this to False, Django will not format dates, numbers and 52 | # calendars according to the current locale 53 | USE_L10N = True 54 | 55 | # Absolute filesystem path to the directory that will hold user-uploaded files. 56 | # Example: "/home/media/media.lawrence.com/" 57 | MEDIA_ROOT = '' 58 | 59 | # URL that handles the media served from MEDIA_ROOT. Make sure to use a 60 | # trailing slash if there is a path component (optional in other cases). 61 | # Examples: "http://media.lawrence.com", "http://example.com/media/" 62 | MEDIA_URL = '' 63 | 64 | # Make this unique, and don't share it with anybody. 65 | SECRET_KEY = 'u@x-aj9(hoh#rb-^ymf#g2jx_hp0vj7u5#b@ag1n^seu9e!%cy' 66 | 67 | # List of callables that know how to import templates from various sources. 68 | TEMPLATE_LOADERS = ( 69 | 'django.template.loaders.filesystem.Loader', 70 | 'django.template.loaders.app_directories.Loader', 71 | # 'django.template.loaders.eggs.Loader', 72 | ) 73 | 74 | MIDDLEWARE_CLASSES = ( 75 | 'django.middleware.common.CommonMiddleware', 76 | 'django.contrib.sessions.middleware.SessionMiddleware', 77 | 'django.middleware.csrf.CsrfViewMiddleware', 78 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 79 | 'django.contrib.messages.middleware.MessageMiddleware', 80 | ) 81 | 82 | ROOT_URLCONF = 'urls' 83 | 84 | TEMPLATE_DIRS = ( 85 | # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". 86 | # Always use forward slashes, even on Windows. 87 | # Don't forget to use absolute paths, not relative paths. 88 | ) 89 | 90 | INSTALLED_APPS = ( 91 | 'django.contrib.auth', 92 | 'django.contrib.contenttypes', 93 | 'django.contrib.sessions', 94 | 'django.contrib.sites', 95 | 'django.contrib.messages', 96 | # Uncomment the next line to enable the admin: 97 | # 'django.contrib.admin', 98 | # Uncomment the next line to enable admin documentation: 99 | # 'django.contrib.admindocs', 100 | 'rest_framework', 101 | 'rest_framework.authtoken', 102 | # 'rest_framework.tests', 103 | # 'rest_framework.tests.accounts', 104 | # 'rest_framework.tests.records', 105 | # 'rest_framework.tests.users', 106 | ) 107 | 108 | # OAuth is optional and won't work if there is no oauth_provider & oauth2 109 | try: 110 | import oauth_provider 111 | import oauth2 112 | except ImportError: 113 | pass 114 | else: 115 | INSTALLED_APPS += ( 116 | 'oauth_provider', 117 | ) 118 | 119 | try: 120 | import provider 121 | except ImportError: 122 | pass 123 | else: 124 | INSTALLED_APPS += ( 125 | 'provider', 126 | 'provider.oauth2', 127 | ) 128 | 129 | # guardian is optional 130 | try: 131 | import guardian 132 | except ImportError: 133 | pass 134 | else: 135 | ANONYMOUS_USER_ID = -1 136 | AUTHENTICATION_BACKENDS = ( 137 | 'django.contrib.auth.backends.ModelBackend', # default 138 | 'guardian.backends.ObjectPermissionBackend', 139 | ) 140 | INSTALLED_APPS += ( 141 | 'guardian', 142 | ) 143 | 144 | STATIC_URL = '/static/' 145 | 146 | PASSWORD_HASHERS = ( 147 | 'django.contrib.auth.hashers.SHA1PasswordHasher', 148 | 'django.contrib.auth.hashers.PBKDF2PasswordHasher', 149 | 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', 150 | 'django.contrib.auth.hashers.BCryptPasswordHasher', 151 | 'django.contrib.auth.hashers.MD5PasswordHasher', 152 | 'django.contrib.auth.hashers.CryptPasswordHasher', 153 | ) 154 | 155 | AUTH_USER_MODEL = 'auth.User' 156 | 157 | import django 158 | 159 | if django.VERSION < (1, 3): 160 | INSTALLED_APPS += ('staticfiles',) 161 | 162 | # If we're running on the Jenkins server we want to archive the coverage reports as XML. 163 | import os 164 | if os.environ.get('HUDSON_URL', None): 165 | TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner' 166 | TEST_OUTPUT_VERBOSE = True 167 | TEST_OUTPUT_DESCRIPTIONS = True 168 | TEST_OUTPUT_DIR = 'xmlrunner' 169 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------