From bc36db57e11aa5c4b82340d829ea0abce4bc3b69 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Sun, 29 Jun 2025 21:30:17 +0300 Subject: [PATCH] Features: 1) Add type annotations to methods in payments serializers for enhanced type safety; Fixes: 1) Correct unnecessary use of `Collection` type hint in core and simple serializers; 2) Fix translation of "blacklisted tokens" in Russian localization; Extra: 1) Simplify conditional logic in `get_children` methods across serializers; 2) Remove unused imports and improve code readability. --- core/serializers/detail.py | 13 ++----------- core/serializers/simple.py | 12 ++---------- payments/serializers.py | 6 +++--- vibes_auth/locale/ru_RU/LC_MESSAGES/django.mo | Bin 10519 -> 10498 bytes vibes_auth/locale/ru_RU/LC_MESSAGES/django.po | 2 +- 5 files changed, 8 insertions(+), 25 deletions(-) diff --git a/core/serializers/detail.py b/core/serializers/detail.py index 1869140b..217a29fa 100644 --- a/core/serializers/detail.py +++ b/core/serializers/detail.py @@ -1,7 +1,5 @@ import logging -from collections.abc import Collection from contextlib import suppress -from typing import Any from django.contrib.auth.models import AnonymousUser from django.core.cache import cache @@ -115,21 +113,14 @@ class CategoryDetailSerializer(ModelSerializer): return filterable_results - def get_children(self, obj) -> Collection[Any]: + def get_children(self, obj) -> list: request = self.context.get("request") if request is not None and request.user.has_perm("view_category"): children = obj.children.all() else: children = obj.children.filter(is_active=True) - if obj.children.exists(): - return ( - CategoryDetailSerializer(children, many=True, context=self.context).data - if obj.children.exists() - else [] - ) - else: - return [] + return CategoryDetailSerializer(children, many=True, context=self.context).data if obj.children.exists() else [] class BrandDetailSerializer(ModelSerializer): diff --git a/core/serializers/simple.py b/core/serializers/simple.py index f05e1a75..6f9e01ce 100644 --- a/core/serializers/simple.py +++ b/core/serializers/simple.py @@ -1,4 +1,3 @@ -from collections.abc import Collection from contextlib import suppress from rest_framework.fields import JSONField, SerializerMethodField @@ -59,21 +58,14 @@ class CategorySimpleSerializer(ModelSerializer): return obj.image.url return None - def get_children(self, obj) -> Collection: + def get_children(self, obj) -> list: request = self.context.get("request") if request is not None and request.user.has_perm("view_category"): children = obj.children.all() else: children = obj.children.filter(is_active=True) - if obj.children.exists(): - return ( - CategorySimpleSerializer(children, many=True, context=self.context).data - if obj.children.exists() - else [] - ) - else: - return [] + return CategorySimpleSerializer(children, many=True, context=self.context).data if obj.children.exists() else [] class BrandSimpleSerializer(ModelSerializer): diff --git a/payments/serializers.py b/payments/serializers.py index 47f953a0..c3191e8f 100644 --- a/payments/serializers.py +++ b/payments/serializers.py @@ -19,11 +19,11 @@ class TransactionProcessSerializer(ModelSerializer): order_hr_id = SerializerMethodField(read_only=True, required=False) order_uuid = SerializerMethodField(read_only=True, required=False) - def get_order_hr_id(self, obj: Transaction): + def get_order_hr_id(self, obj: Transaction) -> str | None: return obj.order.human_readable_id if obj.order else None # type: ignore - def get_order_uuid(self, obj: Transaction): - return obj.order.uuid if obj.order else None # type: ignore + def get_order_uuid(self, obj: Transaction) -> str | None: + return str(obj.order.uuid) if obj.order else None # type: ignore class Meta: model = Transaction diff --git a/vibes_auth/locale/ru_RU/LC_MESSAGES/django.mo b/vibes_auth/locale/ru_RU/LC_MESSAGES/django.mo index fb02b9577ddb4bb0feb470b905f66f68dfc1901c..be0f617f2e0ef0b7654c42bfe05332f4601452ac 100644 GIT binary patch delta 599 zcmXZZOG`pQ6u|KVQUpbsC0JSaR$5t+&}$(PVh`w{kP8V?sQd^)+lv-K(5CG15yD+1 z2AP$$Y}0ii)TUiTiOUw9_cwF6GjqS4_5g5S~s*dE) zjc?e37QM2;iK+rW4qz0cn8ZbV!DDoDIyp%mr&S!i=;{`E!Z}o(YBG8%t^PoUSh;l{ zM^PnGMD-+}xQ04y@M98r9Vwtnyo|G0*IOwlj8m+)aS|Ufj(@23#d%+96Ymz243iU7 wl?AwU31jHP45~z4v)46;cFS4mAgy^ER=t!m@65cJGjH)Sy{?UC3(i&BKQ=y5>Hq)$ delta 640 zcmXZZ&nrYx6u|Klu@KT2HN!A(7{h1~8HJ(AkCLA?#VkakY-BMu>;?%nR(`K6>|`UF zGHQmE1q=6;;UBP4Z0scYUZZaBbI*D2-gnNuYoWu?`CfLkQ$z-ABEz_at@w;JSYQ`% zp&xTGjQKeA?>vTxm$3mKFpXchfvQxb1jA(_*SLTTsdb20u-73`Dbyd3D8e}$!6nrB zyMNPIP5g?zm{%^cj-wdFC!D~N3K1Vha2AhI@0;b!6kd!BF?i_4g3hQ&3zHcV&3K5l zc#m%UL@U~i%z}E<9gJcf&f_>9;2^%^KDMztHOV9P=sbF{sgk{M0`*CGqE(rr{zitl z`Rg|Jqb?+k`bvIq8vPtYJ02jnBqr*@->?tMJ(-4Pv5WW!1NefIXysn@x<#Zn@y3{( zGC4!t*%*Hv!U#5E3UwhLmx-JmOW;JM)U}GMq#5%W>Ov(|++5YM&Zsyk!`vjd@)suz XUf!rHo-ErPa{6~WT=vUbTX)ef$P#ZY diff --git a/vibes_auth/locale/ru_RU/LC_MESSAGES/django.po b/vibes_auth/locale/ru_RU/LC_MESSAGES/django.po index 31fa2c4e..04c9b86e 100644 --- a/vibes_auth/locale/ru_RU/LC_MESSAGES/django.po +++ b/vibes_auth/locale/ru_RU/LC_MESSAGES/django.po @@ -282,7 +282,7 @@ msgstr "Токен в черном списке" #: vibes_auth/models.py:131 msgid "blacklisted tokens" -msgstr "Токены, внесенные в черный список" +msgstr "Чёрный список токенов" #: vibes_auth/serializers.py:110 vibes_auth/serializers.py:132 msgid "no active account"