initial commit
This commit is contained in:
9
.env.example
Normal file
9
.env.example
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
SECRET_KEY=
|
||||||
|
DEBUG=True
|
||||||
|
ALLOWED_HOSTS=localhost,127.0.0.1
|
||||||
|
|
||||||
|
POSTGRES_DB=
|
||||||
|
POSTGRES_USER=
|
||||||
|
POSTGRES_PASSWORD=
|
||||||
|
POSTGRES_HOST=
|
||||||
|
POSTGRES_PORT=
|
||||||
267
.gitignore
vendored
Normal file
267
.gitignore
vendored
Normal file
@@ -0,0 +1,267 @@
|
|||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/python,django
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=python,django
|
||||||
|
|
||||||
|
### Django ###
|
||||||
|
*.log
|
||||||
|
*.pot
|
||||||
|
*.pyc
|
||||||
|
__pycache__/
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
resources/media
|
||||||
|
resources/static
|
||||||
|
|
||||||
|
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
|
||||||
|
# in your Git repository. Update and uncomment the following line accordingly.
|
||||||
|
# <django-project-name>/staticfiles/
|
||||||
|
|
||||||
|
### Django.Python Stack ###
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# poetry
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||||
|
#poetry.lock
|
||||||
|
|
||||||
|
# pdm
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||||
|
#pdm.lock
|
||||||
|
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||||
|
# in version control.
|
||||||
|
# https://pdm.fming.dev/#use-with-ide
|
||||||
|
.pdm.toml
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
# PyCharm
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
### Python ###
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
|
||||||
|
# poetry
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||||
|
|
||||||
|
# pdm
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||||
|
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||||
|
# in version control.
|
||||||
|
# https://pdm.fming.dev/#use-with-ide
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
|
||||||
|
# PyCharm
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
|
||||||
|
### Python Patch ###
|
||||||
|
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
||||||
|
poetry.toml
|
||||||
|
|
||||||
|
# ruff
|
||||||
|
.ruff_cache/
|
||||||
|
|
||||||
|
# LSP config files
|
||||||
|
pyrightconfig.json
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/python,django
|
||||||
0
config/__init__.py
Normal file
0
config/__init__.py
Normal file
16
config/asgi.py
Normal file
16
config/asgi.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
"""
|
||||||
|
ASGI config for config project.
|
||||||
|
|
||||||
|
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||||
|
|
||||||
|
For more information on this file, see
|
||||||
|
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base')
|
||||||
|
|
||||||
|
application = get_asgi_application()
|
||||||
4
config/conf/__init__.py
Normal file
4
config/conf/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
from .rest_framework import *
|
||||||
|
from .jwt import *
|
||||||
|
from .jazzmin import *
|
||||||
|
from .cache import *
|
||||||
24
config/conf/cache.py
Normal file
24
config/conf/cache.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
CACHES = {
|
||||||
|
"default": {
|
||||||
|
"BACKEND": 'django_redis.cache.RedisCache',
|
||||||
|
"LOCATION": 'redis://redis:6379',
|
||||||
|
"TIMEOUT": 300,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
CACHE_MIDDLEWARE_SECONDS = 300
|
||||||
|
|
||||||
|
|
||||||
|
CACHEOPS_REDIS = 'redis://redis:6379'
|
||||||
|
CACHEOPS_DEFAULTS = {
|
||||||
|
"timeout": 300,
|
||||||
|
}
|
||||||
|
|
||||||
|
CACHEOPS = {
|
||||||
|
"accounts.*": {
|
||||||
|
"ops": "all",
|
||||||
|
"timeout": 60 * 5,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
CACHEOPS_DEGRADE_ON_FAILURE = True
|
||||||
|
CACHEOPS_ENABLED = True
|
||||||
55
config/conf/jazzmin.py
Normal file
55
config/conf/jazzmin.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
JAZZMIN_SETTINGS = {
|
||||||
|
"site_title": "Avto Cargo Admin",
|
||||||
|
"site_header": "Avto Cargo",
|
||||||
|
"site_brand": "Avto Cargo",
|
||||||
|
"site_logo": None,
|
||||||
|
"login_logo": None,
|
||||||
|
"login_logo_dark": None,
|
||||||
|
"site_logo_classes": "img-circle",
|
||||||
|
"site_icon": None,
|
||||||
|
"welcome_sign": "Welcome to the Avto Cargo",
|
||||||
|
"copyright": "Acme Avto Cargo Ltd",
|
||||||
|
|
||||||
|
"search_model": ["auth.User"],
|
||||||
|
"user_avatar": None,
|
||||||
|
"topmenu_links": [
|
||||||
|
{"name": "Home", "url": "admin:index", "permissions": ["auth.view_user"]},
|
||||||
|
{"model": "auth.User"},
|
||||||
|
],
|
||||||
|
|
||||||
|
"usermenu_links": [
|
||||||
|
{"name": "Support", "url": "https://github.com/farridav/django-jazzmin/issues", "new_window": True},
|
||||||
|
{"model": "auth.user"}
|
||||||
|
],
|
||||||
|
|
||||||
|
"show_sidebar": True,
|
||||||
|
"navigation_expanded": True,
|
||||||
|
"hide_apps": [],
|
||||||
|
"hide_models": ["auth.Group"],
|
||||||
|
"order_with_respect_to": ["auth"],
|
||||||
|
|
||||||
|
"custom_links": {
|
||||||
|
"books": [{
|
||||||
|
"name": "Make Messages",
|
||||||
|
"url": "make_messages",
|
||||||
|
"icon": "fas fa-comments",
|
||||||
|
"permissions": ["books.view_book"]
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
|
||||||
|
"icons": {
|
||||||
|
"auth": "fas fa-users-cog",
|
||||||
|
"auth.user": "fas fa-user",
|
||||||
|
},
|
||||||
|
|
||||||
|
"default_icon_parents": "fas fa-chevron-circle-right",
|
||||||
|
"default_icon_children": "fas fa-circle",
|
||||||
|
|
||||||
|
"related_modal_active": True,
|
||||||
|
|
||||||
|
"use_google_fonts_cdn": True,
|
||||||
|
"show_ui_builder": False,
|
||||||
|
|
||||||
|
"changeform_format": "collapsible",
|
||||||
|
"language_chooser": False,
|
||||||
|
}
|
||||||
10
config/conf/jwt.py
Normal file
10
config/conf/jwt.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
|
||||||
|
SIMPLE_JWT = {
|
||||||
|
"ACCESS_TOKEN_LIFETIME": timedelta(days=5),
|
||||||
|
"REFRESH_TOKEN_LIFETIME": timedelta(days=90),
|
||||||
|
"ROTATE_REFRESH_TOKENS": True,
|
||||||
|
"BLACKLIST_AFTER_ROTATION": True,
|
||||||
|
"UPDATE_LAST_LOGIN": True,
|
||||||
|
}
|
||||||
12
config/conf/rest_framework.py
Normal file
12
config/conf/rest_framework.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
REST_FRAMEWORK = {
|
||||||
|
'DEFAULT_RENDERER_CLASSES': [
|
||||||
|
'rest_framework.renderers.JSONRenderer',
|
||||||
|
],
|
||||||
|
'DEFAULT_PARSER_CLASSES': [
|
||||||
|
'rest_framework.parsers.JSONParser',
|
||||||
|
],
|
||||||
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||||||
|
'rest_framework.authentication.BasicAuthentication',
|
||||||
|
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
||||||
|
]
|
||||||
|
}
|
||||||
9
config/env.py
Normal file
9
config/env.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
import environ
|
||||||
|
|
||||||
|
environ.Env.read_env(os.path.join('.env'))
|
||||||
|
|
||||||
|
|
||||||
|
env = environ.Env(
|
||||||
|
)
|
||||||
0
config/settings/__init__.py
Normal file
0
config/settings/__init__.py
Normal file
113
config/settings/base.py
Normal file
113
config/settings/base.py
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from config.env import env
|
||||||
|
|
||||||
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
||||||
|
|
||||||
|
|
||||||
|
SECRET_KEY = env.str('SECRET_KEY')
|
||||||
|
|
||||||
|
DEBUG = env.bool('DEBUG')
|
||||||
|
|
||||||
|
ALLOWED_HOSTS = env.list('ALLOWED_HOSTS')
|
||||||
|
|
||||||
|
|
||||||
|
INSTALLED_APPS = [
|
||||||
|
'jazzmin',
|
||||||
|
'django.contrib.admin',
|
||||||
|
'django.contrib.auth',
|
||||||
|
'django.contrib.contenttypes',
|
||||||
|
'django.contrib.sessions',
|
||||||
|
'django.contrib.messages',
|
||||||
|
'django.contrib.staticfiles',
|
||||||
|
# packages
|
||||||
|
'drf_yasg',
|
||||||
|
'rest_framework',
|
||||||
|
'rest_framework_simplejwt',
|
||||||
|
# apps
|
||||||
|
'core.apps.accounts',
|
||||||
|
'core.apps.orders',
|
||||||
|
'core.apps.common',
|
||||||
|
]
|
||||||
|
|
||||||
|
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',
|
||||||
|
]
|
||||||
|
|
||||||
|
ROOT_URLCONF = 'config.urls'
|
||||||
|
|
||||||
|
TEMPLATES = [
|
||||||
|
{
|
||||||
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
|
'DIRS': [],
|
||||||
|
'APP_DIRS': True,
|
||||||
|
'OPTIONS': {
|
||||||
|
'context_processors': [
|
||||||
|
'django.template.context_processors.request',
|
||||||
|
'django.contrib.auth.context_processors.auth',
|
||||||
|
'django.contrib.messages.context_processors.messages',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
WSGI_APPLICATION = 'config.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.postgresql',
|
||||||
|
'NAME': env.str('POSTGRES_DB'),
|
||||||
|
'USER': env.str('POSTGRES_USER'),
|
||||||
|
'PASSWORD': env.str('POSTGRES_PASSWORD'),
|
||||||
|
'HOST': env.str('POSTGRES_HOST'),
|
||||||
|
'PORT': env.str('POSTGRES_PORT'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 = 'uz'
|
||||||
|
|
||||||
|
TIME_ZONE = 'Asia/Tashkent'
|
||||||
|
|
||||||
|
USE_I18N = True
|
||||||
|
|
||||||
|
USE_TZ = False
|
||||||
|
|
||||||
|
|
||||||
|
STATIC_URL = 'static/'
|
||||||
|
STATIC_ROOT = BASE_DIR / 'resources/static'
|
||||||
|
|
||||||
|
MEDIA_URL = 'media/'
|
||||||
|
MEDIA_ROOT = BASE_DIR / 'resources/media'
|
||||||
|
|
||||||
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
|
AUTH_USER_MODEL = 'accounts.User'
|
||||||
|
|
||||||
|
from config.conf import *
|
||||||
0
config/settings/prod.py
Normal file
0
config/settings/prod.py
Normal file
0
config/settings/test.py
Normal file
0
config/settings/test.py
Normal file
39
config/urls.py
Normal file
39
config/urls.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from django.urls import path, include
|
||||||
|
from django.conf import settings
|
||||||
|
from django.conf.urls.static import static
|
||||||
|
|
||||||
|
from rest_framework.permissions import IsAdminUser
|
||||||
|
|
||||||
|
from drf_yasg.views import get_schema_view
|
||||||
|
from drf_yasg import openapi
|
||||||
|
|
||||||
|
|
||||||
|
schema_view = get_schema_view(
|
||||||
|
openapi.Info(
|
||||||
|
title="Avto Cargo API",
|
||||||
|
default_version='v1',
|
||||||
|
description="Avto Cargo",
|
||||||
|
terms_of_service="https://www.google.com/policies/terms/",
|
||||||
|
contact=openapi.Contact(email="contact@snippets.local"),
|
||||||
|
license=openapi.License(name="BSD License"),
|
||||||
|
),
|
||||||
|
public=False,
|
||||||
|
permission_classes=(IsAdminUser,),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('admin/', admin.site.urls),
|
||||||
|
|
||||||
|
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
|
||||||
|
path('api/v1/', include(
|
||||||
|
[
|
||||||
|
path('accounts/', include('core.apps.accounts.urls'))
|
||||||
|
]
|
||||||
|
))
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||||
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
16
config/wsgi.py
Normal file
16
config/wsgi.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
"""
|
||||||
|
WSGI config for config project.
|
||||||
|
|
||||||
|
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||||
|
|
||||||
|
For more information on this file, see
|
||||||
|
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base')
|
||||||
|
|
||||||
|
application = get_wsgi_application()
|
||||||
0
core/apps/accounts/__init__.py
Normal file
0
core/apps/accounts/__init__.py
Normal file
3
core/apps/accounts/admin.py
Normal file
3
core/apps/accounts/admin.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
6
core/apps/accounts/apps.py
Normal file
6
core/apps/accounts/apps.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class AccountsConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'core.apps.accounts'
|
||||||
30
core/apps/accounts/cache.py
Normal file
30
core/apps/accounts/cache.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import redis
|
||||||
|
|
||||||
|
r = redis.StrictRedis.from_url('redis://redis:6379')
|
||||||
|
|
||||||
|
def cache_user_credentials(email, password, passport_id, pnlf, time):
|
||||||
|
key = f"user_credentials:{email}"
|
||||||
|
|
||||||
|
r.hmset(key, {
|
||||||
|
"email": email,
|
||||||
|
"password": password,
|
||||||
|
"passport_id": passport_id,
|
||||||
|
"pnlf": pnlf,
|
||||||
|
})
|
||||||
|
|
||||||
|
r.expire(key, time)
|
||||||
|
|
||||||
|
def get_user_credentials(email):
|
||||||
|
key = f"user_credentials:{email}"
|
||||||
|
|
||||||
|
data = r.hgetall(key)
|
||||||
|
if not data:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return {
|
||||||
|
"email": data.get(b'email').decode() if data.get(b'email') else None,
|
||||||
|
"password": data.get(b'password').decode() if data.get(b'password') else None,
|
||||||
|
"passport_id": data.get(b'passport_id').decode() if data.get(b'passport_id') else None,
|
||||||
|
"pnlf": data.get(b'pnlf').decode() if data.get(b'pnlf') else None,
|
||||||
|
}
|
||||||
|
|
||||||
33
core/apps/accounts/manager.py
Normal file
33
core/apps/accounts/manager.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
from django.contrib.auth.models import UserManager as DjangoUserManager
|
||||||
|
from django.contrib.auth.hashers import make_password
|
||||||
|
|
||||||
|
|
||||||
|
class UserManager(DjangoUserManager):
|
||||||
|
def _create_user_object(self, email, password, **extra_fields):
|
||||||
|
if not email:
|
||||||
|
raise ValueError("The given email must be set")
|
||||||
|
email = self.normalize_email(email)
|
||||||
|
user = self.model(email=email, **extra_fields)
|
||||||
|
user.password = make_password(password)
|
||||||
|
return user
|
||||||
|
|
||||||
|
def _create_user(self, email, password, **extra_fields):
|
||||||
|
user = self._create_user_object(email, password, **extra_fields)
|
||||||
|
user.save(using=self._db)
|
||||||
|
return user
|
||||||
|
|
||||||
|
def create_user(self, email, password=None, **extra_fields):
|
||||||
|
extra_fields.setdefault("is_staff", False)
|
||||||
|
extra_fields.setdefault("is_superuser", False)
|
||||||
|
return self._create_user(email, password, **extra_fields)
|
||||||
|
|
||||||
|
def create_superuser(self, email, password=None, **extra_fields):
|
||||||
|
extra_fields.setdefault("is_staff", True)
|
||||||
|
extra_fields.setdefault("is_superuser", True)
|
||||||
|
|
||||||
|
if extra_fields.get("is_staff") is not True:
|
||||||
|
raise ValueError("Superuser must have is_staff=True.")
|
||||||
|
if extra_fields.get("is_superuser") is not True:
|
||||||
|
raise ValueError("Superuser must have is_superuser=True.")
|
||||||
|
|
||||||
|
return self._create_user(email, password, **extra_fields)
|
||||||
42
core/apps/accounts/migrations/0001_initial.py
Normal file
42
core/apps/accounts/migrations/0001_initial.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Generated by Django 5.2 on 2025-08-25 16:14
|
||||||
|
|
||||||
|
import django.contrib.auth.models
|
||||||
|
import django.utils.timezone
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('auth', '0012_alter_user_first_name_max_length'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='User',
|
||||||
|
fields=[
|
||||||
|
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||||
|
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
||||||
|
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||||
|
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||||
|
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
||||||
|
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
||||||
|
('id', models.UUIDField(db_index=True, editable=False, primary_key=True, serialize=False, unique=True)),
|
||||||
|
('created_at', models.DateField(auto_now_add=True)),
|
||||||
|
('updated_at', models.DateField(auto_now=True)),
|
||||||
|
('full_name', models.CharField(max_length=200)),
|
||||||
|
('email', models.EmailField(max_length=254, unique=True)),
|
||||||
|
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
|
||||||
|
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'foydalanuvchi',
|
||||||
|
'verbose_name_plural': 'foydalanuvchilar',
|
||||||
|
},
|
||||||
|
managers=[
|
||||||
|
('objects', django.contrib.auth.models.UserManager()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
20
core/apps/accounts/migrations/0002_alter_user_managers.py
Normal file
20
core/apps/accounts/migrations/0002_alter_user_managers.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 5.2 on 2025-08-25 16:18
|
||||||
|
|
||||||
|
import core.apps.accounts.manager
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('accounts', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelManagers(
|
||||||
|
name='user',
|
||||||
|
managers=[
|
||||||
|
('objects', core.apps.accounts.manager.UserManager()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Generated by Django 5.2 on 2025-08-25 16:30
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('accounts', '0002_alter_user_managers'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='passport_id',
|
||||||
|
field=models.CharField(max_length=20, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='pnfl',
|
||||||
|
field=models.CharField(max_length=20, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='id',
|
||||||
|
field=models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
0
core/apps/accounts/migrations/__init__.py
Normal file
0
core/apps/accounts/migrations/__init__.py
Normal file
27
core/apps/accounts/models.py
Normal file
27
core/apps/accounts/models.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from django.db import models
|
||||||
|
from django.contrib.auth.models import AbstractUser
|
||||||
|
|
||||||
|
from core.apps.common.models import BaseModel
|
||||||
|
from core.apps.accounts.manager import UserManager
|
||||||
|
|
||||||
|
|
||||||
|
class User(AbstractUser, BaseModel):
|
||||||
|
full_name = models.CharField(max_length=200)
|
||||||
|
email = models.EmailField(unique=True)
|
||||||
|
passport_id = models.CharField(max_length=20, null=True)
|
||||||
|
pnfl = models.CharField(max_length=20, null=True)
|
||||||
|
|
||||||
|
first_name = None
|
||||||
|
last_name = None
|
||||||
|
username = None
|
||||||
|
objects = UserManager()
|
||||||
|
|
||||||
|
USERNAME_FIELD = 'email'
|
||||||
|
REQUIRED_FIELDS = []
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.email
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = 'foydalanuvchi'
|
||||||
|
verbose_name_plural = 'foydalanuvchilar'
|
||||||
20
core/apps/accounts/serializers.py
Normal file
20
core/apps/accounts/serializers.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
from django.db import transaction
|
||||||
|
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from core.apps.accounts.models import User
|
||||||
|
from core.apps.accounts.cache import get_user_credentials
|
||||||
|
|
||||||
|
|
||||||
|
class RegisterSerializer(serializers.ModelSerializer):
|
||||||
|
passport_id = serializers.CharField()
|
||||||
|
pnfl = serializers.CharField()
|
||||||
|
email = serializers.EmailField()
|
||||||
|
password = serializers.CharField()
|
||||||
|
|
||||||
|
def validate_email(self, value):
|
||||||
|
if User.objects.filter(email=value).exists():
|
||||||
|
raise serializers.ValidationError("User with this email already exists")
|
||||||
|
if get_user_credentials(value):
|
||||||
|
raise serializers.ValidationError("User with this email already exists")
|
||||||
|
return value
|
||||||
3
core/apps/accounts/tests.py
Normal file
3
core/apps/accounts/tests.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
8
core/apps/accounts/urls.py
Normal file
8
core/apps/accounts/urls.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from django.urls import path, include
|
||||||
|
|
||||||
|
from rest_framework_simplejwt.views import TokenObtainPairView
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('login/', TokenObtainPairView.as_view()),
|
||||||
|
]
|
||||||
23
core/apps/accounts/views.py
Normal file
23
core/apps/accounts/views.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
from rest_framework import generics, views
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
from core.apps.accounts import serializers
|
||||||
|
from core.apps.accounts import models
|
||||||
|
from core.apps.accounts.cache import cache_user_credentials
|
||||||
|
|
||||||
|
class RegisterApiView(generics.GenericAPIView):
|
||||||
|
serializer_class = serializers.RegisterSerializer
|
||||||
|
queryset = models.User.objects.all()
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
serializer = self.serializer_class(data=request.data)
|
||||||
|
if serializer.is_valid(raise_exception=True):
|
||||||
|
data = serializer.validated_data
|
||||||
|
cache_user_credentials(
|
||||||
|
email=data['email'], password=data['password'],
|
||||||
|
passport_id=data['passport_id'], pnlf=data['pnlf'], time=60*5
|
||||||
|
)
|
||||||
|
return Response(
|
||||||
|
{'success': True, 'message': "code sent"},
|
||||||
|
status=200
|
||||||
|
)
|
||||||
0
core/apps/common/__init__.py
Normal file
0
core/apps/common/__init__.py
Normal file
3
core/apps/common/admin.py
Normal file
3
core/apps/common/admin.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
6
core/apps/common/apps.py
Normal file
6
core/apps/common/apps.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class CommonConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'core.apps.common'
|
||||||
0
core/apps/common/migrations/__init__.py
Normal file
0
core/apps/common/migrations/__init__.py
Normal file
11
core/apps/common/models.py
Normal file
11
core/apps/common/models.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import uuid
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class BaseModel(models.Model):
|
||||||
|
id = models.UUIDField(primary_key=True, editable=False, unique=True, db_index=True, default=uuid.uuid4)
|
||||||
|
created_at = models.DateField(auto_now_add=True)
|
||||||
|
updated_at = models.DateField(auto_now=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
3
core/apps/common/tests.py
Normal file
3
core/apps/common/tests.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
3
core/apps/common/views.py
Normal file
3
core/apps/common/views.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
0
core/apps/orders/__init__.py
Normal file
0
core/apps/orders/__init__.py
Normal file
3
core/apps/orders/admin.py
Normal file
3
core/apps/orders/admin.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
6
core/apps/orders/apps.py
Normal file
6
core/apps/orders/apps.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class OrdersConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'core.apps.orders'
|
||||||
0
core/apps/orders/migrations/__init__.py
Normal file
0
core/apps/orders/migrations/__init__.py
Normal file
3
core/apps/orders/models.py
Normal file
3
core/apps/orders/models.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
3
core/apps/orders/tests.py
Normal file
3
core/apps/orders/tests.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
3
core/apps/orders/views.py
Normal file
3
core/apps/orders/views.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
55
docker-compose.yaml
Normal file
55
docker-compose.yaml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
networks:
|
||||||
|
avto_cargo:
|
||||||
|
driver: bridge
|
||||||
|
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pd_data: null
|
||||||
|
|
||||||
|
services:
|
||||||
|
nginx:
|
||||||
|
networks:
|
||||||
|
- avto_cargo
|
||||||
|
ports:
|
||||||
|
- ${PORT:-8001}:80
|
||||||
|
volumes:
|
||||||
|
- ./resources/layout/nginx.conf/:/etc/nginx/nginx.conf
|
||||||
|
- ./resources/:/usr/share/nginx/html/resources/
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./docker/Dockerfile.nginx
|
||||||
|
depends_on:
|
||||||
|
- web
|
||||||
|
|
||||||
|
web:
|
||||||
|
networks:
|
||||||
|
- avto_cargo
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./docker/Dockerfile.web
|
||||||
|
command: ${COMMAND:-sh ./resources/scripts/entrypoint.sh}
|
||||||
|
environment:
|
||||||
|
- PYTHONPYCACHEPREFIX=/var/cache/pycache
|
||||||
|
volumes:
|
||||||
|
- ./:/code
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
- redis
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:17
|
||||||
|
networks:
|
||||||
|
- avto_cargo
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||||
|
POSTGRES_USER: ${POSTGRES_USER}
|
||||||
|
POSTGRES_DB: ${POSTGRES_DB}
|
||||||
|
volumes:
|
||||||
|
- pd_data:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
redis:
|
||||||
|
networks:
|
||||||
|
- avto_cargo
|
||||||
|
image: redis
|
||||||
|
ports:
|
||||||
|
- "6380:6379"
|
||||||
3
docker/Dockerfile.nginx
Normal file
3
docker/Dockerfile.nginx
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
COPY ./resources/layout/nginx.conf /etc/nginx/nginx.conf
|
||||||
14
docker/Dockerfile.web
Normal file
14
docker/Dockerfile.web
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
FROM python:3.13-alpine
|
||||||
|
|
||||||
|
ENV PYCACHEPREFIX=/dev/null
|
||||||
|
|
||||||
|
RUN apk update && apk add git gettext
|
||||||
|
|
||||||
|
WORKDIR /code
|
||||||
|
|
||||||
|
COPY requirements.txt /code/requirements.txt
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
|
||||||
|
|
||||||
|
CMD ["sh", "./entrypoint.sh"]
|
||||||
|
|
||||||
22
manage.py
Executable file
22
manage.py
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
"""Django's command-line utility for administrative tasks."""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Run administrative tasks."""
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base')
|
||||||
|
try:
|
||||||
|
from django.core.management import execute_from_command_line
|
||||||
|
except ImportError as exc:
|
||||||
|
raise ImportError(
|
||||||
|
"Couldn't import Django. Are you sure it's installed and "
|
||||||
|
"available on your PYTHONPATH environment variable? Did you "
|
||||||
|
"forget to activate a virtual environment?"
|
||||||
|
) from exc
|
||||||
|
execute_from_command_line(sys.argv)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
22
requirements.txt
Normal file
22
requirements.txt
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
asgiref==3.9.1
|
||||||
|
click==8.2.1
|
||||||
|
Django==5.2
|
||||||
|
django-cacheops==7.2
|
||||||
|
django-environ==0.12.0
|
||||||
|
django-jazzmin==3.0.1
|
||||||
|
djangorestframework==3.16.1
|
||||||
|
djangorestframework_simplejwt==5.5.1
|
||||||
|
drf-yasg==1.21.10
|
||||||
|
funcy==2.0
|
||||||
|
gunicorn==23.0.0
|
||||||
|
h11==0.16.0
|
||||||
|
inflection==0.5.1
|
||||||
|
packaging==25.0
|
||||||
|
psycopg2-binary==2.9.10
|
||||||
|
PyJWT==2.10.1
|
||||||
|
pytz==2025.2
|
||||||
|
PyYAML==6.0.2
|
||||||
|
redis==6.4.0
|
||||||
|
sqlparse==0.5.3
|
||||||
|
uritemplate==4.2.0
|
||||||
|
uvicorn==0.35.0
|
||||||
13
resources/layout/Dockerfile.alpine
Normal file
13
resources/layout/Dockerfile.alpine
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
FROM python:3.13-alpine
|
||||||
|
|
||||||
|
ENV PYTHONPYCACHEPREFIX=/dev/null
|
||||||
|
|
||||||
|
RUN apk update && apk add git gettext
|
||||||
|
|
||||||
|
WORKDIR /code
|
||||||
|
|
||||||
|
COPY requirements.txt /code/requirements.txt
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
|
||||||
|
|
||||||
|
CMD ["sh", "./entrypoint.sh"]
|
||||||
3
resources/layout/Dockerfile.nginx
Normal file
3
resources/layout/Dockerfile.nginx
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
COPY ./resources/layout/nginx.conf /etc/nginx/nginx.conf
|
||||||
52
resources/layout/nginx.conf
Normal file
52
resources/layout/nginx.conf
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
worker_processes 1;
|
||||||
|
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
include mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
|
||||||
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||||
|
'$status $body_bytes_sent "$http_referer" '
|
||||||
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||||
|
access_log /var/log/nginx/access.log main;
|
||||||
|
|
||||||
|
sendfile on;
|
||||||
|
tcp_nopush on;
|
||||||
|
tcp_nodelay on;
|
||||||
|
keepalive_timeout 65;
|
||||||
|
types_hash_max_size 2048;
|
||||||
|
client_max_body_size 1024M;
|
||||||
|
|
||||||
|
# Server block for handling requests
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://web:8000;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto https;
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
}
|
||||||
|
location /ws/ {
|
||||||
|
proxy_pass http://web:8000; # Uvicorn serveri ishga tushadigan port
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /static/ {
|
||||||
|
alias /usr/share/nginx/html/resources/static/;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /media/ {
|
||||||
|
alias /usr/share/nginx/html/resources/media/;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
resources/scripts/backup.sh
Normal file
5
resources/scripts/backup.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
file=/tmp/db-$(/usr/bin/date +\%Y-%m-%d-%H:%M:%S).sql
|
||||||
|
container=postgres
|
||||||
|
/usr/bin/docker container exec $container pg_dump -U postgres django > $file
|
||||||
|
mc cp $file b2/buket-name
|
||||||
|
rm $file
|
||||||
8
resources/scripts/entrypoint-server.sh
Normal file
8
resources/scripts/entrypoint-server.sh
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
python3 manage.py collectstatic --noinput
|
||||||
|
python3 manage.py migrate --noinput
|
||||||
|
|
||||||
|
gunicorn config.wsgi:application -b 0.0.0.0:8000 --workers $(($(nproc) * 2 + 1))
|
||||||
|
|
||||||
|
|
||||||
|
exit $?
|
||||||
7
resources/scripts/entrypoint.sh
Normal file
7
resources/scripts/entrypoint.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
python3 manage.py collectstatic --noinput
|
||||||
|
python3 manage.py migrate --noinput
|
||||||
|
|
||||||
|
uvicorn config.asgi:application --host 0.0.0.0 --port 8000 --reload --reload-dir core --reload-dir config
|
||||||
|
|
||||||
|
exit $?
|
||||||
Reference in New Issue
Block a user