from dotenv import load_dotenv # from http.cookiejar import debug from pathlib import Path from datetime import timedelta import os from django.templatetags.static import static from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ # TODO CREATE A ENV WITH THIS NAME ### keep the .env name to .env.local if you want to change this name you should change it in here too when you load this env load_dotenv(".env.local") DOMAIN = os.getenv("DOMAIN") API_DOMAIN = os.getenv("API_DOMAIN") OPENAI_API_KEY = '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' # TODO update telegram bot token TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN") # TODO update email bullshit EMAIL_BACKEND = os.getenv("EMAIL_BACKEND") EMAIL_HOST = os.getenv("EMAIL_HOST") EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER") EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD") DEFAULT_FROM_EMAIL = os.getenv("SECRET_KEY") SECRET_KEY = os.getenv("SECRET_KEY") DEBUG = True # in production lists of allowed hosts and allowed orgins will genrate # in development every host and orgin will be true # in prodcution it will use the postgres info you enterd in .env.local # in development it will use the sqlite BASE_DIR = Path(__file__).resolve().parent.parent if DEBUG: ALLOWED_HOSTS = ['127.0.0.1', 'localhost', DOMAIN, API_DOMAIN] CSRF_TRUSTED_ORIGINS = [ f"https://{DOMAIN}", f"http://{DOMAIN}", f"https://{API_DOMAIN}", f"http://{API_DOMAIN}", ] # CORS_ALLOWED_ORIGINS = [f"https://{API_DOMAIN}", f"http://{API_DOMAIN}", # f"http://{DOMAIN}", f"https://{DOMAIN}", ] # import re # CORS_ALLOWED_ORIGIN_REGEXES = [ # re.compile(r'^https?://(?:\w+\.)?{}$'.format(re.escape(API_DOMAIN))), # re.compile(r'^https?://(?:\w+\.)?{}$'.format(re.escape(DOMAIN))), # re.compile(r'^https?://(?:\w+\.)?localhost:\d+$'), # re.compile(r'^https?://(?:\w+\.)?127\.0\.0\.1:\d+$'), # ] CORS_ALLOW_ALL_ORIGINS = True # database postgres DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': os.getenv("DB_NAME"), 'USER': os.getenv("DB_USER"), 'PASSWORD': os.getenv("DB_PASSWORD"), 'HOST': os.getenv("DB_HOST"), 'PORT': os.getenv("DB_PORT"), } } else: CORS_ALLOW_ALL_ORIGINS = True # sqlite database DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } } # Application definition INSTALLED_APPS = [ # unfold theme "unfold", "unfold.contrib.filters", "unfold.contrib.forms", "unfold.contrib.inlines", "unfold.contrib.import_export", "unfold.contrib.guardian", "unfold.contrib.simple_history", # django 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', # thired party apps 'corsheaders', 'rest_framework', 'drf_spectacular', 'django_cleanup.apps.CleanupConfig', 'django_filters', 'rest_framework_simplejwt', 'rest_framework_simplejwt.token_blacklist', 'rest_framework.authtoken', 'import_export', # custom apps 'product', 'account', 'ticket', 'chat', 'order', 'home', 'blog', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', "whitenoise.middleware.WhiteNoiseMiddleware", 'django.contrib.sessions.middleware.SessionMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'core.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 = 'core.wsgi.application' 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', }, ] LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_TZ = True MEDIA_URL = '/shop_media/' MEDIA_ROOT = '/app/media' STATIC_URL = '/shop_static/' STATIC_ROOT = '/app/static' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'custom_static'), # BASE_DIR / "core" / "static" ] STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' # AUTH_USER_MODEL = 'accounts.User' REST_FRAMEWORK = { # 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'], 'DEFAULT_RENDERER_CLASSES': [ 'rest_framework.renderers.JSONRenderer', 'rest_framework.renderers.BrowsableAPIRenderer', ], 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_simplejwt.authentication.JWTAuthentication', ), 'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema', # 'DEFAULT_PERMISSION_CLASSES': [ # 'rest_framework.permissions.IsAuthenticated', # ], } SIMPLE_JWT = { 'ACCESS_TOKEN_LIFETIME': timedelta(days=1), 'REFRESH_TOKEN_LIFETIME': timedelta(days=7), 'ROTATE_REFRESH_TOKENS': True, 'BLACKLIST_AFTER_ROTATION': True, } SPECTACULAR_SETTINGS = { 'TITLE': os.getenv("SITE_TITLE"), 'DESCRIPTION': os.getenv("SITE_TITLE"), 'VERSION': '1.0.0', 'SERVE_INCLUDE_SCHEMA': False, 'COMPONENT_SPLIT_REQUEST': True } UNFOLD = { "SITE_TITLE": os.getenv("SITE_TITLE"), "SITE_HEADER": os.getenv("SITE_HEADER"), "SITE_URL": DOMAIN, "SITE_SYMBOL": "shield_person", "SITE_FAVICONS": [ { "rel": "icon", "sizes": "32x32", "type": "image/svg+xml", "href": lambda request: static("favicon.svg"), }, ], # "LOGIN": { # "image": lambda request: static("robot.png"), # }, "BORDER_RADIUS": "15px", "SHOW_HISTORY": True, "SHOW_VIEW_ON_SITE": True, "ENVIRONMENT": "core.settings.environment_callback", "COLORS": { "base": { "50": "249 250 251", "100": "243 244 246", "200": "229 231 235", "300": "209 213 219", "400": "156 163 175", "500": "107 114 128", "600": "75 85 99", "700": "55 65 81", "800": "31 41 55", "900": "17 24 39", "950": "3 7 18" }, "primary": { "50": "255 241 242", "100": "255 228 230", "200": "254 205 211", "300": "253 164 175", "400": "251 113 133", "500": "244 63 94", "600": "225 29 72", "700": "190 18 60", "800": "159 18 57", "900": "136 19 55", "950": "76 5 25" }, "font": { "subtle-light": "var(--color-base-500)", # text-base-500 "subtle-dark": "var(--color-base-400)", # text-base-400 "default-light": "var(--color-base-600)", # text-base-600 "default-dark": "var(--color-base-300)", # text-base-300 "important-light": "var(--color-base-900)", # text-base-900 "important-dark": "var(--color-base-100)", # text-base-100 }, }, "EXTENSIONS": { "modeltranslation": { "flags": { "en": "🇬🇧", }, }, }, "SIDEBAR": { "show_search": False, "show_all_applications": False, "navigation": [ { "separator": False, # Top border "collapsible": False, # Collapsible group of links "items": [ { "title": _("داشبرد ادمین"), "icon": "dashboard", "link": reverse_lazy("admin:index"), }, { "title": _("سفارشات"), "icon": "shopping_cart", "link": reverse_lazy("admin:order_ordermodel_changelist"), "badge": "utils.admin.admin_pending_count", }, ], }, { "title": _("Shop Products"), "separator": True, "collapsible": False, "items": [ { "title": _("محصولات"), "icon": "redeem", "link": reverse_lazy("admin:product_productmodel_changelist"), }, { "title": _("نظرات"), "icon": "chat", "link": reverse_lazy("admin:product_commentmodel_changelist"), }, { "title": _("قیمت دلار"), "icon": "payments", "link": reverse_lazy("admin:product_dollormodel_changelist"), "badge": "utils.admin.dollor_price", }, ], }, { "title": _("Categories section"), "separator": True, "collapsible": False, "items": [ { "title": _("دسته بندی"), "icon": "category", "link": reverse_lazy("admin:product_maincategorymodel_changelist"), }, { "title": _("زیر دسته بندی"), "icon": "category", "link": reverse_lazy("admin:product_subcategorymodel_changelist"), } ], }, { "title": _("Visual Sections "), "separator": True, "collapsible": True, "items": [ { "title": _("اسلاید ها"), "icon": "slide_library", "link": reverse_lazy("admin:home_slidermodel_changelist"), }, { "title": _("عکس مقایسه"), "icon": "compare", "link": reverse_lazy("admin:home_homeimagemodel_changelist"), } , { "title": _("مقالات و بلاگ ها"), "icon": "newsmode", "link": reverse_lazy("admin:blog_blogmodel_changelist"), } ], }, { "title": _("Users and Customers"), "separator": True, "collapsible": True, "items": [ { "title": _("کاربران"), "icon": "person", "link": reverse_lazy("admin:account_user_changelist"), },{ "title": _("چت محصول"), "icon": "chat", "link": reverse_lazy("admin:chat_productchatmodel_changelist"), }, { "title": _("ادرس ها"), "icon": "contact_mail", "link": reverse_lazy("admin:account_useraddressmodel_changelist"), }, ], }, { "title": _("Ticket and Support"), "separator": True, "collapsible": True, "items": [ { "title": _("تیکت"), "icon": "confirmation_number", "link": reverse_lazy("admin:ticket_ticket_changelist"), }, ], }, ], }, } AUTH_USER_MODEL = 'account.User' def environment_callback(request): return ["Development", "danger"] def badge_callback(request): return 3