|
1 | 1 | """
|
2 |
| -Django settings for odm2cvs project. |
| 2 | +Django settings for djangoProject project. |
| 3 | +
|
| 4 | +Generated by 'django-admin startproject' using Django 3.1.2. |
3 | 5 |
|
4 | 6 | For more information on this file, see
|
5 |
| -https://docs.djangoproject.com/en/1.7/topics/settings/ |
| 7 | +https://docs.djangoproject.com/en/3.1/topics/settings/ |
6 | 8 |
|
7 | 9 | For the full list of settings and their values, see
|
8 |
| -https://docs.djangoproject.com/en/1.7/ref/settings/ |
| 10 | +https://docs.djangoproject.com/en/3.1/ref/settings/ |
9 | 11 |
|
10 | 12 | To setup the settings json file:
|
11 | 13 | 1. rename settings_template.json to settings.json
|
|
14 | 16 | 4. Profit!
|
15 | 17 | """
|
16 | 18 |
|
17 |
| - |
18 |
| -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
19 |
| -import os |
| 19 | +import sys |
20 | 20 | import json
|
| 21 | +from pathlib import Path |
| 22 | + |
| 23 | +# Build paths inside the project like this: BASE_DIR / 'subdir'. |
| 24 | +from typing import Dict, Any, TextIO, List, Tuple, Union |
21 | 25 |
|
22 |
| -BASE_DIR = os.path.dirname(os.path.dirname(__file__)) |
| 26 | +BASE_DIR: Path = Path(__file__).resolve().parent.parent |
| 27 | + |
| 28 | + |
| 29 | +config: Dict[str, Any] = {} |
23 | 30 |
|
24 |
| -data = {} |
25 | 31 | try:
|
26 |
| - with open(os.path.join(BASE_DIR, 'settings', 'settings.json')) as data_file: |
27 |
| - data = json.load(data_file) |
28 |
| -except IOError: |
29 |
| - print("You need to setup the settings data file (see instructions in base.py file.)") |
| 32 | + data_file: TextIO |
| 33 | + with open(BASE_DIR / 'settings' / 'settings.json') as data_file: |
| 34 | + config = json.load(data_file) |
| 35 | +except IOError as ioe: |
| 36 | + sys.exit('You need to setup the settings data file (see instructions in base.py file.)') |
30 | 37 |
|
31 | 38 |
|
32 | 39 | try:
|
33 |
| - SECRET_KEY = data["secret_key"] |
| 40 | + SECRET_KEY: str = config['secret_key'] |
34 | 41 | except KeyError:
|
35 |
| - print("The secret key is required in the settings.json file.") |
36 |
| - exit(1) |
| 42 | + print() |
| 43 | + exit('The secret key is required in the settings.json file.') |
37 | 44 |
|
38 |
| -RECAPTCHA_KEY = data["recaptcha_secret_key"] if "recaptcha_secret_key" in data else "" |
39 |
| -RECAPTCHA_USER_KEY = data["recaptcha_user_key"] if "recaptcha_user_key" in data else "" |
40 |
| -RECAPTCHA_VERIFY_URL = "https://www.google.com/recaptcha/api/siteverify" |
| 45 | +RECAPTCHA_KEY: str = config['recaptcha_secret_key'] if 'recaptcha_secret_key' in config else '' |
| 46 | +RECAPTCHA_USER_KEY: str = config['recaptcha_user_key'] if 'recaptcha_user_key' in config else '' |
| 47 | +RECAPTCHA_VERIFY_URL: str = 'https://www.google.com/recaptcha/api/siteverify' |
41 | 48 |
|
42 |
| -ALLOWED_HOSTS = [] |
| 49 | +ALLOWED_HOSTS: List[str] = [] |
43 | 50 |
|
44 | 51 |
|
45 | 52 | # Application definition
|
46 | 53 |
|
47 |
| -INSTALLED_APPS = [ |
| 54 | +INSTALLED_APPS: List[str] = [ |
48 | 55 | 'django.contrib.admin',
|
49 | 56 | 'django.contrib.auth',
|
50 | 57 | 'django.contrib.contenttypes',
|
51 | 58 | 'django.contrib.sessions',
|
52 | 59 | 'django.contrib.messages',
|
53 | 60 | 'django.contrib.staticfiles',
|
54 |
| - 'tastypie', |
55 | 61 | 'cvservices',
|
56 | 62 | 'cvinterface',
|
57 |
| - 'rdfserializer', |
58 |
| - 'widget_tweaks', |
59 | 63 | ]
|
60 | 64 |
|
61 |
| -MIDDLEWARE_CLASSES = [ |
| 65 | +MIDDLEWARE: List[str] = [ |
62 | 66 | 'django.middleware.security.SecurityMiddleware',
|
63 | 67 | 'django.contrib.sessions.middleware.SessionMiddleware',
|
64 | 68 | 'django.middleware.common.CommonMiddleware',
|
65 | 69 | 'django.middleware.csrf.CsrfViewMiddleware',
|
66 | 70 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
|
67 |
| - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', |
68 | 71 | 'django.contrib.messages.middleware.MessageMiddleware',
|
69 | 72 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
70 | 73 | ]
|
71 | 74 |
|
72 | 75 | ROOT_URLCONF = 'odm2cvs.urls'
|
73 | 76 |
|
74 |
| -TEMPLATES = [ |
| 77 | +TEMPLATES: List[Dict[str, Any]] = [ |
75 | 78 | {
|
76 | 79 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
77 |
| - 'DIRS': [os.path.join(BASE_DIR, 'templates')] |
| 80 | + 'DIRS': [BASE_DIR / 'templates'] |
78 | 81 | ,
|
79 | 82 | 'APP_DIRS': True,
|
80 | 83 | 'OPTIONS': {
|
|
88 | 91 | },
|
89 | 92 | ]
|
90 | 93 |
|
91 |
| -WSGI_APPLICATION = 'odm2cvs.wsgi.application' |
| 94 | +WSGI_APPLICATION: str = 'odm2cvs.wsgi.application' |
92 | 95 |
|
93 | 96 |
|
94 | 97 | # Databases
|
95 |
| -DATABASES = {} |
96 |
| -for database in data['databases']: |
| 98 | +DATABASES: Dict[str, Dict[str: Any]] = {} |
| 99 | +for database in config['databases']: |
97 | 100 | DATABASES[database['name']] = {
|
98 | 101 | 'ENGINE': database['engine'],
|
99 | 102 | 'NAME': database['schema'],
|
|
105 | 108 | }
|
106 | 109 |
|
107 | 110 | # Password validation
|
108 |
| -# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators |
| 111 | +# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators |
109 | 112 |
|
110 |
| -AUTH_PASSWORD_VALIDATORS = [ |
| 113 | +AUTH_PASSWORD_VALIDATORS: List[Dict[str, str]] = [ |
111 | 114 | {
|
112 | 115 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
113 | 116 | },
|
|
124 | 127 |
|
125 | 128 | # Internationalization
|
126 | 129 |
|
127 |
| -LANGUAGE_CODE = 'en-us' |
| 130 | +LANGUAGE_CODE: str = 'en-us' |
| 131 | + |
| 132 | +TIME_ZONE: str = 'UTC' |
128 | 133 |
|
129 |
| -TIME_ZONE = 'UTC' |
| 134 | +USE_I18N: bool = True |
130 | 135 |
|
131 |
| -USE_I18N = True |
| 136 | +USE_L10N: bool = True |
132 | 137 |
|
133 |
| -USE_L10N = True |
| 138 | +USE_TZ: bool = True |
134 | 139 |
|
135 |
| -USE_TZ = True |
| 140 | +SITE_ID: int = 1 |
136 | 141 |
|
137 | 142 |
|
138 |
| -TASTYPIE_DEFAULT_FORMATS = ['json'] |
| 143 | +TASTYPIE_DEFAULT_FORMATS: List[str] = ['json'] |
139 | 144 |
|
140 |
| -API_LIMIT_PER_PAGE = 0 |
| 145 | +API_LIMIT_PER_PAGE: int = 0 |
141 | 146 |
|
142 | 147 |
|
143 |
| -EMAIL_HOST = 'mail.usu.edu' |
| 148 | +EMAIL_HOST: str = 'mail.usu.edu' |
144 | 149 |
|
145 |
| -EMAIL_SENDER = data['email_sender'] if 'email_sender' in data else '', |
146 |
| -EMAIL_SENDER = EMAIL_SENDER[0] if isinstance(EMAIL_SENDER, tuple) else EMAIL_SENDER |
| 150 | +EMAIL_SENDER: Union[Tuple, str] = config['email_sender'] if 'email_sender' in config else '', |
| 151 | +EMAIL_SENDER: str = EMAIL_SENDER[0] if isinstance(EMAIL_SENDER, tuple) else EMAIL_SENDER |
147 | 152 |
|
148 |
| -EMAIL_RECIPIENTS = list(data['email_recipients']) if 'email_recipients' in data else [], |
149 |
| -EMAIL_RECIPIENTS = EMAIL_RECIPIENTS[0] if isinstance(EMAIL_RECIPIENTS, tuple) else EMAIL_RECIPIENTS |
| 153 | +EMAIL_RECIPIENTS: Union[Tuple, str] = list(config['email_recipients']) if 'email_recipients' in config else [], |
| 154 | +EMAIL_RECIPIENTS: str = EMAIL_RECIPIENTS[0] if isinstance(EMAIL_RECIPIENTS, tuple) else EMAIL_RECIPIENTS |
150 | 155 |
|
151 |
| -EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' |
| 156 | +EMAIL_BACKEND: str = 'django.core.mail.backends.smtp.EmailBackend' |
152 | 157 |
|
153 |
| -DATABASE_ROUTERS = ['odm2cvs.db_routers.ControlledVocabularyRouter'] |
| 158 | +DATABASE_ROUTERS: List[str] = ['odm2cvs.db_routers.ControlledVocabularyRouter'] |
0 commit comments