base.py 15.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
"""
Django settings for base_django_project project.

For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/
"""
import environ

ROOT_DIR = environ.Path(__file__) - 3  # (base_django_project/config/settings/base.py - 3 = base_django_project/)
APPS_DIR = ROOT_DIR.path('base_django_project')

# Load operating system environment variables and then prepare to use them
env = environ.Env()

# .env file, should load only in development environment
READ_DOT_ENV_FILE = env.bool('DJANGO_READ_DOT_ENV_FILE', default=False)

if READ_DOT_ENV_FILE:
    # Operating System Environment variables have precedence over variables defined in the .env file,
    # that is to say variables from the .env files will only be used if not defined
    # as environment variables.
    env_file = str(ROOT_DIR.path('.env'))
    print('Loading : {}'.format(env_file))
    env.read_env(env_file)
    print('The .env file has been loaded. See base.py for more information')

# APP CONFIGURATION
# ------------------------------------------------------------------------------
DJANGO_APPS = [
    # Default Django apps:
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
Bruno Martin's avatar
Bruno Martin committed
40
    'django.contrib.flatpages',
Bruno Martin's avatar
Bruno Martin committed
41 42 43
    
    'dal',
    'dal_select2',
44 45 46 47
    # Admin
    'django.contrib.admin',
]
THIRD_PARTY_APPS = [
Bruno Martin's avatar
Bruno Martin committed
48 49
    # needed for allauth templates
    'crispy_forms',
50 51 52 53 54 55 56 57 58 59 60
    'allauth',  # registration
    'allauth.account',  # registration
    'allauth.socialaccount',  # registration
    'allauth.socialaccount.providers.facebook',
    'allauth.socialaccount.providers.twitter',
    'django_filters',
    'rest_framework',
    'rest_framework.authtoken',
    'rest_auth',
    'rest_auth.registration',
    'corsheaders',
61 62
    'cities_light',

Bruno Martin's avatar
Bruno Martin committed
63 64
    # legacy apps deps, refactor one day...
    'localflavor',
65 66 67
    'compressor',
    'pinax.webanalytics',

Bruno Martin's avatar
Bruno Martin committed
68 69 70 71 72 73
    # pages admin editor related
    'ckeditor',
    'easy_thumbnails',
    'filer',
    'mptt',

74 75
    'courier',
    'courier.emails',
76
    # 'courier.emails.providers.onesignal',
77 78 79
    'courier.pushnotifications',
    'courier.pushnotifications.providers.onesignal',
    'discussion',
80 81 82 83 84
]

# Apps specific for this project go here.
LOCAL_APPS = [
    # custom users app
85
    'users.apps.UsersConfig',
Bruno Martin's avatar
Bruno Martin committed
86
    'pages.apps.PagesConfig',
Bruno Martin's avatar
Bruno Martin committed
87 88 89 90 91 92 93
    'courses.apps.CoursesConfig',
    'courses_learning_objects.apps.CoursesLearningObjectsConfig',
    'courses_certification.apps.CoursesCertificationConfig',
    'courses_gamification.apps.CoursesGamificationConfig',
    'courses_reports.apps.CoursesReportsConfig',
    'courses_legacy.apps.CoursesLegacyConfig',
    'courses_legacy.administration',
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
]

# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

# MIDDLEWARE CONFIGURATION
# ------------------------------------------------------------------------------
MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # XFrameOptions disabled needed to login iframe
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

# MIGRATIONS CONFIGURATION
# ------------------------------------------------------------------------------
MIGRATION_MODULES = {
    'sites': 'base_django_project.contrib.sites.migrations'
}

# DEBUG
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = env.bool('DJANGO_DEBUG', False)

# FIXTURE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
FIXTURE_DIRS = (
    str(APPS_DIR.path('fixtures')),
)

# EMAIL CONFIGURATION
# ------------------------------------------------------------------------------
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')

# MANAGER CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
ADMINS = [
    ("""hacklab""", 'sysadmin@hacklab.com.br'),
]

# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
MANAGERS = ADMINS

# DATABASE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
# Raises ImproperlyConfigured exception if database variables aren't in os.environ
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'HOST': env('POSTGRES_HOST', default='postgres'),
        'NAME': env('POSTGRES_DB'),
        'USER': env('POSTGRES_USER'),
        'PASSWORD': env('POSTGRES_PASSWORD'),
    },
}
DATABASES['default']['ATOMIC_REQUESTS'] = True


# GENERAL CONFIGURATION
# ------------------------------------------------------------------------------
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Sao_Paulo'

# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
LANGUAGE_CODE = 'pt-br'

# See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
SITE_ID = 1

# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
USE_I18N = True

# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
USE_L10N = True

# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
USE_TZ = True

# TEMPLATE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#templates
TEMPLATES = [
    {
        # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
        'DIRS': [
            str(APPS_DIR.path('templates')),
        ],
        'OPTIONS': {
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
            'debug': DEBUG,
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
            # https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
            'loaders': [
201
                'courses_legacy.core.loaders.TimtecThemeLoader',
202 203 204 205 206 207 208 209 210 211 212 213 214
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ],
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
215
                # legacy stuff
216 217 218 219
                'courses_legacy.core.context_processors.site_settings',
                # 'courses_legacy.core.context_processors.contact_form',
                'courses_legacy.core.context_processors.get_current_path',
                # 'courses_legacy.core.context_processors.terms_acceptance_required',
220 221 222 223 224
            ],
        },
    },
]

225 226 227
# See: http://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs
CRISPY_TEMPLATE_PACK = 'bootstrap4'

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
# STATIC FILE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
STATIC_ROOT = str(ROOT_DIR('staticfiles'))

# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = '/static/'

# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = [
    str(APPS_DIR.path('static')),
]

# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

# MEDIA CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
MEDIA_ROOT = str(APPS_DIR('media'))

# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
MEDIA_URL = '/media/'

# URL Configuration
# ------------------------------------------------------------------------------
ROOT_URLCONF = 'config.urls'

# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
WSGI_APPLICATION = 'config.wsgi.application'

# PASSWORD STORAGE SETTINGS
# ------------------------------------------------------------------------------
# See https://docs.djangoproject.com/en/dev/topics/auth/passwords/#using-argon2-with-django
PASSWORD_HASHERS = [
    'django.contrib.auth.hashers.Argon2PasswordHasher',
    'django.contrib.auth.hashers.PBKDF2PasswordHasher',
    'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
    'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
    'django.contrib.auth.hashers.BCryptPasswordHasher',
]

# PASSWORD VALIDATION
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators
# ------------------------------------------------------------------------------

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# AUTHENTICATION CONFIGURATION
# ------------------------------------------------------------------------------
AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
302
        'rest_framework.authentication.SessionAuthentication',
303 304 305 306
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticatedOrReadOnly',
    ),
Bruno Martin's avatar
Bruno Martin committed
307 308 309
    'DEFAULT_FILTER_BACKENDS': (
        'django_filters.rest_framework.DjangoFilterBackend',
    ),
310 311 312
}

REST_AUTH_REGISTER_SERIALIZERS = {
Bruno Martin's avatar
Bruno Martin committed
313
    'REGISTER_SERIALIZER': 'users.serializers.RegistrationSerializer'
314 315 316 317 318 319 320 321 322
}

# Some really nice defaults
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'optional'
ACCOUNT_USERNAME_REQUIRED = False

ACCOUNT_ALLOW_REGISTRATION = env.bool('DJANGO_ACCOUNT_ALLOW_REGISTRATION', True)
Bruno Martin's avatar
Bruno Martin committed
323
SOCIALACCOUNT_ADAPTER = 'users.adapters.SocialAccountAdapter'
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
SOCIALACCOUNT_QUERY_EMAIL = True

SOCIALACCOUNT_PROVIDERS = {
    'facebook': {
        'METHOD': 'js_sdk',
        'SCOPE': ['email', 'public_profile', 'user_friends'],
        'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
        'INIT_PARAMS': {'cookie': True},
        'FIELDS': [
            'id',
            'email',
            'name',
            'first_name',
            'last_name',
            'verified',
            'locale',
            'timezone',
            'link',
            'gender',
            'updated_time',
        ],
        'EXCHANGE_TOKEN': True,
        'VERIFIED_EMAIL': False,
347
        'VERSION': 'v2.12',
348 349 350 351 352 353 354 355 356 357 358 359 360
    }
}

# Custom user app defaults
# Select the correct user model
AUTH_USER_MODEL = 'users.User'
LOGIN_URL = 'account_login'

# SLUGLIFIER
AUTOSLUG_SLUGIFY_FUNCTION = 'slugify.slugify'


# Custom Admin URL, use {% url 'admin:index' %}
361
ADMIN_URL = env('DJANGO_ADMIN_URL', default=r'^django/admin/')
362 363 364 365 366 367 368

# Django cors
# ------------------------------------------------------------------------------
CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = (
    'example.com',
)
Bruno Martin's avatar
Bruno Martin committed
369

370 371 372 373 374 375
# Django-courier
# ------------------------------------------------------------------------------
COURIER_DEFAULT_PROVIDER = env('COURIER_DEFAULT_PROVIDER', default='')
COURIER_ONESIGNAL_APP_ID = env('COURIER_ONESIGNAL_APP_ID', default='')
COURIER_ONESIGNAL_USER_ID = env('COURIER_ONESIGNAL_USER_ID', default='')

376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
# Django cities light
# ------------------------------------------------------------------------------
CITIES_LIGHT_INCLUDE_COUNTRIES = ['BR']

# http://download.geonames.org/export/dump/iso-languagecodes.txt
CITIES_LIGHT_TRANSLATION_LANGUAGES = ['pt', 'abbr']

# http://www.geonames.org/export/codes.html
CITIES_LIGHT_INCLUDE_CITY_TYPES = [
    'PPL', 'PPLA', 'PPLA2', 'PPLA3', 'PPLA4', 'PPLC', 'PPLF', 'PPLG', 'PPLL', 'PPLR', 'PPLS', 'STLMT',
]

# API CEP Aberto
# ------------------------------------------------------------------------------
CEP_ABERTO_API_KEY = env.str('CEP_ABERTO_API_KEY', '')
CEP_ABERTO_URL = env.str('CEP_ABERTO_URL', '')
Bruno Martin's avatar
Bruno Martin committed
392

393 394 395
RECAPTCHA_SECRET_KEY = env.str('RECAPTCHA_SECRET_KEY', '')

# Legacy Defaults, review everything. Everyting beyond here is legacy
Bruno Martin's avatar
Bruno Martin committed
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
# ------------------------------------------------------------------------------
TERMS_ACCEPTANCE_REQUIRED = True
REGISTRATION_DEFAULT_GROUP_NAME = 'students'
# ACCOUNT_ADAPTER = "accounts.adapter.TimtecAdapter"
# ACCOUNT_UNIQUE_EMAIL = True
# ACCOUNT_AUTHENTICATION_METHOD = "username_email"
# ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 7
# ACCOUNT_EMAIL_REQUIRED = True
# ACCOUNT_EMAIL_VERIFICATION = 'optional'
# ACCOUNT_EMAIL_SUBJECT_PREFIX = "[timtec] "
# ACCOUNT_SIGNUP_FORM_CLASS = 'accounts.forms.SignupForm'
ACCOUNT_REQUIRED_FIELDS = ('first_name', 'last_name', )
# SOCIALACCOUNT_EMAIL_VERIFICATION = False

CERTIFICATE_SIZE = (862, 596)
PHANTOMJS_PATH = ROOT_DIR.path('node_modules/phantomjs-prebuilt/bin/phantomjs')

413
YOUTUBE_API_KEY = env.str('YOUTUBE_API_KEY', '')
414 415 416 417 418 419 420 421 422 423 424 425 426 427

# [legacy] Django compressor stuff
COMPRESS_OFFLINE = True

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
]

COMPRESS_PRECOMPILERS = (
    ('text/x-scss', 'django_libsass.SassCompiler'),
)

428 429 430 431
SITE_DOMAIN = ''
SITE_HOME = ''
SITE_NAME = ''

432 433 434 435 436
#
# Theme related options
#
THEMES_DIR = ''
TIMTEC_THEME = 'courses_legacy'  # don't forget to re run collectstatic if you change the theme
437
TIMTEC_THEMES_COMPAT = env.bool('DJANGO_TIMTEC_THEMES_COMPAT', default=False)