From 5d06cceb26ea9c72d3f64960b7083d8a0f4af75a Mon Sep 17 00:00:00 2001 From: Nadya2502 Date: Fri, 9 Feb 2024 15:19:28 +0100 Subject: [PATCH 1/4] =?UTF-8?q?=D0=92=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B8=20general=20=D1=81=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D0=B0=D0=BB=D0=B0=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C?= =?UTF-8?q?=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=BE=D0=B2=D1=8B=D1=85=20?= =?UTF-8?q?=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20=D0=B3?= =?UTF-8?q?=D0=BB=D0=B0=D0=B2=D0=BD=D0=BE=D0=B9=20=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=86=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/apps/general/apps.py | 6 ++++ .../apps/general/migrations/0001_initial.py | 36 +++++++++++++++++++ .../apps/general/migrations/__init__.py | 0 src/backend/apps/general/models.py | 14 ++++++++ src/backend/apps/general/serializers.py | 9 +++++ src/backend/apps/general/views.py | 9 +++++ 6 files changed, 74 insertions(+) create mode 100644 src/backend/apps/general/apps.py create mode 100644 src/backend/apps/general/migrations/0001_initial.py create mode 100644 src/backend/apps/general/migrations/__init__.py create mode 100644 src/backend/apps/general/serializers.py create mode 100644 src/backend/apps/general/views.py diff --git a/src/backend/apps/general/apps.py b/src/backend/apps/general/apps.py new file mode 100644 index 0000000..b7fc242 --- /dev/null +++ b/src/backend/apps/general/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class GeneralConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "apps.general" diff --git a/src/backend/apps/general/migrations/0001_initial.py b/src/backend/apps/general/migrations/0001_initial.py new file mode 100644 index 0000000..28c44cc --- /dev/null +++ b/src/backend/apps/general/migrations/0001_initial.py @@ -0,0 +1,36 @@ +# Generated by Django 5.0.1 on 2024-02-08 22:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + initial = True + + dependencies = [ + migrations.swappable_dependency(), + ] + + operations = [ + migrations.CreateModel( + name="Section", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "title", + models.TextField(max_length=55, verbose_name="Заголовок"), + ), + ( + "description", + models.TextField(max_length=160, verbose_name="Текст"), + ), + ], + ), + ] diff --git a/src/backend/apps/general/migrations/__init__.py b/src/backend/apps/general/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/backend/apps/general/models.py b/src/backend/apps/general/models.py index 84dce68..725695c 100644 --- a/src/backend/apps/general/models.py +++ b/src/backend/apps/general/models.py @@ -9,3 +9,17 @@ class CreatedModifiedFields(models.Model): class Meta: abstract = True + + +class Section(models.Model): + """Секции на главной странице""" + + title = models.TextField( + verbose_name="Заголовок", max_length=55, null=False + ) + description = models.TextField( + verbose_name="Текст", max_length=160, null=False + ) + + def __str__(self): + return self.title diff --git a/src/backend/apps/general/serializers.py b/src/backend/apps/general/serializers.py new file mode 100644 index 0000000..4e1a463 --- /dev/null +++ b/src/backend/apps/general/serializers.py @@ -0,0 +1,9 @@ +from rest_framework import serializers + +from .models import Section + + +class SectionSerializer(serializers.ModelSerializer): + class Meta: + model = Section + fields = "__all__" diff --git a/src/backend/apps/general/views.py b/src/backend/apps/general/views.py new file mode 100644 index 0000000..07c50de --- /dev/null +++ b/src/backend/apps/general/views.py @@ -0,0 +1,9 @@ +from rest_framework import generics + +from .models import Section +from .serializers import SectionSerializer + + +class SectionAPIList(generics.RetrieveAPIView): + queryset = Section.objects.all() + serializer_class = SectionSerializer From 7bca28d4e0af3ea673d251ceb247f273428967db Mon Sep 17 00:00:00 2001 From: Nadya2502 Date: Fri, 9 Feb 2024 15:47:42 +0100 Subject: [PATCH 2/4] =?UTF-8?q?[+]=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=B2=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20general=20=D0=BC=D0=BE=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=20=D0=B4=D0=BB=D1=8F=20=D1=82=D0=B5=D0=BA=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D1=8B=D1=85=20=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=BE=D0=B2=20=D0=B3=D0=BB=D0=B0=D0=B2=D0=BD=D0=BE?= =?UTF-8?q?=D0=B9=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/apps/general/migrations/0001_initial.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/backend/apps/general/migrations/0001_initial.py b/src/backend/apps/general/migrations/0001_initial.py index 28c44cc..c6f9195 100644 --- a/src/backend/apps/general/migrations/0001_initial.py +++ b/src/backend/apps/general/migrations/0001_initial.py @@ -10,6 +10,8 @@ class Migration(migrations.Migration): migrations.swappable_dependency(), ] + + operations = [ migrations.CreateModel( name="Section", From 566c0af73d6452654d152cdae4e1173006050c6e Mon Sep 17 00:00:00 2001 From: Nadya2502 Date: Mon, 12 Feb 2024 15:39:01 +0100 Subject: [PATCH 3/4] =?UTF-8?q?[~]=20=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=D0=B0=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8E=20SectionAPIList=20(=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=D0=B0=20generics.ListAPIView),=20=D1=83?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=BB=D0=B0=20max=5Flength=20=D0=B2=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 6 ++--- src/backend/apps/general/constants.py | 2 ++ ...section_description_alter_section_title.py | 22 +++++++++++++++++++ src/backend/apps/general/models.py | 6 +++-- src/backend/apps/general/views.py | 2 +- 5 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/backend/apps/general/constants.py create mode 100644 src/backend/apps/general/migrations/0002_alter_section_description_alter_section_title.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0bf5a4d..0a2503d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,18 +13,18 @@ repos: - id: check-merge-conflict - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.12.1 + rev: 24.1.1 hooks: - id: black language_version: python3.12.1 exclude: migrations - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort - repo: https://github.com/pre-commit/mirrors-mypy - rev: "" + rev: "v1.8.0" hooks: - id: mypy diff --git a/src/backend/apps/general/constants.py b/src/backend/apps/general/constants.py new file mode 100644 index 0000000..274e629 --- /dev/null +++ b/src/backend/apps/general/constants.py @@ -0,0 +1,2 @@ +TITLE_LENGTH = 100 +DESCRIPRION_LENGTH = 250 diff --git a/src/backend/apps/general/migrations/0002_alter_section_description_alter_section_title.py b/src/backend/apps/general/migrations/0002_alter_section_description_alter_section_title.py new file mode 100644 index 0000000..a894e95 --- /dev/null +++ b/src/backend/apps/general/migrations/0002_alter_section_description_alter_section_title.py @@ -0,0 +1,22 @@ +# Generated by Django 5.0.1 on 2024-02-12 13:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("general", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="section", + name="description", + field=models.TextField(max_length=250, verbose_name="Текст"), + ), + migrations.AlterField( + model_name="section", + name="title", + field=models.TextField(max_length=100, verbose_name="Заголовок"), + ), + ] diff --git a/src/backend/apps/general/models.py b/src/backend/apps/general/models.py index 725695c..c8ae9b0 100644 --- a/src/backend/apps/general/models.py +++ b/src/backend/apps/general/models.py @@ -1,5 +1,7 @@ from django.db import models +from .constants import DESCRIPRION_LENGTH, TITLE_LENGTH + class CreatedModifiedFields(models.Model): """Базовая модель.""" @@ -15,10 +17,10 @@ class Section(models.Model): """Секции на главной странице""" title = models.TextField( - verbose_name="Заголовок", max_length=55, null=False + verbose_name="Заголовок", max_length=TITLE_LENGTH, null=False ) description = models.TextField( - verbose_name="Текст", max_length=160, null=False + verbose_name="Текст", max_length=DESCRIPRION_LENGTH, null=False ) def __str__(self): diff --git a/src/backend/apps/general/views.py b/src/backend/apps/general/views.py index 07c50de..76ea9cb 100644 --- a/src/backend/apps/general/views.py +++ b/src/backend/apps/general/views.py @@ -4,6 +4,6 @@ from .serializers import SectionSerializer -class SectionAPIList(generics.RetrieveAPIView): +class SectionAPIList(generics.RetrieveAPIView, generics.ListAPIView): queryset = Section.objects.all() serializer_class = SectionSerializer From abe173b16ef452b35ad601fc388219d8a8ecbd60 Mon Sep 17 00:00:00 2001 From: Nadya2502 Date: Wed, 14 Feb 2024 13:42:49 +0100 Subject: [PATCH 4/4] fixed mistakes --- src/backend/apps/general/constants.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/backend/apps/general/constants.py b/src/backend/apps/general/constants.py index 06a210d..ac715af 100644 --- a/src/backend/apps/general/constants.py +++ b/src/backend/apps/general/constants.py @@ -1,4 +1,3 @@ - TITLE_LENGTH = 100 DESCRIPRION_LENGTH = 250 MAX_LENGTH_EMAIL = 256 @@ -8,4 +7,3 @@ "@/./+/-/_" ) EMAIL_ERROR_TEXT = "Не корректный email." -