· 7 years ago · Dec 06, 2018, 08:22 AM
1# Django settings for data_admin project.
2import os
3from pyutil.program.conf import Conf
4from pyutil.program.pathutil import append_path, get_fullpath
5
6append_path(__file__, '..')
7BASE_DIR = os.path.dirname(os.path.dirname(__file__))
8conf_name = os.environ.get('DJ_CONF', 'deploy')
9dj_debug = os.environ.get('DJ_DEBUG', '')
10CONF = conf = Conf(get_fullpath(__file__, 'conf/%s.conf' % conf_name))
11
12DEBUG = (dj_debug or conf.get('is_debug')) == 'True'
13DEBUG = 'True'
14TEMPLATE_DEBUG = DEBUG
15
16ADMINS = (
17 ('Ping Yin', 'yinping@bytedance.com'),
18)
19
20MANAGERS = ADMINS
21
22DATABASES = {
23 'op_admin': {
24 'ENGINE': 'django.db.backends.mysql',
25 'NAME': conf.get('op_admin_db_name'),
26 'USER': conf.get('op_admin_write_user'),
27 'PASSWORD': conf.get('op_admin_write_password'),
28 'HOST': conf.get('op_admin_write_host'),
29 'PORT': conf.get('op_admin_write_port'),
30 'OPTIONS': { 'autocommit': True, }
31 },
32 'web_article': {
33 'ENGINE': 'django.db.backends.mysql',
34 'NAME': conf.get('db_web_article_name'),
35 'USER': conf.get('db_web_article_user'),
36 'PASSWORD': conf.get('db_web_article_password'),
37 'HOST': conf.get('db_web_article_host'),
38 'PORT': conf.get('db_web_article_port'),
39 'OPTIONS': { 'autocommit': True, }
40 },
41 'web_comment': {
42 'ENGINE': 'django.db.backends.mysql',
43 'NAME': conf.get('db_web_comment_name'),
44 'USER': conf.get('db_web_comment_user'),
45 'PASSWORD': conf.get('db_web_comment_password'),
46 'HOST': conf.get('db_web_comment_host'),
47 'PORT': conf.get('db_web_comment_port'),
48 'OPTIONS': { 'autocommit': True, }
49 },
50 'resys': {
51 'ENGINE': 'django.db.backends.mysql',
52 'NAME': conf.get('ss_recommend_name'),
53 'USER': conf.get('ss_recommend_write_user'),
54 'PASSWORD': conf.get('ss_recommend_write_password'),
55 'HOST': conf.get('ss_recommend_write_host'),
56 'PORT': conf.get('ss_recommend_write_port'),
57 'OPTIONS': {'autocommit': True,}
58 },
59 'recommend':{
60 'ENGINE': 'django.db.backends.mysql',
61 'NAME': conf.get('ss_recommend_aws_name'),
62 'USER': conf.get('ss_recommend_aws_read_user'),
63 'PASSWORD': conf.get('ss_recommend_aws_read_password'),
64 'HOST': conf.get('ss_recommend_aws_read_host'),
65 'PORT': conf.get('ss_recommend_aws_read_port'),
66 'OPTIONS': {'autocommit': True,}
67 },
68 'ss_article': {
69 'ENGINE': 'django.db.backends.mysql',
70 'NAME': conf.get('ss_article_db_name'),
71 'USER': conf.get('ss_article_write_user'),
72 'PASSWORD': conf.get('ss_article_write_password'),
73 'HOST': conf.get('ss_article_write_host'),
74 'PORT': conf.get('ss_article_write_port'),
75 'OPTIONS': { 'autocommit': True, }
76 },
77 'ss_article2': {
78 'ENGINE': 'django.db.backends.mysql',
79 'NAME': conf.get('ss_article2_db_name'),
80 'USER': conf.get('ss_article2_write_user'),
81 'PASSWORD': conf.get('ss_article2_write_password'),
82 'HOST': conf.get('ss_article2_write_host'),
83 'PORT': conf.get('ss_article2_write_port'),
84 'OPTIONS': { 'autocommit': True, }
85 },
86 'profile_meta_db_write': {
87 'ENGINE': 'django.db.backends.mysql',
88 'NAME': conf.get('profile_meta_db_db_name'),
89 'USER': conf.get('profile_meta_db_write_user'),
90 'PASSWORD': conf.get('profile_meta_db_write_password'),
91 'HOST': conf.get('profile_meta_db_write_host'),
92 'PORT': conf.get('profile_meta_db_write_port'),
93 'OPTIONS': { 'autocommit': True, }
94 },
95 'crawl': {
96 'ENGINE': 'django.db.backends.mysql',
97 'NAME': conf.get('crawl_db_name'),
98 'USER': conf.get('crawl_write_user'),
99 'PASSWORD': conf.get('crawl_write_password'),
100 'HOST': conf.get('crawl_write_host'),
101 'PORT': conf.get('crawl_write_port'),
102 'OPTIONS': {'autocommit': True,}
103 },
104 'video_annotation': {
105 'ENGINE': 'django.db.backends.mysql',
106 'NAME': conf.get('video_db_name'),
107 'USER': conf.get('video_db_write_user'),
108 'PASSWORD': conf.get('video_db_write_password'),
109 'HOST': conf.get('video_db_write_host'),
110 'PORT': conf.get('video_db_write_port'),
111 'OPTIONS': {'autocommit': True,}
112 }
113}
114DATABASES['default'] = DATABASES['op_admin']
115
116# Hosts/domain names that are valid for this site; required if DEBUG is False
117# See https://docs.djangoproject.com/en/1.3/ref/settings/#allowed-hosts
118ALLOWED_HOSTS = ['*']
119
120EMAIL_HOST = '10.4.16.240'
121EMAIL_HOST_USER = 'deliverer@admin.bytedance.com'
122EMAIL_HOST_PASSWORD = '906jiaoye'
123EMAIL_USE_TLS = True
124EMAIL_SUBJECT_PREFIX = '[admin]'
125DEFAULT_FROM_EMAIL = 'deliverer@admin.bytedance.com'
126
127# Local time zone for this installation. Choices can be found here:
128# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
129# although not all choices may be available on all operating systems.
130# On Unix systems, a value of None will cause Django to use the same
131# timezone as the operating system.
132# If running in a Windows environment this must be set to the same as your
133# system time zone.
134#TIME_ZONE = 'America/Chicago'
135TIME_ZONE = 'Etc/UTC'
136
137# Language code for this installation. All choices can be found here:
138# http://www.i18nguy.com/unicode/language-identifiers.html
139LANGUAGE_CODE = 'en-us'
140
141SITE_ID = 1
142
143# If you set this to False, Django will make some optimizations so as not
144# to load the internationalization machinery.
145USE_I18N = True
146
147# If you set this to False, Django will not format dates, numbers and
148# calendars according to the current locale
149USE_L10N = True
150
151# Absolute filesystem path to the directory that will hold user-uploaded files.
152# Example: "/home/media/media.lawrence.com/media/"
153MEDIA_ROOT = ''
154
155# URL that handles the media served from MEDIA_ROOT. Make sure to use a
156# trailing slash.
157# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
158MEDIA_URL = ''
159
160# Absolute path to the directory static files should be collected to.
161# Don't put anything in this directory yourself; store your static files
162# in apps' "static/" subdirectories and in STATICFILES_DIRS.
163# Example: "/home/media/media.lawrence.com/static/"
164STATIC_ROOT = os.path.join(BASE_DIR, 'webroot/')
165
166# URL prefix for static files.
167# Example: "http://media.lawrence.com/static/"
168STATIC_URL = '/data/static/'
169
170# URL prefix for admin static files -- CSS, JavaScript and images.
171# Make sure to use a trailing slash.
172# Examples: "http://foo.com/static/admin/", "/static/admin/".
173ADMIN_MEDIA_PREFIX = '/data/static/admin/'
174
175
176# Additional locations of static files
177STATICFILES_DIRS = (
178 # Put strings here, like "/home/html/static" or "C:/www/django/static".
179 # Always use forward slashes, even on Windows.
180 # Don't forget to use absolute paths, not relative paths.
181 os.path.join(BASE_DIR, "webroot/static"),
182)
183# List of finder classes that know how to find static files in
184# various locations.
185STATICFILES_FINDERS = (
186 'django.contrib.staticfiles.finders.FileSystemFinder',
187 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
188# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
189)
190
191# Make this unique, and don't share it with anybody.
192# SECRET_KEY = 'gt%n6&aqml!ljfa3&xq31xof5yifwecyn7f@uz(%x4u9eusdkd'
193SECRET_KEY = 'po$)40yi8jlufjc05*&h6aocoy+n1q75n6@2a)xgb@*xgx$()a'
194SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
195
196# List of callables that know how to import templates from various sources.
197TEMPLATE_LOADERS = (
198 'django.template.loaders.filesystem.Loader',
199 'django.template.loaders.app_directories.Loader',
200# 'django.template.loaders.eggs.Loader',
201)
202
203MIDDLEWARE_CLASSES = (
204 'hot_topic.middleware.PublicAccess',
205 'django.contrib.sessions.middleware.SessionMiddleware',
206 'pyutil.django.cas.middleware.CASDisabledCSRFMiddleware',
207 'django.middleware.common.CommonMiddleware',
208 #'django.middleware.csrf.CsrfViewMiddleware',
209 'django.contrib.auth.middleware.AuthenticationMiddleware',
210 'pyutil.django.cas.middleware.CASMiddleware',
211 'pyutil.django.middleware.auth.RequireStaffMemberMiddleware',
212 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
213 'pyutil.django.middleware.url_auth.UrlAuthenticationMiddleware',
214 'django.contrib.messages.middleware.MessageMiddleware',
215 'django.middleware.clickjacking.XFrameOptionsMiddleware',
216 'django.middleware.locale.LocaleMiddleware',
217)
218
219
220AUTHENTICATION_BACKENDS = (
221 'pyutil.django.base_backends.FrequencyLDAPBackend',
222 'pyutil.django.user_group.backends.UserGroupBackend',
223 'pyutil.django.cas.backends.CASBackend',
224 'pyutil.django.backends.PermissionOnlyHierarchicalModelBackend',
225)
226
227CAS_SERVER_URL = "https://sso.bytedance.com/cas/"
228# CAS_SERVER_URL = "https://test-sso.bytedance.net/cas/"
229CAS_SINGLE_SIGN_OUT = True
230CAS_VERSION = '3'
231CAS_AUTO_CREATE_USERS = True
232
233# config for UrlAuthenticationMiddleware
234URL_AUTH_CONFIG = {
235 'redis_key': 'crawl/user/function_url_patterns',
236 'redis_name': 'redis_crawl',
237}
238
239ROOT_URLCONF = 'djangosite.urls'
240
241TEMPLATE_DIRS = (
242 # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
243 # Always use forward slashes, even on Windows.
244 # Don't forget to use absolute paths, not relative paths.
245 os.path.join(os.path.dirname(__file__), 'templates'),
246)
247
248INSTALLED_APPS = (
249 'django.contrib.auth',
250 'django.contrib.contenttypes',
251 'django.contrib.sessions',
252 'django.contrib.messages',
253 'django.contrib.staticfiles',
254 'django.contrib.admin',
255 'mptt',
256 'hierarchical_auth',
257 'pyutil.django.user_group',
258 'pyutil.django.cas',
259 'raven.contrib.django.raven_compat',
260
261 'article',
262 'recsys',
263 'data_profile', # profile is conflict with python's package
264 'debuginfo',
265 #'push_and_search',
266 'ttpush',
267 'search',
268 'topic',
269 'labeling',
270 'category',
271 'channel',
272 'evaluation',
273 'video',
274 'operation',
275 'video_annotation_sys',
276 'download',
277 'hot_topic',
278)
279
280class DBRouter(object):
281 auth_tables = (
282 'auth_group', 'auth_group_permissions', 'auth_message', 'auth_permission',
283 'auth_user', 'auth_user_groups', 'auth_user_user_permissions', 'django_admin_log',
284 'django_content_type', 'django_session', 'django_site', 'gm_group_assign_record',
285 'gm_group_assign_record_users', 'gm_group_manager', 'gm_group_manager_groups',
286 'ug_user_group_users', 'ug_user_group_admins', 'ug_user_group_groups', 'ug_user_group_permissions',
287 'ug_user_group', 'admin_function', 'admin_user', 'ug_user_group_admin_functions', 'django_cas_pgtiou',
288 'django_cas_session_service_ticket', 'django_cas_tgt',
289 )
290 web_comment_tables = [
291 'comment',
292 'comment_ext',
293 'comment_stats',
294 'offsite_user',
295 ]
296 web_article_tables = [
297 'article_group',
298 'article_group_stats',
299 'article_image',
300 'article_item',
301 'article_item_stats',
302 'channel_mapping',
303 'channel_mapping_past',
304 'domain_mapping',
305 'domain_pattern_blacklist',
306 'domain_suffix',
307 'sort_rank_history',
308 'statistics_count',
309 ]
310 ss_article_tables = ['crawl_group_ttl', 'crawl_article_item']
311 ss_article2_tables = (
312 'crawl_link_message_ref',
313 )
314 ss_annotation_tables = [
315 'ss_annotation_user',
316 'ss_annotation_video',
317 'ss_annotation_task',
318 'ss_annotation_history'
319 ]
320
321 profile_meta_db_tables = ['tag']
322 resys_tables = ['group_quality_feature']
323 recommend_tables = ['group_boost_strategy', 'group_boost_strategy_history', 'group_rate_profile_all', 'group_rate_profile', 'longterm_day_verify_recall']
324 crawl_tables = (
325 'message',
326 )
327
328 def db_for_read(self, model, **hints):
329 tbl = model._meta.db_table
330 if tbl in self.auth_tables:
331 return 'op_admin'
332 elif tbl in self.web_article_tables:
333 return 'web_article'
334 elif tbl in self.ss_article_tables:
335 return 'ss_article'
336 elif tbl in self.ss_article2_tables:
337 return 'ss_article2'
338 elif tbl in self.web_comment_tables:
339 return 'web_comment'
340 elif tbl in self.recommend_tables:
341 return 'recommend'
342 elif tbl in self.resys_tables:
343 return 'resys'
344 elif tbl in self.profile_meta_db_tables:
345 return 'profile_meta_db_write'
346 elif tbl in self.crawl_tables:
347 return 'crawl'
348 elif tbl in self.ss_annotation_tables:
349 return 'video_annotation'
350
351 return 'default'
352
353 def db_for_write(self, model, **hints):
354 return self.db_for_read(model, **hints)
355
356DATABASE_ROUTERS = ['settings.DBRouter', ]
357
358# A sample logging configuration. The only tangible logging
359# performed by this configuration is to send an email to
360# the site admins on every HTTP 500 error.
361# See http://docs.djangoproject.com/en/dev/topics/logging for
362# more details on how to customize your logging configuration.
363LOGGING = {
364 'version': 1,
365 'disable_existing_loggers': False,
366 'handlers': {
367 'mail_admins': {
368 'level': 'ERROR',
369 'class': 'django.utils.log.AdminEmailHandler'
370 }
371 },
372 'loggers': {
373 'django.request': {
374 'handlers': ['mail_admins'],
375 'level': 'ERROR',
376 'propagate': True,
377 },
378 }
379}
380
381
382LANGUAGE_CODE = 'en-us'
383LOCALE_PATHS = (
384 os.path.join(BASE_DIR, 'djangosite/localization'),
385)
386LANGUAGES = (
387 ('en', 'English'),
388 ('zh-hans', 'Simplified Chinese')
389)