[init] project

This commit is contained in:
Data-Name-ID
2024-04-02 00:51:49 +03:00
commit 52233d0028
28 changed files with 685 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
# Folders
venv/
__pycache__/
+165
View File
@@ -0,0 +1,165 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.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
*.pot
# Django stuff:
*.log
local_settings.py
*.sqlite3
*.sqlite3-journal
# 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/
# Django stuff
cache
media
static/
+9
View File
@@ -0,0 +1,9 @@
FROM python:3.12-slim
WORKDIR /app
COPY requirements/prod.txt .
RUN pip install --no-cache-dir -r prod.txt
COPY . .
+33
View File
@@ -0,0 +1,33 @@
dump:
@cd project && python -Xutf8 manage.py dumpdata --format json --indent 4 -o fixtures/data.json
load:
@cd project && python -Xutf8 manage.py loaddata fixtures/data.json
mig:
@cd project && python manage.py makemigrations
@cd project && python manage.py migrate
check: test
@ruff check --fix
test:
@cd project && python manage.py test
run:
@cd project && python manage.py runserver
su:
@cd project && python manage.py createsuperuser
loc-m:
@cd project && django-admin makemessages -l ru -l en
loc-c:
@cd project && django-admin compilemessages
help:
@cd project && python manage.py help
sort:
sort-requirements requirements/prod.txt requirements/test.txt requirements/dev.txt
+1
View File
@@ -0,0 +1 @@
# SkillHub Backend
View File
+6
View File
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ApiConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "api"
+3
View File
@@ -0,0 +1,3 @@
from django.urls import include, path
urlpatterns = []
View File
+7
View File
@@ -0,0 +1,7 @@
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
application = get_asgi_application()
+148
View File
@@ -0,0 +1,148 @@
import sys
from pathlib import Path
from environs import Env
BASE_DIR = Path(__file__).resolve().parent.parent
env = Env()
env.read_env(BASE_DIR.parent / ".env")
DEFAULT_HOSTS = ["127.0.0.1", "localhost"]
with env.prefixed("DJANGO_"):
SECRET_KEY = env("SECRET_KEY", "change-me")
DEBUG = env.bool("DEBUG", False)
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", DEFAULT_HOSTS)
INTERNAL_IPS = env.list("INTERNAL_IPS", ALLOWED_HOSTS)
CSRF_TRUSTED_ORIGINS = env.list("CSRF_TRUSTED_ORIGINS", [])
DB_NAME = env("DB_NAME", "db.sqlite3")
with env.prefixed("POSTGRES_"):
if not DEBUG:
POSTGRES_DB = env("DB", "postgres")
POSTGRES_USER = env("USER", "postgres")
POSTGRES_PASSWORD = env("PASSWORD", "postgres")
POSTGRES_HOST = env("HOST", "localhost")
POSTGRES_PORT = env("PORT", "5432")
TESTING = len(sys.argv) > 1 and sys.argv[1] == "test"
MIGRATING = len(sys.argv) > 1 and (
"migrate" in sys.argv[1] or "makemigrations" in sys.argv[1]
)
INSTALLED_APPS = [
# Built-in apps
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# Third-party apps
"rest_framework",
"corsheaders",
"drf_yasg",
# Developed apps
]
MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
"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_DIR = BASE_DIR / "templates"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [TEMPLATES_DIR],
"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 = "config.wsgi.application"
if DEBUG:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / DB_NAME,
},
}
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": POSTGRES_DB,
"USER": POSTGRES_USER,
"PASSWORD": POSTGRES_PASSWORD,
"HOST": POSTGRES_HOST,
"PORT": 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"
),
},
]
USE_I18N = True
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_TZ = True
STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / "static"
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
REST_FRAMEWORK = {
"DEFAULT_FILTER_BACKENDS": [
"django_filters.rest_framework.DjangoFilterBackend"
],
}
if DEBUG and not (TESTING or MIGRATING):
INSTALLED_APPS.append("debug_toolbar")
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
+30
View File
@@ -0,0 +1,30 @@
from django.conf import settings
from django.contrib import admin
from django.urls import include, path
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
schema_view = get_schema_view(
openapi.Info(title="SkillHub API", default_version="1")
)
urlpatterns = [
# Built-in urls
path("admin/", admin.site.urls),
# API documentation
path(
"swagger/",
schema_view.with_ui("swagger"),
name="swagger",
),
path(
"redoc/",
schema_view.with_ui("redoc"),
name="redoc",
),
# API
path("api/", include("api.urls")),
]
if settings.DEBUG and not (settings.TESTING or settings.MIGRATING):
urlpatterns += (path("__debug__/", include("debug_toolbar.urls")),)
+7
View File
@@ -0,0 +1,7 @@
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
application = get_wsgi_application()
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env python
import os
import sys
def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
msg = (
"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?"
)
raise ImportError(msg) from exc
execute_from_command_line(sys.argv)
if __name__ == "__main__":
main()
+10
View File
@@ -0,0 +1,10 @@
[tool.ruff]
line-length = 79
exclude = ["migrations"]
[tool.ruff.lint]
select = ["ALL"]
ignore = ["D", "ANN", "EXE002", "RUF012", "RUF001", "COM812", "ISC001"]
[tool.ruff.format]
skip-magic-trailing-comma = false
+4
View File
@@ -0,0 +1,4 @@
django-debug-toolbar==4.3.0
-r test.txt
-r lint.txt
+2
View File
@@ -0,0 +1,2 @@
sort-requirements
ruff
+10
View File
@@ -0,0 +1,10 @@
django==4.2.11
environs==11.0.0
gunicorn==21.2.0
psycopg2-binary==2.9.9
djangorestframework==3.15.1
django-filter==24.2
Pillow==10.2.0
drf-yasg==1.21.7
django-cors-headers
setuptools
+1
View File
@@ -0,0 +1 @@
-r prod.txt
+18
View File
@@ -0,0 +1,18 @@
# For django app
DJANGO_SECRET_KEY = your-secret-key
DJANGO_DEBUG = False
DJANGO_ALLOWED_HOSTS = 127.0.0.1,localhost
DJANGO_INTERNAL_IPS = 127.0.0.1,localhost
DJANGO_CSRF_TRUSTED_ORIGINS = http://127.0.0.1:8000,localhost
# For docker(remove if you want to keep defaults)
POSTGRES_PORT = <port_to_be_forwared> # default: 5432
POSTGRES_DB = <db_name> # default: postgres
POSTGRES_USER = <postgres_user> # default: postgres
POSTGRES_PASSWORD = <password> # default: postgres
PGADMIN_PORT = <port_to_be_forwared> # default: 5050
PGADMIN_EMAIL = <email> # default: admin@mail.com
PGADMIN_PASSWORD = <password> # default: admin