Advertisement
juanmd

base.py Proyecto 2 UCN

May 12th, 2022 (edited)
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.10 KB | None | 0 0
  1. import json
  2. from django.core.exceptions import ImproperlyConfigured
  3. from unipath import Path
  4.  
  5.  
  6. BASE_DIR = Path(__file__).ancestor(3)
  7.  
  8.  
  9. with open("global_data.json") as f:
  10.     value = json.loads(f.read())
  11.  
  12.  
  13. def get_value(value_title, values=value):
  14.     try:
  15.         return values[value_title]
  16.     except:
  17.         msg = f"The name of {value_title} doesn't exists"
  18.         raise ImproperlyConfigured(msg)
  19.  
  20.  
  21. def gettext(s):
  22.     return s
  23.  
  24.  
  25. SECRET_KEY = get_value('SECRET_KEY')
  26.  
  27.  
  28. LANGUAGE_CODE = get_value('LANGUAGE_CODE')
  29.  
  30.  
  31. TIME_ZONE = get_value('TIME_ZONE')
  32.  
  33.  
  34. DJANGO_APPS = (
  35.     'django.contrib.admin',
  36.     'django.contrib.auth',
  37.     'django.contrib.contenttypes',
  38.     'django.contrib.sessions',
  39.     'django.contrib.messages',
  40.     'django.contrib.staticfiles',
  41. )
  42.  
  43.  
  44. THIRD_PARTY_APPS = (
  45.     #
  46. )
  47.  
  48.  
  49. LOCAL_APPS = (
  50.     #
  51. )
  52.  
  53.  
  54. INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
  55.  
  56.  
  57. WSGI_APPLICATION = f'{get_value("CORE_APP")}.wsgi.application'
  58.  
  59.  
  60. ROOT_URLCONF = f'{get_value("CORE_APP")}.urls'
  61.  
  62.  
  63. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  64.  
  65.  
  66. MIDDLEWARE = [
  67.     'django.middleware.security.SecurityMiddleware',
  68.     'django.contrib.sessions.middleware.SessionMiddleware',
  69.     'django.middleware.common.CommonMiddleware',
  70.     'django.middleware.csrf.CsrfViewMiddleware',
  71.     'django.middleware.locale.LocaleMiddleware',
  72.     'django.contrib.auth.middleware.AuthenticationMiddleware',
  73.     'django.contrib.messages.middleware.MessageMiddleware',
  74.     'django.middleware.clickjacking.XFrameOptionsMiddleware',
  75. ]
  76.  
  77.  
  78. TEMPLATES = [
  79.     {
  80.         'BACKEND': 'django.template.backends.django.DjangoTemplates',
  81.         'DIRS': [BASE_DIR.child('templates')],
  82.         'APP_DIRS': True,
  83.         'OPTIONS': {
  84.             'context_processors': [
  85.                 'django.contrib.auth.context_processors.auth',
  86.                 'django.contrib.messages.context_processors.messages',
  87.                 'django.template.context_processors.debug',
  88.                 'django.template.context_processors.request',
  89.                 'django.template.context_processors.i18n',
  90.                 'django.template.context_processors.csrf',
  91.                 'django.template.context_processors.media',
  92.             ],
  93.         },
  94.     },
  95. ]
  96.  
  97.  
  98. AUTH_PASSWORD_VALIDATORS = [
  99.     {
  100.         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  101.     },
  102.     {
  103.         'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  104.     },
  105.     {
  106.         'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  107.     },
  108.     {
  109.         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  110.     },
  111. ]
  112.  
  113.  
  114. TIME_ZONE = 'America/Bogota'
  115.  
  116.  
  117. DEFAULT_CHARSET = 'utf-8'
  118.  
  119.  
  120. LANGUAGES = (
  121.     ('es-co', gettext('Español Colombia')),
  122.     ('en', gettext('English')),
  123. )
  124.  
  125.  
  126. LOCALE_PATHS = [
  127.     BASE_DIR.child('locale'),
  128. ]
  129.  
  130.  
  131. USE_I18N = True
  132.  
  133.  
  134. USE_L10N = True
  135.  
  136.  
  137. USE_TZ = True
  138.  
  139.  
  140. STATIC_URL = '/static/'
  141.  
  142.  
  143. MEDIA_URL = '/media/'
  144.  
  145.  
  146. MEDIA_ROOT = BASE_DIR.child('media')
  147.  
  148.  
  149. STATICFILES_DIRS = [BASE_DIR.child('static')]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement