From 8fd9dcbb95f6211d5d303d54be9bf758d65ea123 Mon Sep 17 00:00:00 2001 From: NECROshizo Date: Sat, 6 Apr 2024 18:23:00 +0300 Subject: [PATCH] fix 100 trening update close #175 --- backend/api/v1/views.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/backend/api/v1/views.py b/backend/api/v1/views.py index 100986b..04601a4 100644 --- a/backend/api/v1/views.py +++ b/backend/api/v1/views.py @@ -254,12 +254,15 @@ def _update_user_timezone_data(self, user: ClassUser, user_timezone: str) -> Non def post(self, request: Request, *args, **kwargs) -> Response: user_timezone = request.data.get("timezone") - user = request.user + if not user_timezone: return Response({"timezone": "Часовой пояс пользователя обязателен."}, status=status.HTTP_400_BAD_REQUEST) - response = Response({"updated": True}, status=status.HTTP_200_OK) - if not user.last_completed_training: + + user = request.user + last_traning = user.last_completed_training + + if not last_traning: self._update_user_timezone_data(user, user_timezone) return response @@ -272,8 +275,9 @@ def post(self, request: Request, *args, **kwargs) -> Response: return response user.timezone = user_timezone - if amount_of_skips >= days_missed: - self._updates_skip_data(user, amount_of_skips, days_missed, date_day_ago) - else: - self._clearing_user_training_data(user) + if last_traning.training_day.day_number < 100: + if amount_of_skips >= days_missed: + self._updates_skip_data(user, amount_of_skips, days_missed, date_day_ago) + else: + self._clearing_user_training_data(user) return response