From 3387f831535d2f6c0a8b85cc8798cdcdbc9967dd Mon Sep 17 00:00:00 2001 From: Konstantin Raikhert <69113745+KonstantinRaikhert@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:09:49 +0300 Subject: [PATCH] Dev (#575) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * Create/endpoint game (#442) * create endpoint_game * create endpoint_game * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * test cd * fix: remove games button for team agents (#445) * Bugfix/game creation form fixes (#441) * feat: add basic admin pages for new models * refactor: remove wrong constraint * bugfix: fix edit game form, now working but not completely * bugfix: fix edit game form, now working properly * perf: add more precise team filtering --------- Co-authored-by: Konstantin Raikhert * test cd * Add docker scripts in Makefile and add ds_server in gitignore (#447) * Add docker scripts in Makefile and add ds_server in gitignore * Add new make commands in help * Update README.md * Решен баг с заполением БД реальными данными (#451) * fix player_video_games views (#452) Co-authored-by: zaritskiyaa * fix stage * Feature/models id sync (#454) * refactor: merge migrations and create fresh initial * feat: create new PK field for models, sync objects' ids * fix: fix docstring error * change ER diagram --------- Co-authored-by: Konstantin Raikhert * Bugfix/template fixes (#458) * fix: remove unload for unloads * fix: fix player's teams display * Fix search display, implement searching games and add icons for edit/delete games (#461) * Fix search display, implement seatching games and add icons for edit/delete games * delete print --------- Co-authored-by: Konstantin Raikhert * fix: fix game creation via admin panel, also add basic form validation (#460) Co-authored-by: Konstantin Raikhert * Edit players_number (#453) * Edit players_number * Edit players_number * Ruff fix * Fix ruff v2 * Ruff fix v3 * Fix templates * delete unsupport file * ruff check --------- Co-authored-by: Konstantin Raikhert * Create/video recognition (#455) * Save changes in poetry.lock * code according to PEP8 * create endpoint video_recognition * fix video api * code according to PEP8 * code according to PEP8 * code according to PEP8 * code according to PEP8 * code according to PEP8 --------- Co-authored-by: Konstantin Raikhert * refactoring video_api views and swagger doc (#464) * refactoring video_api views and swagger doc * expand service/a_hockey_requests.py/send_request_to_video_processing_service. Assigned try name for env param * fix env * fix bug with init environ object --------- Co-authored-by: zaritskiyaa * add requirement * fix name mistake in env param (#465) Co-authored-by: zaritskiyaa * Bugfix/player number edit form (#470) * fix: fix template for player number edit, also fix errors display * fix: add view name * Feature/factories and bugfix in player (#472) * fix player * add factory game * rebild factory * fix factory gamecreate * fix factory gamecreate * fix ruff * fix warning timedata --------- Co-authored-by: Максим Портнов Co-authored-by: Алексей Сосов~ * fix game_team query (#477) Co-authored-by: zaritskiyaa * Add GameDataPlayer model for storing game JSON data (#481) * Add GameDataPlayer model for storing game JSON data * add jpg in ER docs --------- Co-authored-by: Konstantin Raikhert * connect celery with redis back/broker. create mock tasks (#484) Co-authored-by: zaritskiyaa Co-authored-by: Konstantin Raikhert * Add JSON player data factory (#483) * add mock functional for processing video (#486) * add mock functional for processing video * fix readme --------- Co-authored-by: zaritskiyaa * Bugfix/fix analytic table in uploads (#493) * fix_analytic_table_in_uploads * fix_analytics_table_uploads --------- Co-authored-by: Tom Bulmer * rework GameDataPlayer model, refactoring mock celery tasks/serializer (#489) Co-authored-by: zaritskiyaa * Add celery instruction * add celery instruction * fix migrations conflict * Add feature dynamic video button in player_views and templates player_id and video_games_button. And fixed the filter in the PlayerGamesVideo view by id instead of pk (#496) * Feature/readme fix (#500) * fix .gitignore and README * mv pytest.ini in root folder * Revert .python-version change * Bugfix/template fix game detail (#499) * Fix button game_detail button visual bug * Add .python-version into gitignore * move into the right center * Added the feature of an additional column name of the competition on the games page. Added data to the context in the view of the GamesListView (#497) * add make command for kson factory (#498) * test_status_service (#501) Co-authored-by: Tom Bulmer * Added diagram video workers in docs. (#508) Deleted commands for DS server from Makefile (image_video, start_video). Deleted obsoleted units about parsing files and API DS from README.md. * Update the game player model - update a player number unique constraint (#505) (#510) * Update game player number unique constraint (#505) * Fix code-style ruff issues * Fix code-style ruff issues (#505) * Update unique game player number constraint fields; update fields in create game player signal (#505) * Refactor requests to DS API, add YandexDist token to settings and .env.example (#511) * Tests remarks (#514) * Add show message for unload_player_game_video (#509) (#512) * feat: Add show message for unload_player_game_video. fix: Change ' to " in base_settings.py. * fix: Revert " to ' in base_settings.py. * fix: Add game name to message. * Add validation to check unique player number field in player update form, edit players numbers in game form. (#517) * Feature/download player video (#520) (#521) * feat: Add download player video if video link exists. feat: Add yadisk in poetry. * fix: Refactor code. * fix: Move player video dir to constants. fix: Change path video dir to path video file. * fix: Add type hinting. fix: Refactor code. * fix: Change varialble name from error to error_message. * add TODO --------- Co-authored-by: Konstantin Raikhert * Bugfix/visible form adding player in team (#518) (#523) * fix: Correct misprints in template. fix: Fix visible form for adding teams. fix: Save added or updated player's teams. * fix: Change PlayerForm for visible team form. * fix: Move mixin in mixins.py and ajax view in ajax.py. * Bugfix/change footer buttons color (#525) (#526) * fix: Add return button to pages: staff_id_team_edit, staff_id_team_create, edit_team_players_numbers, game_edit. * fix: Change pagination border to border-2. fix: Correct position of footer buttons. * fix: Change color of footer buttons. * Integrate Celery worker and flower run into Make run (Issue #515) (#527) * Integrate Celery worker and flower run into Make run * add celery connction in config django --------- Co-authored-by: Konstantin Raikhert * Feature/django message in game card (#519) (#522) * Add django messages to game detail page. * Add django messages to game detail page. * Fix issue #507 - fix stage (#530) * Fix issue #507 - fix dependencies * Fix issue #507 - optimze dependencies fix * Fix stage deployment error (#535) * Add celery tasks to download videos from Y.disk, to slice video with player moments. (#532) * Feature/Add DS mock server (#533) * feat: Add fastapi[standard] in development requirements. * feat: Add FastAPI ds mock server. * feat: Add ds-mock command to Makefile. * fix: Delete queues from Celery. * fix: Change directory service to Django app. * feat: Add DS mock server. * fix: Delete redundant logging. * fix: Add logging to a_hockey_requests. fix: Change raise error to message. * fix: Delete redundant files. * fix: Change print to logging. fix: Correct import sort. * fix: Correct docstring in apps.py. * fix: Update README.md. * fix: Add file with test response json. * add some TODO * fix: Move mock_ds_server in separate directory. * fix: Update Makefile. * feat: Add mock_ds_server in Celery autodiscovery tasks. * fix: Add logging and return error messages in send_game_video_to_process. * fix: Add logging and change exception catch in send_request_to_process_video. * fix: Move mock_ds_server in separate directory. * fix: Change GameFeatureSerializer to structure of DS answer. * fix: Add logging and small refactoring. * fix: Add type hints in GameFeatureSerializer. * fix: Update Makefile * feat: Return Celery queues * fix: Correct task arguments * fix: Change response of mock DS server Small refactor code. * fix: Change logging level * fix: Change bulk_create_gamedataplayer_objects To structure response mock DS server * Revert "Merge branch 'dev' into feature/ds-mock-server" This reverts commit 879a5adc1117028ff1f7c4be7ec9670b6c245d63, reversing changes made to 2cd61257097a9b50b12b4784a805fa9458c11ad3. * fix: Delete unnecessary code. * fix: Add try..catch exceptions. * fix: Change game name to game id. * fix: Old data of players rewrite, if exist. * feat: Unlink mock DS server from the Django server. * fix: Revert RequestException. * feat: Add TODO for send mail. * fix: Delete unused import. * feat: Add send mail of end video process. --------- Co-authored-by: Konstantin Raikhert * fix bug (#538) Co-authored-by: Khasanov Alexander * Bugfix/random teams in created game (#539) * fix: Close div and change h7 to h6. * feat: Add back button to game_info page. * fix: Correct adding team to GameTeam. Delete mock-code for request to DS server. * fix: Refactor view-function send_game_video_to_process. * fix: Change url to send_game_video_to_process_view. * fix: Delete unusale import. * add spec of analytics in docs * add spec of analytics in docs * Feature/removing celery (#545) * game views in process * remove celery of game views * remove celery of player_views * remove celery * fix core.config.base * fix players-view * fix README * test prod workflow * fix /infra/prod/ * fix docker compose prod * test prod.dockerfile * test prod.dockerfile2 * test prod.dockerfile3 * test prod.dockerfile4 * test prod.dockerfile5 * test prod.dockerfile6 * test deploy to production * test deploy to production2 * test deploy to production3 * test deploy to production4 * test deploy to production6 * Relocated openpyxl config file to configs folder (#549) * Add commands export-db and import-db. (#548) * test deploy to production7 * test deploy to production8 * test deploy to production9 * test deploy to production10 * test deploy to production10 * test deploy to production11 * test deploy to production12 * test deploy to production13 * test deploy to production14 * test deploy to production15 * test deploy to production16 * test deploy to production17 * test deploy to production18 * test deploy to production19 * test deploy to production20 * test deploy to production21 * test deploy to production22 * test deploy to production23 * test deploy to production24 * test deploy to production25 * test deploy to production26 * test deploy to production27 * test secrets * test secrets1 * test secrets2 * test secrets3 * test secrets4 * test secrets5 * test secrets6 * test secrets7 * test copy infra to vps * test copy infra to vps - 1 * test copy infra to vps - 2 * test copy infra to vps - 3 * test copy infra to vps - 4 * test copy infra to vps - 5 * test copy infra to vps - 6 * test copy infra to vps - 7 * test copy infra to vps - 8 * test copy infra to vps - 9 * test copy infra to vps - 10 * test copy infra to vps - 11 * test copy infra to vps - 12 * Removed the video_api module and everything related to it * test deploy * test deploy1 * test deploy2 * test deploy3 * test deploy4 * test deploy5 * test deploy6 * test deploy7 * test deploy8 * test deploy8 * test deploy9 * test deploy10 * test deploy11 * test deploy12 * test deploy13 * test deploy14 * test deploy15 * test deploy16 * test deploy17 * test deploy18 * test deploy19 * test deploy20 * test deploy21 * pre-realease * pre-realease1 * pre-realease2 * pre-realease3 * pre-realease4 * pre-realease5 * pre-realease6 * pre-realease7 * pre-realease8 * pre-realease9 * pre-realease10 * pre-realease11 * on review * test build * test build1 * test build2 * test build3 * test watchtower * test watchtower1 * on review3 * on review4 * test build * test build1 * on review 4 * test build-1 * test build-2 * test build 5 * test build 6 * test build 6 * test build 7 * test build 8 * test build 8 * test build 9 * test build 10 * test build 11 * test build 12 * test build 14 * on_review * on_review final * on_review final * on_review final1 * Remove parser and rewrite command fill-db (#554) * fix by review * Feature/modify import commands (#564) * update import import-db.py, export-db.py, docker-compose.prod.yaml * fix deploy * on review * games button removed; game signals disabled (#555) * games button removed; game signals disabled * games signals and button deleted * returned the signals file so that there would be no conflict during the merge * fix ruff --------- Co-authored-by: Konstantin Raikhert * Remove games app. Rewrite ER Diagram. (#566) Co-authored-by: Konstantin Raikhert * Bugfix/fix the player bday validator (#571) * games button removed; game signals disabled * games signals and button deleted * fix age limits --------- Co-authored-by: webn1nja * Fix team assignment bug where other players were removed from the team when assigned (#569) Co-authored-by: Konstantin Raikhert * Bugfix/diagnosis register validator (#570) * add validator registr * on review --------- Co-authored-by: zaritskiyaa Co-authored-by: Rodion a vrode ne on <132199131+SHURSHALO@users.noreply.github.com> Co-authored-by: Nikita Smykov <132088678+Apicqq@users.noreply.github.com> Co-authored-by: Игорь Митяшин <132353894+ItsFreez@users.noreply.github.com> Co-authored-by: Salikov Nikita Co-authored-by: zaritskiiAA <166800734+zaritskiiAA@users.noreply.github.com> Co-authored-by: Milkyaway13 <129880524+Milkyaway13@users.noreply.github.com> Co-authored-by: Maxim Portnov <124585181+DoomHunter190@users.noreply.github.com> Co-authored-by: Максим Портнов Co-authored-by: Алексей Сосов~ Co-authored-by: posredn1k <114393753+posredn1k@users.noreply.github.com> Co-authored-by: trippiez <116493293+trippiez@users.noreply.github.com> Co-authored-by: Tom Bulmer Co-authored-by: PavelNep1996 <118282648+PavelNep1996@users.noreply.github.com> Co-authored-by: Borovkov Ilya <48968499+ffff00-korj@users.noreply.github.com> Co-authored-by: AleksandrPU Co-authored-by: ramil-khan <116222162+ramil-khan@users.noreply.github.com> Co-authored-by: RuselK <123992635+RuselK@users.noreply.github.com> Co-authored-by: AlexanderKhasanov Co-authored-by: Khasanov Alexander Co-authored-by: OlegGsk <142893688+OlegGsk@users.noreply.github.com> Co-authored-by: Олег Говоровский Co-authored-by: Konstantin Shperling (Toksi) <79082640+Toksi86@users.noreply.github.com> Co-authored-by: Иван <128288828+InKLaR1TY@users.noreply.github.com> Co-authored-by: Toksi86 Co-authored-by: Konstantin Co-authored-by: webn1nja --- .github/workflows/prod_deploy.yaml | 1 - adaptive_hockey_federation/core/constants.py | 390 +++++++++--------- adaptive_hockey_federation/main/forms.py | 9 +- adaptive_hockey_federation/main/validators.py | 14 + infra/prod/adaptive_hockey_federation.service | 6 +- 5 files changed, 216 insertions(+), 204 deletions(-) create mode 100644 adaptive_hockey_federation/main/validators.py diff --git a/.github/workflows/prod_deploy.yaml b/.github/workflows/prod_deploy.yaml index 21a315bd..406b5189 100644 --- a/.github/workflows/prod_deploy.yaml +++ b/.github/workflows/prod_deploy.yaml @@ -127,7 +127,6 @@ jobs: echo "${{ secrets.ENV_FILE }}" > .env cd infra/prod/ - sudo systemctl stop adaptive_hockey_federation.service docker system prune --force sudo cp -f /home/production/adaptive_hockey_federation/infra/prod/adaptive_hockey_federation.service /etc/systemd/system/adaptive_hockey_federation.service diff --git a/adaptive_hockey_federation/core/constants.py b/adaptive_hockey_federation/core/constants.py index 3e43e633..edc76084 100644 --- a/adaptive_hockey_federation/core/constants.py +++ b/adaptive_hockey_federation/core/constants.py @@ -1,195 +1,195 @@ -from dataclasses import dataclass -from enum import IntEnum, StrEnum - - -class UserConstans(IntEnum): - """Константы для приложения users.""" - - NAME_MAX_LENGTH = 256 - EMAIL_MAX_LENGTH = 256 - QUERY_SET_LENGTH = 15 - - -class Role(StrEnum): - """Роли пользователей.""" - - AGENT = "Представитель команды" - MODERATOR = "Модератор" - ADMIN = "Администратор" - SUPERUSER = "Администратор" - - -ROLES_CHOICES = ( - (Role.AGENT, "Представитель команды"), - (Role.MODERATOR, "Модератор"), - (Role.ADMIN, "Администратор"), -) - - -class Group(StrEnum): - """Группы ролей пользоватлей.""" - - ADMINS = "Администраторы" - MODERATORS = "Модераторы" - AGENTS = "Представители команд" - - -GROUPS_BY_ROLE = { - Role.ADMIN: Group.ADMINS, - Role.AGENT: Group.AGENTS, - Role.MODERATOR: Group.MODERATORS, - Role.SUPERUSER: Group.ADMINS, -} - - -class Discipline(StrEnum): - """Виды дисциплин в хоккее.""" - - SLEDGE_HOCKEY = "Следж-хоккей" - BLIND_HOCKEY = "Хоккей для незрячих" - SPECIAL_HOCKEY = "Специальный хоккей" - ROLLER_HOCKEY = "Роликовый следж-хоккей" - - -DISCIPLINE_LEVELS = { - Discipline.SLEDGE_HOCKEY: (1, 2, 3, 4, 5, 6), - Discipline.ROLLER_HOCKEY: (1, 2, 3, 4, 5, 6), - Discipline.BLIND_HOCKEY: ("B1", "B2", "B3", "B4", "B5", "б/к"), - Discipline.SPECIAL_HOCKEY: ("A", "B", "C"), -} - - -class MainConstantsInt(IntEnum): - """Константы int для main/models.py.""" - - CHAR_FIELD_LENGTH = 256 - CLASS_FIELD_LENGTH = 10 - DEFAULT_VALUE = 0 - - -class MainConstantsStr(StrEnum): - """Константы str для main/models.py.""" - - EMPTY_VALUE_DISPLAY = "" - - -class Gender(StrEnum): - """Пол.""" - - MAN = "Мужской" - WOMAN = "Женский" - - -GENDER_CHOICES = ( - (Gender.MAN.value, "Мужской"), - (Gender.WOMAN.value, "Женский"), -) - - -class PlayerPosition(StrEnum): - """Позиции игроков.""" - - STRIKER = "Нападающий" - BOBBER = "Поплавок" - GOALKEEPER = "Вратарь" - DEFENDER = "Защитник" - - -PLAYER_POSITION_CHOICES = ( - (PlayerPosition.STRIKER.value, "Нападающий"), - (PlayerPosition.BOBBER.value, "Поплавок"), - (PlayerPosition.GOALKEEPER.value, "Вратарь"), - (PlayerPosition.DEFENDER.value, "Защитник"), -) - - -class StaffPosition(StrEnum): - """Роли представителей команд.""" - - TRAINER = "тренер" - OTHER = "пушер-тьютор" - - -STAFF_POSITION_CHOICES = ( - (StaffPosition.TRAINER.value, "тренер"), - (StaffPosition.OTHER.value, "пушер-тьютор"), -) - - -class TimeFormat: - """Форматы времени.""" - - TIME_FORMAT = "%H-%M-%S" - - -class AgeLimits(IntEnum): - """Возростные лимиты.""" - - MIN_AGE_PLAYER = 6 - MAX_AGE_PLAYER = 18 - - -FORM_HELP_TEXTS = { - "identity_document": ( - "Введите данные в формате 'Паспорт ХХХХ ХХХХХХ' или " - "'Свидетельство о рождении X-XX XXXXXX'" - ), - "birthday": ( - f"Возраст должен быть от {AgeLimits.MIN_AGE_PLAYER}" - f"до {AgeLimits.MAX_AGE_PLAYER} лет" - ), - "available_teams": ("Список доступных команд перемещение двойным щелчком"), - "email": ( - "Введите актуальную электронную почту в формате example@domen.ru" - ), - "role": ("Выберите роль которая соответствует пользователю"), - "player_teams": ( - "Список команд в которых состоит игрок удаление двойным щелчком" - ), - "staff_teams": ( - "Список команд в которых состоит сотрудник удаление двойным щелчком" - ), - "available_disciplines": ( - "Список доступных дисциплин перемещение двойным щелчком" - ), - "disciplines": "Список дисциплин в соревновании", -} - - -@dataclass -class FileConstants: - """Константы для файлов.""" - - FILE_RESOLUTION = ("png", "jpeg", "jpg", "pdf") - MAX_UPLOAD_SIZE: int = 10485760 - MAX_UPLOAD_SIZE_MB: str = str(int(MAX_UPLOAD_SIZE / (1024 * 1024))) + " MB" - - -SEARCH_ALIAS = { - "surname": "surname", - "name": "name", - "birthday": "birthday", - "gender": "gender", - "number": "surname", - "discipline": "discipline__discipline_name_id__name", - "diagnosis": "diagnosis__name", - "city": "city_name", -} - - -class Directory: - """Директории.""" - - GAMES = "games" - PLAYER_VIDEO_DIR = "player_video" - UNLOAD_DIR = "unloads_data" - - -class YadiskDirectory(StrEnum): - """Директории на Яндекс.Диске.""" - - GAMES = "games" - PLAYER_GAMES = "player_games" - - -PLAYER_GAME_NAME = "{surname}_{name[0]}_{patronymic[0]}_{game_name}.mp4" +from dataclasses import dataclass +from enum import IntEnum, StrEnum + + +class UserConstans(IntEnum): + """Константы для приложения users.""" + + NAME_MAX_LENGTH = 256 + EMAIL_MAX_LENGTH = 256 + QUERY_SET_LENGTH = 15 + + +class Role(StrEnum): + """Роли пользователей.""" + + AGENT = "Представитель команды" + MODERATOR = "Модератор" + ADMIN = "Администратор" + SUPERUSER = "Администратор" + + +ROLES_CHOICES = ( + (Role.AGENT, "Представитель команды"), + (Role.MODERATOR, "Модератор"), + (Role.ADMIN, "Администратор"), +) + + +class Group(StrEnum): + """Группы ролей пользоватлей.""" + + ADMINS = "Администраторы" + MODERATORS = "Модераторы" + AGENTS = "Представители команд" + + +GROUPS_BY_ROLE = { + Role.ADMIN: Group.ADMINS, + Role.AGENT: Group.AGENTS, + Role.MODERATOR: Group.MODERATORS, + Role.SUPERUSER: Group.ADMINS, +} + + +class Discipline(StrEnum): + """Виды дисциплин в хоккее.""" + + SLEDGE_HOCKEY = "Следж-хоккей" + BLIND_HOCKEY = "Хоккей для незрячих" + SPECIAL_HOCKEY = "Специальный хоккей" + ROLLER_HOCKEY = "Роликовый следж-хоккей" + + +DISCIPLINE_LEVELS = { + Discipline.SLEDGE_HOCKEY: (1, 2, 3, 4, 5, 6), + Discipline.ROLLER_HOCKEY: (1, 2, 3, 4, 5, 6), + Discipline.BLIND_HOCKEY: ("B1", "B2", "B3", "B4", "B5", "б/к"), + Discipline.SPECIAL_HOCKEY: ("A", "B", "C"), +} + + +class MainConstantsInt(IntEnum): + """Константы int для main/models.py.""" + + CHAR_FIELD_LENGTH = 256 + CLASS_FIELD_LENGTH = 10 + DEFAULT_VALUE = 0 + + +class MainConstantsStr(StrEnum): + """Константы str для main/models.py.""" + + EMPTY_VALUE_DISPLAY = "" + + +class Gender(StrEnum): + """Пол.""" + + MAN = "Мужской" + WOMAN = "Женский" + + +GENDER_CHOICES = ( + (Gender.MAN.value, "Мужской"), + (Gender.WOMAN.value, "Женский"), +) + + +class PlayerPosition(StrEnum): + """Позиции игроков.""" + + STRIKER = "Нападающий" + BOBBER = "Поплавок" + GOALKEEPER = "Вратарь" + DEFENDER = "Защитник" + + +PLAYER_POSITION_CHOICES = ( + (PlayerPosition.STRIKER.value, "Нападающий"), + (PlayerPosition.BOBBER.value, "Поплавок"), + (PlayerPosition.GOALKEEPER.value, "Вратарь"), + (PlayerPosition.DEFENDER.value, "Защитник"), +) + + +class StaffPosition(StrEnum): + """Роли представителей команд.""" + + TRAINER = "тренер" + OTHER = "пушер-тьютор" + + +STAFF_POSITION_CHOICES = ( + (StaffPosition.TRAINER.value, "тренер"), + (StaffPosition.OTHER.value, "пушер-тьютор"), +) + + +class TimeFormat: + """Форматы времени.""" + + TIME_FORMAT = "%H-%M-%S" + + +class AgeLimits(IntEnum): + """Возростные лимиты.""" + + MIN_AGE_PLAYER = 6 + MAX_AGE_PLAYER = 25 + + +FORM_HELP_TEXTS = { + "identity_document": ( + "Введите данные в формате 'Паспорт ХХХХ ХХХХХХ' или " + "'Свидетельство о рождении X-XX XXXXXX'" + ), + "birthday": ( + f"Возраст должен быть от {AgeLimits.MIN_AGE_PLAYER}" + f"до {AgeLimits.MAX_AGE_PLAYER} лет" + ), + "available_teams": ("Список доступных команд перемещение двойным щелчком"), + "email": ( + "Введите актуальную электронную почту в формате example@domen.ru" + ), + "role": ("Выберите роль которая соответствует пользователю"), + "player_teams": ( + "Список команд в которых состоит игрок удаление двойным щелчком" + ), + "staff_teams": ( + "Список команд в которых состоит сотрудник удаление двойным щелчком" + ), + "available_disciplines": ( + "Список доступных дисциплин перемещение двойным щелчком" + ), + "disciplines": "Список дисциплин в соревновании", +} + + +@dataclass +class FileConstants: + """Константы для файлов.""" + + FILE_RESOLUTION = ("png", "jpeg", "jpg", "pdf") + MAX_UPLOAD_SIZE: int = 10485760 + MAX_UPLOAD_SIZE_MB: str = str(int(MAX_UPLOAD_SIZE / (1024 * 1024))) + " MB" + + +SEARCH_ALIAS = { + "surname": "surname", + "name": "name", + "birthday": "birthday", + "gender": "gender", + "number": "surname", + "discipline": "discipline__discipline_name_id__name", + "diagnosis": "diagnosis__name", + "city": "city_name", +} + + +class Directory: + """Директории.""" + + GAMES = "games" + PLAYER_VIDEO_DIR = "player_video" + UNLOAD_DIR = "unloads_data" + + +class YadiskDirectory(StrEnum): + """Директории на Яндекс.Диске.""" + + GAMES = "games" + PLAYER_GAMES = "player_games" + + +PLAYER_GAME_NAME = "{surname}_{name[0]}_{patronymic[0]}_{game_name}.mp4" diff --git a/adaptive_hockey_federation/main/forms.py b/adaptive_hockey_federation/main/forms.py index f4baeedb..0fb2d6f3 100644 --- a/adaptive_hockey_federation/main/forms.py +++ b/adaptive_hockey_federation/main/forms.py @@ -28,6 +28,7 @@ StaffTeamMember, Team, ) +from main.validators import validate_registr_diagnosis from users.models import User @@ -142,7 +143,10 @@ def clean_identity_document(self): def clean_diagnosis(self): """Метод, выполняющий валидацию поля с диагнозом.""" nosology = self.cleaned_data.get("nosology") - diagnosis = self.cleaned_data.get("diagnosis") + diagnosis = validate_registr_diagnosis( + self.cleaned_data.get("diagnosis"), + ) + if Diagnosis.objects.filter(name=diagnosis).exists(): diagnos = Diagnosis.objects.get(name=diagnosis) if diagnos.nosology != nosology: @@ -205,9 +209,6 @@ def save(self, commit=True): instance = super().save(commit=False) if commit: instance.save() - instance.team.through.objects.filter( - team__in=self.cleaned_data["team"], - ).delete() instance.team.set(self.cleaned_data["team"]) return instance diff --git a/adaptive_hockey_federation/main/validators.py b/adaptive_hockey_federation/main/validators.py new file mode 100644 index 00000000..309d6967 --- /dev/null +++ b/adaptive_hockey_federation/main/validators.py @@ -0,0 +1,14 @@ +import re + + +def validate_registr_diagnosis(diagnosis: str) -> str: + """ + Метод, проверяющий диагноз на соответствие коду МКБ-10. + + Если нет, то возвращает диагноз в нижней регистре с заглавной буквы. + """ + pattern = r"^([A-Z]\d{2})(.\d)?$" + + if not re.match(pattern, diagnosis): + return diagnosis.capitalize() + return diagnosis diff --git a/infra/prod/adaptive_hockey_federation.service b/infra/prod/adaptive_hockey_federation.service index 3c5193ff..a54b0ab5 100644 --- a/infra/prod/adaptive_hockey_federation.service +++ b/infra/prod/adaptive_hockey_federation.service @@ -8,14 +8,12 @@ After=docker.service Restart=always RestartSec=5 -TimeOutStartSec=1200 +TimeoutStartSec=1200 User=production WorkingDirectory=/home/production/adaptive_hockey_federation/infra/prod/ ExecStartPre=docker compose -f docker-compose.prod.yaml --env-file /home/production/adaptive_hockey_federation/.env pull -ExecStartPre=docker compose -f docker-compose.prod.yaml --env-file /home/production/adaptive_hockey_federation/.env down - # compose up ExecStart=docker compose -f docker-compose.prod.yaml --env-file /home/production/adaptive_hockey_federation/.env up @@ -28,4 +26,4 @@ ExecStartPost=sleep 5 [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target