""" 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', 'django.contrib.flatpages', 'dal', 'dal_select2', # Admin 'django.contrib.admin', ] THIRD_PARTY_APPS = [ # needed for allauth templates 'crispy_forms', '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', 'cities_light', # legacy apps deps, refactor one day... 'localflavor', 'compressor', 'pinax.webanalytics', # pages admin editor related 'ckeditor', 'easy_thumbnails', 'filer', 'mptt', 'courier', 'courier.emails', # 'courier.emails.providers.onesignal', 'courier.pushnotifications', 'courier.pushnotifications.providers.onesignal', 'discussion', ] # Apps specific for this project go here. LOCAL_APPS = [ # custom users app 'users.apps.UsersConfig', 'pages.apps.PagesConfig', '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', ] # 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': [ 'courses_legacy.core.loaders.TimtecThemeLoader', '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', # legacy stuff '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', ], }, }, ] # See: http://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs CRISPY_TEMPLATE_PACK = 'bootstrap4' # 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', 'rest_framework.authentication.SessionAuthentication', ), 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticatedOrReadOnly', ), 'DEFAULT_FILTER_BACKENDS': ( 'django_filters.rest_framework.DjangoFilterBackend', ), } REST_AUTH_REGISTER_SERIALIZERS = { 'REGISTER_SERIALIZER': 'users.serializers.RegistrationSerializer' } # 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) SOCIALACCOUNT_ADAPTER = 'users.adapters.SocialAccountAdapter' 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, 'VERSION': 'v2.12', } } # 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' %} ADMIN_URL = env('DJANGO_ADMIN_URL', default=r'^django/admin/') # Django cors # ------------------------------------------------------------------------------ CORS_ORIGIN_ALLOW_ALL = False CORS_ORIGIN_WHITELIST = ( 'example.com', ) # 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='') # 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', '') RECAPTCHA_SECRET_KEY = env.str('RECAPTCHA_SECRET_KEY', '') # Legacy Defaults, review everything. Everyting beyond here is legacy # ------------------------------------------------------------------------------ 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') YOUTUBE_API_KEY = env.str('YOUTUBE_API_KEY', '') # [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'), ) SITE_DOMAIN = '' SITE_HOME = '' SITE_NAME = '' # # Theme related options # THEMES_DIR = '' TIMTEC_THEME = 'courses_legacy' # don't forget to re run collectstatic if you change the theme TIMTEC_THEMES_COMPAT = env.bool('DJANGO_TIMTEC_THEMES_COMPAT', default=False)