forked from jozo/djangorestframework-camel-case2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
45 lines (33 loc) · 1.18 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from rest_framework.settings import APISettings
USER_SETTINGS = getattr(settings, 'JSON_CAMEL_CASE', {})
DEFAULTS = {
'RENDERER_CLASS': 'rest_framework.renderers.JSONRenderer',
'PARSER_CLASS': 'rest_framework.parsers.JSONParser',
'JSON_UNDERSCOREIZE': {
'no_underscore_before_number': False,
},
}
# List of settings that may be in string import notation.
IMPORT_STRINGS = (
'RENDERER_CLASS',
'PARSER_CLASS'
)
VALID_SETTINGS = {
'RENDERER_CLASS': (
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.UnicodeJSONRenderer',
),
'PARSER_CLASS': (
'rest_framework.parsers.JSONParser',
)
}
def validate_settings(input_settings, valid_settings):
for setting_name, valid_values in valid_settings.items():
input_setting = input_settings.get(setting_name)
if input_setting and input_setting not in valid_values:
raise ImproperlyConfigured(setting_name)
validate_settings(USER_SETTINGS, VALID_SETTINGS)
api_settings = APISettings(USER_SETTINGS, DEFAULTS, IMPORT_STRINGS)