Skip to content

Commit

Permalink
feature: рефакторинг кода связанного с моделью ambassador
Browse files Browse the repository at this point in the history
  • Loading branch information
yan-gabala committed Mar 2, 2024
1 parent 7526cf0 commit 3cfca18
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 78 deletions.
17 changes: 1 addition & 16 deletions crm_yandex/ambassadors/admin.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
from django.contrib import admin

from ambassadors.models import Ambassador, Course, Status, Recipe


@admin.register(Course)
class CourseAdmin(admin.ModelAdmin):
pass


@admin.register(Status)
class StatusAdmin(admin.ModelAdmin):
pass
from ambassadors.models import Ambassador


@admin.register(Ambassador)
class AmbassadorAdmin(admin.ModelAdmin):
pass


@admin.register(Recipe)
class RecipeAdmin(admin.ModelAdmin):
pass
23 changes: 12 additions & 11 deletions crm_yandex/ambassadors/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from core.constants import Limits
from core.constants import (Limits, AMBASSADOR_STATUS_CHOICES,
CLOTHING_SIZE_CHOICES, COURSE_CHOICES,
SEX_CHOICES, SEX_MAX_LEN)
from core.validators import (POSTAL_CODE_VALIDATOR,
PHONE_NUMBER_VALIDATOR,
TELEGRAM_USERNAME_VALIDATOR)
from django.db import models

from ambassadors.validators import (POSTAL_CODE_VALIDATOR,
PHONE_NUMBER_VALIDATOR,
TELEGRAM_USERNAME_VALIDATOR)




class Ambassador(models.Model):
"""
Expand Down Expand Up @@ -46,10 +45,12 @@ class Ambassador(models.Model):
verbose_name="Электронная почта",
)
phone_number = models.CharField(
max_length=Limits.NAME_MAX_LEN.value,
verbose_name="Номер телефона",
validators=(TELEGRAM_USERNAME_VALIDATOR,)
)
nickname_telegram = models.CharField(
max_length=Limits.NAME_MAX_LEN.value,
verbose_name="Ник в телеграм",
validators=(PHONE_NUMBER_VALIDATOR,)
)
Expand Down Expand Up @@ -81,11 +82,12 @@ class Ambassador(models.Model):
max_length=Limits.NAME_MAX_LEN.value,
verbose_name="Размер обуви",
)
about_me = models.CharField( ### последнее поле из ЯФ ###
about_me = models.TextField( ### последнее поле из ЯФ ###
verbose_name="О себе",
)
status = models.CharField( ### далее поля задает КМ ###
choices=Limits.AMBASSADOR_STATUS_CHOICES.value,
max_length=Limits.NAME_MAX_LEN.value,
choices=AMBASSADOR_STATUS_CHOICES,
verbose_name="Статус амбассадора"
)
# status_profile = models.BooleanField
Expand All @@ -94,8 +96,7 @@ class Ambassador(models.Model):
class Meta:
verbose_name = "Амбассадор"
verbose_name_plural = "Амбассадоры"
ordering = ['-date'] # сортировка держит сверху самую свежую анкету из ЯФ

ordering = ['fio'] # поменять на дату заполнения анкеты - сортировка держит сверху самую свежую анкету из ЯФ



Expand Down
16 changes: 1 addition & 15 deletions crm_yandex/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
from rest_framework import serializers

from backend.crm_yandex.ambassadors.models_old import Ambassador, Course, Status


class CourseSerializer(serializers.ModelSerializer):

class Meta:
model = Course
fields = "__all__"


class StatusSerializer(serializers.ModelSerializer):

class Meta:
model = Status
fields = "__all__"
from ambassadors.models import Ambassador


class AmbassadorSerializer(serializers.ModelSerializer):
Expand Down
5 changes: 2 additions & 3 deletions crm_yandex/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
from django.contrib import admin
from django.urls import include, path

from api.views import index, CourseViewSet, StatusViewSet
from api.views import index, AmbassadorViewSet


router = routers.DefaultRouter()
router.register("course", CourseViewSet)
router.register("status", StatusViewSet)
router.register("ambassador", AmbassadorViewSet)

urlpatterns = [
path("index", index),
Expand Down
18 changes: 2 additions & 16 deletions crm_yandex/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,14 @@
from djoser.views import UserViewSet
from rest_framework.viewsets import ModelViewSet

from backend.crm_yandex.ambassadors.models_old import Ambassador, Course, Status
from api.serializers import AmbassadorSerializer, CourseSerializer, StatusSerializer
from ambassadors.models import Ambassador
from api.serializers import AmbassadorSerializer


def index(request):
return HttpResponse("Привет Амбассадорам!")


class CustomUserViewSet(UserViewSet):
pass


class CourseViewSet(ModelViewSet):
queryset = Course.objects.all()
serializer_class = CourseSerializer


class StatusViewSet(ModelViewSet):
queryset = Status.objects.all()
serializer_class = StatusSerializer


class AmbassadorViewSet(ModelViewSet):
queryset = Ambassador.objects.all()
serializer_class = AmbassadorSerializer
94 changes: 77 additions & 17 deletions crm_yandex/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,81 @@ class Limits(IntEnum):
MAX_LEN_EMAIL_FIELD = 256
MAX_LEN_USERS_CHARFIELD = 150
DESIGNATION = 200
STATUS_MAX_LEN: int = 50
NAME_MAX_LEN: int = 100
SIZE_MAX_LEN: int = 10
GOAL_MAX_LEN: int = 255
DECIMAL_MAX_DIGITS: int = 10
DECIMAL_PLACES: int = 2
AMBASSADOR_STATUS_CHOICES = [
('active', 'Активный'),
('paused', 'На паузе'),
('away', 'Ушёл'),
('pending', 'Уточняется'),
]
GUIDE_STATUS_CHOICES = [
('not_completed', 'Не пройден'),
('partially_completed', 'Пройдена 1 часть гайда'),
('completed', 'Полностью пройден'),
STATUS_MAX_LEN = 50
DECIMAL_MAX_DIGITS = 10
DECIMAL_PLACES = 2
NAME_MAX_LEN = 100
SIZE_MAX_LEN = 10
GOAL_MAX_LEN = 255
PHONE_NUM_MAX_LEN = 20
CLOTHING_SIZE_MAX_LEN = 2
PROMOCODE_MAX_LEN = 20
PREFERENCE_MAX_LEN = 255
TELEGRAM_MAX_LEN = 32


AMBASSADOR_STATUS_CHOICES = [
('active', 'Активный'),
('paused', 'На паузе'),
('away', 'Ушёл'),
('pending', 'Уточняется'),
]
GUIDE_STATUS_CHOICES = [
('not_completed', 'Не пройден'),
('partially_completed', 'Пройдена 1 часть гайда'),
('completed', 'Полностью пройден'),
]
AMBASSADOR_STATUS_CHOICES = [
('active', 'Активный'),
('paused', 'На паузе'),
('left', 'Ушёл'),
('pending', 'Уточняется'),
]
GUIDE_STATUS_CHOICES = [
('not_completed', 'Не пройден'),
('partially_completed', 'Пройдена 1 часть гайда'),
('completed', 'Полностью пройден'),
]
SEX_CHOICES = [
('М', 'Мужчина'),
('Ж', 'Женщина')
]
SEX_MAX_LEN: int = 1
COURSE_CHOICES = [
('analyst', 'Аналитик данных'),
('data_scientist', 'Специалист по Data Science'),
('python_dev', 'Python-разработчик'),
('web_dev', 'Веб-разработчик'),
('qa_engineer', 'Инженер по тестированию(QA)'),
('ux_ui_designer', 'UX/UI-дизайнер'),
('marketing', 'Маркетинг'),
('graphic_designer', 'Графический дизайнер'),
('middle_python', 'Middle Python'),
('c_plus_plus', 'C++'),
('data_engineer', 'Инженер данных'),
('it_recruiter', 'IT-рекрутер'),
('management', 'Управление'),
('english', 'Английский'),
('critical_thinking', 'Критическое мышление'),
('business_communication', 'Рабочая коммуникация'),
('developer_algorithms', 'Алгоритмы для разработчиков'),
('product_design', 'Продуктовый дизайн'),
('sql_data_analytics', 'SQL для работы с данными и аналитики'),
('java_dev', 'Java-разработчик'),
('commercial_illustrator', 'Коммерческий иллюстратор'),
('fullstack_dev', 'Фулстек разработчик'),
('advanced_go_dev', 'Продвинутый GO-разработчик'),
('devops', 'DevOps для эксплуатации и разработки'),
('ios_dev', 'IOS-разработчик'),
('business_analyst', 'Бизнес-аналитик'),
('product_manager_exp', 'Продакт-менеджер для специалистов с опытом'),
('android_dev', 'Андроид-разработчик'),
('project_manager', 'Менеджер проектов'),
]

CLOTHING_SIZE_CHOICES = [
('xs', 'XS'),
('s', 'S'),
('m', 'M'),
('l', 'L'),
('xl', 'XL'),
]
File renamed without changes.

0 comments on commit 3cfca18

Please sign in to comment.