· 8 years ago · Jul 12, 2017, 10:38 PM
1import socket
2import sbhs_server.credentials as credentials
3
4hostname = socket.gethostname()
5is_production = hostname == "shan"
6
7# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
8import os
9BASE_DIR = os.path.dirname(os.path.dirname(__file__))
10OUTPUT_DIR = os.path.join(BASE_DIR, 'output')
11
12# SECURITY WARNING: keep the secret key used in production secret!
13SECRET_KEY = credentials.PROJECT_SECRET_KEY
14
15# SECURITY WARNING: don't run with debug turned on in production!
16DEBUG = not is_production
17
18TEMPLATE_DEBUG = not is_production
19
20ALLOWED_HOSTS = [
21 "localhost",
22 "127.0.0.1",
23 "192.168.43.208",
24 "192.168.43.144",
25 "10.42.0.1",
26]
27
28# Application definition
29FIXTURE_DIRS = os.path.join(BASE_DIR, "yaksh", "fixtures")
30
31URL_ROOT = ''
32
33if not DEBUG:
34 ALLOWED_HOSTS = [
35 "localhost",
36 "127.0.0.1",
37 "vlabs.iitb.ac.in",
38 "vlabs.iitb.ac.in.",
39 "10.102.152.15",
40 ]
41
42# Application definition
43
44INSTALLED_APPS = (
45 'django.contrib.admin',
46 'django.contrib.auth',
47 'django.contrib.contenttypes',
48 'django.contrib.sessions',
49 'django.contrib.messages',
50 'django.contrib.staticfiles',
51
52 'undelete',
53 'yaksh',
54 'taggit',
55
56 'account',
57 'custom_admin',
58 'experiment',
59 'pages',
60 'password',
61 'sbhs_server.tables',
62)
63
64MIDDLEWARE_CLASSES = (
65 'django.contrib.sessions.middleware.SessionMiddleware',
66 'django.middleware.common.CommonMiddleware',
67 'django.middleware.csrf.CsrfViewMiddleware',
68 'django.contrib.auth.middleware.AuthenticationMiddleware',
69 'yaksh.middleware.one_session_per_user.OneSessionPerUserMiddleware',
70 'yaksh.middleware.user_time_zone.TimezoneMiddleware',
71 'django.contrib.messages.middleware.MessageMiddleware',
72 'django.middleware.clickjacking.XFrameOptionsMiddleware',
73)
74
75ROOT_URLCONF = 'sbhs_server.urls'
76
77WSGI_APPLICATION = 'sbhs_server.wsgi.application'
78
79if is_production:
80 DATABASES = {
81 'default': {
82 'ENGINE': 'django.db.backends.mysql',
83 'NAME': credentials.DB_NAME,
84 'USER': credentials.DB_USER,
85 'PASSWORD': credentials.DB_PASS,
86 'HOST': credentials.DB_HOST,
87 'PORT': credentials.DB_PORT,
88 }
89 }
90else:
91 DATABASES = {
92 'default': {
93 'ENGINE': 'django.db.backends.sqlite3',
94 'NAME': os.path.join(BASE_DIR, 'sbhs.sqlite3'),
95 }
96 }
97
98LANGUAGE_CODE = 'en-us'
99
100TIME_ZONE = 'Asia/Kolkata'
101
102USE_I18N = True
103
104USE_L10N = True
105
106USE_TZ = True
107
108AUTH_USER_MODEL = 'tables.Account'
109LOGIN_URL = '/sbhs/enter'
110LOGIN_REDIRECT_URL = '/sbhs/'
111LOGOUT_URL = '/sbhs/logout'
112SESSION_EXPIRE_AT_BROWSER_CLOSE = True
113CSRF_COOKIE_NAME = "pfesgbxra"
114SESSION_COOKIE_NAME = "frffvbaVq"
115
116MEDIA_URL = "/data/"
117MEDIA_ROOT = os.path.join(BASE_DIR, "yaksh", "data")
118
119# Set this varable to <True> if smtp-server is not allowing to send email.
120EMAIL_USE_TLS = False
121
122EMAIL_HOST = 'smtp-auth.iitb.ac.in'
123EMAIL_PORT = 25
124EMAIL_HOST_USER = credentials.EMAIL_HOST_USER
125EMAIL_HOST_PASSWORD = credentials.EMAIL_HOST_PASSWORD
126
127# Set EMAIL_BACKEND to 'django.core.mail.backends.smtp.EmailBackend' in production
128EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
129
130# SENDER_EMAIL, REPLY_EMAIL, PRODUCTION_URL, IS_DEVELOPMENT are used in email
131# verification. Set the variables accordingly to avoid errors in production
132
133# This email id will be used as <from address> for sending emails.
134# For example no_reply@<your_organization>.in can be used.
135SENDER_EMAIL = 'your_email'
136
137# Organisation/Indivudual Name.
138SENDER_NAME = 'your_name'
139
140# This email id will be used by users to send their queries
141# For example queries@<your_organization>.in can be used.
142REPLY_EMAIL = 'your_reply_email'
143
144# This url will be used in email verification to create activation link.
145# Add your hosted url to this variable.
146# For example https://127.0.0.1:8000 or 127.0.0.1:8000
147PRODUCTION_URL = 'your_project_url'
148
149DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
150
151# Static files (CSS, JavaScript, Images)
152# https://docs.djangoproject.com/en/1.6/howto/static-files/
153
154
155if is_production:
156 BASE_URL = "http://vlabs.iitb.ac.in/sbhs/"
157 FORCE_SCRIPT_NAME = "/sbhs"
158 USE_X_FORWARDED_HOST = True
159else:
160 BASE_URL = "http://127.0.0.1:8000/"
161
162SBHSCLIENT_STATIC_DIR = os.path.join(BASE_DIR, "client_static")
163STATICFILES_DIRS = (
164 os.path.join(BASE_DIR, "static"),
165 os.path.join(SBHSCLIENT_STATIC_DIR, "zipped"),
166)
167STATIC_ROOT = os.path.join(BASE_DIR, "production_static_files")
168
169if is_production:
170 STATIC_URL = 'http://vlabs.iitb.ac.in/sbhs/static/'
171else:
172 STATIC_URL = '/static/'
173
174# TEMPLATE_DIRS = (
175# os.path.join(BASE_DIR, "production_static_files"),
176# os.path.join(BASE_DIR, 'templates/'),
177# )
178
179TEMPLATES = [
180 {
181 'BACKEND': 'django.template.backends.django.DjangoTemplates',
182 'DIRS': [
183 os.path.join(BASE_DIR, 'templates'),
184 ],
185 'APP_DIRS': True,
186 'OPTIONS': {
187 'context_processors': [
188 'django.template.context_processors.debug',
189 'django.template.context_processors.request',
190 'django.contrib.auth.context_processors.auth',
191 'django.contrib.messages.context_processors.messages',
192 ],
193 },
194 },
195]
196
197import warnings
198warnings.filterwarnings(
199 'ignore', r"DateTimeField .* received a naive datetime",
200 RuntimeWarning, r'django\.db\.models\.fields')
201
202if not is_production:
203 import logging
204 l = logging.getLogger('django.db')
205 l.setLevel(logging.DEBUG)
206 l.addHandler(logging.StreamHandler())
207
208 LOGGING = {
209 'version': 1,
210 'disable_existing_loggers': False,
211 'handlers': {
212 'console': {
213 'level': 'DEBUG',
214 'class': 'logging.StreamHandler',
215 },
216 },
217 'loggers': {
218 'django.db': {
219 'level': 'DEBUG',
220 'handlers': ['console'],
221 },
222 }
223 }
224else:
225 LOGGING = {
226 'version': 1,
227 'disable_existing_loggers': False,
228 'handlers': {
229 'file': {
230 'level': 'DEBUG',
231 'class': 'logging.FileHandler',
232 'filename': os.path.join(BASE_DIR, 'log/django_error.log'),
233 }
234 },
235 'loggers': {
236 'django.request': {
237 'handlers': ['file'],
238 'level': 'ERROR',
239 'propagate': True,
240 }
241 }
242 }
243
244EXPERIMENT_LOGS_DIR = os.path.join(BASE_DIR, 'experiments')
245
246if not is_production:
247 SBHS_ADMINS = (
248 ("Amol Mandhane", "+91-9999999999", "amol_mandhane@iitb.ac.in"),
249 ("Amol Mandhane", "+91-9999999999", "amol_mandhane@iitb.ac.in"),
250 )
251else:
252 from sbhs_server.sbhs_admin_config import SBHS_ADMINS
253
254SBHS_GLOBAL_LOG_DIR = os.path.join(BASE_DIR, 'log')