diff --git a/app/.env.example b/.env.example similarity index 100% rename from app/.env.example rename to .env.example diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f2e1699 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +# syntax=docker/dockerfile:1 +FROM python:3 +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 +WORKDIR /code +COPY requirements/* /code/ +RUN pip install -r prod.txt +COPY . /code/ diff --git a/README.md b/README.md index 1650d7c..fe303fb 100644 --- a/README.md +++ b/README.md @@ -1 +1,36 @@ -# backend \ No newline at end of file +# backend + +#### Веб-сервер, для обработки и хранения информации о пользователях и их операциях +# +Стек технологий: +- Django, DRF, Channels +- Celery +- Postgresql +- Swagger + +## Сборка из исходного кода +#### Установка зависимостей +```shell +$ python3 -m venv venv +$ source venv/bin/activate +$ cd app +$ pip install -r reuirements/base.txt +$ mv .env.example .env +``` + +#### Подготовка бд +```shell +$ python3 manage.py makemigrations && python3 manage.py migrate users +$ python3 manage.py migrate +$ python manage.py loaddata departmens.json +``` + +#### Запуск веб сервера +```shell +$ python3 manage.py runserver +``` + +#### Запуск celery +```shell +$ celery -A conf worker --loglevel=INFO +``` \ No newline at end of file diff --git a/app/conf/settings/base.py b/app/conf/settings/base.py index b44fa7c..2840b31 100644 --- a/app/conf/settings/base.py +++ b/app/conf/settings/base.py @@ -3,12 +3,13 @@ from pathlib import Path import environ ROOT_DIR = Path(__file__).resolve(strict=True).parent.parent.parent +ENV_DIR = ROOT_DIR.parent env = environ.Env() READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=True) if READ_DOT_ENV_FILE: # OS environment variables take precedence over variables from .env - env.read_env(str(ROOT_DIR / ".env")) + env.read_env(str(ENV_DIR / ".env")) # GENERAL # ------------------------------------------------------------------------------ diff --git a/app/conf/settings/deploy.py b/app/conf/settings/deploy.py new file mode 100644 index 0000000..773cfc4 --- /dev/null +++ b/app/conf/settings/deploy.py @@ -0,0 +1 @@ +from .base import * \ No newline at end of file diff --git a/app/events/models.py b/app/events/models.py index 9e51695..31c403b 100644 --- a/app/events/models.py +++ b/app/events/models.py @@ -29,7 +29,6 @@ class Event(models.Model): class EventAttendance(models.Model): event = models.ForeignKey(Event, related_name="people", on_delete=models.CASCADE) worker = models.ForeignKey(User, related_name="events", on_delete=models.CASCADE) - token = models.CharField(blank=False, unique=True, max_length=128) attended = models.BooleanField(default=False) @property diff --git a/app/events/signals.py b/app/events/signals.py index 0c4f4e2..31a57c3 100644 --- a/app/events/signals.py +++ b/app/events/signals.py @@ -10,13 +10,8 @@ from .models import EventAttendance, Event @receiver(post_save, sender=EventAttendance) def create_attendance(sender, instance, created, **kwargs): if created: - token = generate_charset(25) - while EventAttendance.objects.filter(token=token).exists(): - token = generate_charset(25) - instance.token = token - instance.event.planning += 1 - instance.event.save(update_fields=["planning", "token"]) + instance.event.save(update_fields=["planning"]) @receiver(post_save, sender=Event) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0ba463d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: "3.9" + +services: + db: + image: postgres + volumes: + - ./data/db:/var/lib/postgresql/data + environment: + - POSTGRES_DB=moretech + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=debug + web: + build: . + command: python manage.py runserver 0.0.0.0:8000 + volumes: + - .:/code + ports: + - "8000:8000" + environment: + - POSTGRES_NAME=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + depends_on: + - db + diff --git a/app/requirements/base.txt b/requirements/base.txt similarity index 100% rename from app/requirements/base.txt rename to requirements/base.txt diff --git a/requirements/prod.txt b/requirements/prod.txt new file mode 100644 index 0000000..222c15a --- /dev/null +++ b/requirements/prod.txt @@ -0,0 +1,3 @@ +-r base.txt + +gunicorn \ No newline at end of file