|
8 | 8 | """ |
9 | 9 |
|
10 | 10 | import os |
11 | | - |
12 | | -# For importing schema |
13 | | -from api.scripts.utilities import SettingsUtils |
14 | | - |
15 | 11 | # For importing configuration files |
16 | 12 | import configparser |
| 13 | +# For importing schema |
| 14 | +from api.scripts.utilities import SettingsUtils |
17 | 15 |
|
18 | 16 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
19 | 17 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|
50 | 48 | # Source: https://dzone.com/articles/how-to-fix-django-cors-error |
51 | 49 |
|
52 | 50 | # Check for open (public) access to the API. |
53 | | -if(server_config['REQUESTS_FROM']['public'].strip() == 'false'): |
| 51 | +if server_config['REQUESTS_FROM']['public'].strip() == 'false': |
54 | 52 |
|
55 | 53 | # Process the requester groups. |
56 | 54 |
|
|
63 | 61 | # Flatten the list. |
64 | 62 | # Source: https://stackabuse.com/python-how-to-flatten-list-of-lists/ |
65 | 63 | flattened = [item.strip() for sublist in requesters for item in sublist] |
66 | | - |
| 64 | + |
67 | 65 | if server_config['PRODUCTION']['production'] == 'True': |
68 | 66 | ALLOWED_HOSTS = [i.strip() for i in server_config['HOSTNAMES']['prod_names'].split(',')] |
69 | 67 | elif server_config['PRODUCTION']['production'] == 'False': |
70 | 68 | ALLOWED_HOSTS = [i.strip() for i in server_config['HOSTNAMES']['names'].split(',')] |
71 | | - |
| 69 | + |
72 | 70 | CORS_ORIGIN_ALLOW_ALL = False |
73 | 71 | CORS_ORIGIN_WHITELIST = tuple(flattened) |
74 | | - |
75 | | -elif(server_config['REQUESTS_FROM']['public'].strip() == 'true'): |
| 72 | + |
| 73 | +elif server_config['REQUESTS_FROM']['public'].strip() == 'true': |
76 | 74 | if server_config['PRODUCTION']['production'] == 'True': |
77 | 75 | ALLOWED_HOSTS = [server_config['HOSTNAMES']['prod_names'].split(',')[0],'*'] |
78 | 76 | CORS_ORIGIN_ALLOW_ALL = True |
|
90 | 88 | 'DEFAULT_PERMISSION_CLASSES': [ |
91 | 89 | 'rest_framework.permissions.IsAuthenticated' |
92 | 90 | ], |
93 | | - 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema' |
| 91 | + 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema' |
94 | 92 | } |
95 | 93 |
|
96 | 94 | # Password validation |
|
218 | 216 | STATIC_ROOT = '/var/www/bcoeditor/bco_api/bco_api/static/' |
219 | 217 |
|
220 | 218 | # ----- CUSTOM VARIABLES AND METHODS ----- # |
221 | | - |
222 | | - |
223 | | - |
224 | | - |
225 | 219 | # Load request and validation templates (definitions). |
226 | | - |
227 | 220 | # Note that we will get TWO loads of settings.py if we start without runserver --noreload |
228 | | - |
229 | 221 | # There is only set of definitions for requests, but for validations, we may have sub-folders. |
230 | | - |
231 | 222 | # First, the request definitions. |
232 | 223 | REQUEST_TEMPLATES = SettingsUtils.SettingsUtils().load_schema_local(search_parameters={ |
233 | 224 | 'request_definitions/': '.schema' |
|
248 | 239 | OBJECT_NAMING = {} |
249 | 240 |
|
250 | 241 | if server_config['PRODUCTION']['production'] == 'True': |
251 | | - |
| 242 | + |
252 | 243 | for i in server_config['OBJECT_NAMING']: |
253 | 244 | if i.split('_')[0] == 'prod': |
254 | | - |
| 245 | + |
255 | 246 | # Strip out the production flag. |
256 | | - stripped = '_'.join(i.split('_')[1:]) |
257 | | - |
258 | | - OBJECT_NAMING[stripped] = server_config['OBJECT_NAMING'][i] |
| 247 | + STRIPPED = '_'.join(i.split('_')[1:]) |
| 248 | + |
| 249 | + OBJECT_NAMING[STRIPPED] = server_config['OBJECT_NAMING'][i] |
259 | 250 |
|
260 | 251 | elif server_config['PRODUCTION']['production'] == 'False': |
261 | 252 |
|
|
269 | 260 | EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' |
270 | 261 | EMAIL_HOST = 'localhost' |
271 | 262 | EMAIL_PORT = 25 |
272 | | - |
0 commit comments