Skip to content

Commit

Permalink
end project
Browse files Browse the repository at this point in the history
  • Loading branch information
RustamovAkrom committed Oct 4, 2024
1 parent 61a2919 commit 0ff596a
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 15 deletions.
12 changes: 7 additions & 5 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ DEBUG=DEBUG


# Django PostgreSQL database configurations
POSTGRES_DB_NAME=POSTGRES_DB_NAME
POSTGRES_DB_PASSWORD=POSTGRES_DB_PASSWORD
POSTGRES_DB_USER=POSTGRES_DB_USER
POSTGRES_DB_HOST=POSTGRES_DB_HOST
POSTGRES_DD_PORT=POSTGRES_DB_PORT
POSTGRES_NAME=POSTGRES_DB_NAME
POSTGRES_PASSWORD=POSTGRES_DB_PASSWORD
POSTGRES_USER=POSTGRES_DB_USER
POSTGRES_HOST=POSTGRES_DB_HOST
POSTGRES_PORT=POSTGRES_DB_PORT

CELERY_BROKER_URL=CELERY_BROKER_URL
10 changes: 0 additions & 10 deletions Dockerfile

This file was deleted.

14 changes: 14 additions & 0 deletions core/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
from celery import Celery
from django.conf import settings


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")

app = Celery("core", broker=settings.CELERY_BROCKER_URL)
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

@app.task(bind=True)
def debug_task(self):
print(f"Request: {self.request!r}")
3 changes: 3 additions & 0 deletions core/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from .apps import * # noqa
from .celery import * # noqa
from .email import * # noqa
from .stripe import * # noqa
12 changes: 12 additions & 0 deletions core/config/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os

CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL")
CELERY_RESULT_BACKEND = "django-db"
CELERY_ACCEPT_CONTENT = ["application/json"]
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_SERIALIZER = "json"
CELERY_TIMEZONE = "Asia/Tashkent"
CELERY_TASK_TRACK_STARTED = True
CELERY_TASK_TIME_LIMIT = 30 * 60 # 30m
CELERY_CACHE_BACKEND = "default"
CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
10 changes: 10 additions & 0 deletions core/config/email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os

# EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD")
EMAIL_USE_TLS = True
5 changes: 5 additions & 0 deletions core/config/stripe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os


STRIPE_API_KEY = os.getenv("STRIPE_API_KEY")
STRIPE_API_VERSION = os.getenv("STRIPE_API_VERSION")
108 changes: 108 additions & 0 deletions core/settings/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from pathlib import Path
import os

from dotenv import load_dotenv

from core.config import DJANGO_DEFAULT_APPS, PROJECT_APPS, THIRTY_PARTY_APPS

from django.utils.translation import gettext_lazy

load_dotenv()

BASE_DIR = Path(__file__).resolve().parent.parent

SECRET_KEY = os.getenv("SECRET_KEY")

DEBUG = os.getenv("DEBUG") in ["true", "1", True]

ALLOWED_HOSTS = os.getenv("DJANGO_ALLOWED_HOSTS", 'localhost').split()

INSTALLED_APPS = DJANGO_DEFAULT_APPS + PROJECT_APPS + THIRTY_PARTY_APPS

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.locale.LocaleMiddleware",
"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": [BASE_DIR.joinpath("templates")],
"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",
"apps.shop.context_processors.categories",
"apps.cart.context_processors.cart",
],
},
},
]

WSGI_APPLICATION = "core.wsgi.application"

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}

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",
},
]


def gettext(_: str):
return gettext_lazy(_)


LANGUAGE_CODE = "en-us"

TIME_ZONE = "Asia/Tashkent"

USE_I18N = True

USE_TZ = True

LANGUAGES = [
("en", gettext("English")),
("uz", gettext("Uzbek")),
]

MODELTRANSLATION_DEFAULT_LANGUAGE = "en"

STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR.joinpath("staticfiles")
STATICFILES_DIRS = [BASE_DIR.joinpath("static")]

MEDIA_URL = "media/"
MEDIA_ROOT = BASE_DIR.joinpath("media")

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

AUTH_USER_MODEL = "account.CustomUser"

CART_SESSION_ID = "cart"
Empty file added core/settings/development.py
Empty file.
13 changes: 13 additions & 0 deletions core/settings/production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os


DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.getenv('POSTGRES_NAME'),
'PASSWORD': os.getenv('POSTGRES_PASSWORD'),
'USER': os.getenv('POSTGRES_USER', 'postgres'),
'HOST': os.getenv('POSTGRES_HOST', 'localhost'),
'PORT': os.getenv('POSTGRES_PORT', 5432)
}
}

0 comments on commit 0ff596a

Please sign in to comment.