Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
9.0 kB
4
Indexable
"""
Django settings for firsatcocuk project.

Generated by 'django-admin startproject' using Django 4.1.4.

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

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

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
# SECRET_KEY = 'django-insecure-n$ak7_0v9u%gji9)rn4n0%&as8kq04t#88#rgns31nzsd9y469'
from django.core.exceptions import ImproperlyConfigured
 
def get_env_variable(var_name):
    try:
        return os.environ[var_name]
    except KeyError:
        error_msg = "Set the %s environment variable" % var_name
        raise ImproperlyConfigured(error_msg)
 
SECRET_KEY = get_env_variable('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']

INSTALLED_APPS = [
    'rest_framework',
    'rest_framework.authtoken',
    'dj_rest_auth',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'dj_rest_auth.registration',
    'django.contrib.sites',

    'jazzmin',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'firsatcocuk_core',
    'corsheaders',
]

MIDDLEWARE = [
    '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',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
]

ROOT_URLCONF = 'firsatcocuk.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'firsatcocuk.wsgi.application'

# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': BASE_DIR / 'db.sqlite3',
#     }
# }
    # import psycopg2.extensions
    #
    # DATABASES = {
    #     'default': {
    #         'ENGINE': 'django.db.backends.postgresql',
    #         'NAME': 'firsatcocuk',
    #         'USER': 'dev-user',
    #         'PASSWORD': 'WGGMBmYx1wN8gQJ',
    #         'HOST': '185.184.27.95',
    #         'PORT': '5432',
    #         'ATOMIC_REQUESTS': True,
    #         'OPTIONS': {
    #             'isolation_level': psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE,
    #         },
    #     }
    # }

import psycopg2.extensions
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'firsatcocuk',
        'USER': 'dev-user',
        'PASSWORD': 'WGGMBmYx1wN8gQJ',
        'HOST': '185.184.27.95',
        'PORT': '5432',
        'ATOMIC_REQUESTS': True,
        'OPTIONS': {
            'isolation_level': psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE,
        },
    }
}

CORS_ALLOWED_ORIGINS = [
    "http://localhost:3000",
]


# Password validation
# https://docs.djangoproject.com/en/4.1/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',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = 'TR'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

JAZZMIN_SETTINGS = {
    "site_title": "TrAir",
    "site_header": "TrAir",
    "site_brand": ".",
    "site_icon": "../static/imgs/favicon.png",
    "site_logo": "../static/imgs/trair_beyaz.png",
    "login_logo": "../static/imgs/trair_logo.png",
    # "site_logo_classes": "mx-auto",
    "site_logo_classes":"",
    # Add your own branding here
    "welcome_sign": "",
    # Copyright on the footer
    "copyright": "",
    "user_avatar": None,
    # Whether to display the side menu
    "show_sidebar": True,
    # Whether to aut expand the menu
    "navigation_expanded": True,
    # Custom icons for side menu apps/models
    "icons": {
        "auth": "fas fa-users-cog",
        "auth.user": "fas fa-user",
        "users.User": "fas fa-user",
        "auth.Group": "fas fa-users",
        "admin.LogEntry": "fas fa-file",
        "firsatcocuk_core.Category": "fas fa-boxes",
        "firsatcocuk_core.Slider": "fas fa-images",
        "firsatcocuk_core.City": "fas fa-city",
        "firsatcocuk_core.Building": "fas fa-building",
        "firsatcocuk_core.Hall": "fas fa-gopuram",
        "firsatcocuk_core.Block": "fas fa-sort-alpha-up",
        "firsatcocuk_core.Seat": "fas fa-chair",
        "firsatcocuk_core.Artist": "fas fa-theater-masks",
        "firsatcocuk_core.Rule": "fas fa-info-circle",
        "firsatcocuk_core.Event": "fas fa-calendar",
        "firsatcocuk_core.Variant": "fas fa-tasks",
        "firsatcocuk_core.Ticket": "fas fa-ticket-alt",
        "firsatcocuk_core.CustomUser": "fas fa-user",
    },
    # # Icons that are used when one is not manually specified
    "default_icon_parents": "fas fa-chevron-circle-right",
    "default_icon_children": "fas fa-arrow-circle-right",
    # Use modals instead of popups
    "related_modal_active": False,
    # Relative paths to custom CSS/JS scripts (must be present in static files)
    # Uncomment this line once you create the bootstrap-dark.css file
    "custom_css": "../static/css/style.css",
    "custom_js": "../static/js/script.js",
    # Whether to show the UI customizer on the sidebar
    "show_ui_builder": False,
    "changeform_format": "horizontal_tabs",
    # override change forms on a per modeladmin basis
    "changeform_format_overrides": {
        "auth.user": "collapsible",
        "auth.group": "vertical_tabs",
    },
    "order_with_respect_to": ["firsatcocuk_core"],
       

}

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        # 'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication',
        'dj_rest_auth.jwt_auth.JWTCookieAuthentication'
    ),
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}

CORS_ORIGIN_ALLOW_ALL = True

SITE_ID = 1

ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_UNIQUE_EMAIL = True

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.yandex.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'beratemredemir@trair.com.tr'
DEFAULT_FROM_EMAIL = 'beratemredemir@trair.com.tr'
EMAIL_HOST_PASSWORD = "F-YtC7n.U=h=90m3"
EMAIL_USE_TLS = True

ACCOUNT_MAIL_VERIFICATION = 'none'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = "email"

LOGIN_REDIRECT_URL = '/'
APPEND_SLASH = False

REST_AUTH = {
    'SESSION_LOGIN': True,
    'USE_JWT': True,
    'JWT_AUTH_COOKIE': 'jwt-auth',
    'JWT_AUTH_HTTPONLY': False,
}

AUTH_USER_MODEL = "firsatcocuk_core.CustomUser"

AUTHENTICATION_BACKENDS = [
    'firsatcocuk_core.authentication.EmailBackend',
    'django.contrib.auth.backends.ModelBackend',
]

DJ_REST_AUTH_SERIALIZERS = {
    'REGISTER_SERIALIZER': 'firsatcocuk_core.api.serializers.CustomRegisterSerializer',
    'TOKEN_SERIALIZER': 'firsatcocuk_core.api.serializers.CustomTokenSerializer',
}


STATIC_ROOT = os.path.join(BASE_DIR, 'static_cdn')

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),   
)
MEDIA_ROOT = (
    os.path.join(BASE_DIR, 'images')
)
MEDIA_URL = '/images/'

MEDIAFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
    os.path.join(BASE_DIR, 'images'),
)