pylance fixes

This commit is contained in:
2025-05-30 18:13:52 +03:00
parent f224c41e60
commit 6b4c6cd4d5
5 changed files with 64 additions and 6 deletions

View File

@@ -185,15 +185,25 @@ class ChangeUserMembership(ViewSet):
user = request.user
user_profile = get_object_or_404(UserProfile, user=user)
# преобразуем plan в account_type если нужно
# преобразуем plan в account_type
if 'plan' in request.data and 'account_type' not in request.data:
request.data['account_type'] = request.data['plan']
if 'account_type' not in request.data:
return Response({
"error": "Не указан тарифный план",
"details": "Необходимо указать plan или account_type"
}, status=status.HTTP_400_BAD_REQUEST)
serializer = PlanChangeSerializer(user_profile, data=request.data)
if serializer.is_valid():
# получаем объект тарифного плана
new_plan = get_object_or_404(Pricing, plan=serializer.validated_data['account_type'])
try:
if not serializer.is_valid():
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
account_type = request.data['account_type']
# получаем тарифный план
new_plan = get_object_or_404(Pricing, plan=account_type)
# создаем транзакцию
transaction = Transactions.objects.create(
@@ -208,8 +218,14 @@ class ChangeUserMembership(ViewSet):
serializer.save()
return Response({
"message": "Тариф успешно изменен",
"account_type": serializer.validated_data['account_type']
"account_type": new_plan.plan
}, status=status.HTTP_200_OK)
except Exception as e:
return Response({
"error": "Ошибка при изменении тарифного плана",
"details": str(e)
}, status=status.HTTP_400_BAD_REQUEST)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)