diff --git a/core/graphene/mutations.py b/core/graphene/mutations.py index a7aaa90d..819181dc 100644 --- a/core/graphene/mutations.py +++ b/core/graphene/mutations.py @@ -187,15 +187,15 @@ class BuyOrder(BaseMutation): @staticmethod def mutate( - _parent, - info, - order_uuid=None, - order_hr_id=None, - force_balance=False, - force_payment=False, - promocode_uuid=None, - shipping_address=None, - billing_address=None, + _parent, + info, + order_uuid=None, + order_hr_id=None, + force_balance=False, + force_payment=False, + promocode_uuid=None, + shipping_address=None, + billing_address=None, ): if not any([order_uuid, order_hr_id]) or all([order_uuid, order_hr_id]): raise BadRequest(_("please provide either order_uuid or order_hr_id - mutually exclusive")) @@ -242,12 +242,12 @@ class BulkOrderAction(BaseMutation): @staticmethod def mutate( - _parent, - info, - action, - products, - order_uuid=None, - order_hr_id=None, + _parent, + info, + action, + products, + order_uuid=None, + order_hr_id=None, ): if not any([order_uuid, order_hr_id]) or all([order_uuid, order_hr_id]): raise BadRequest(_("please provide either order_uuid or order_hr_id - mutually exclusive")) @@ -293,17 +293,17 @@ class BuyUnregisteredOrder(BaseMutation): @staticmethod def mutate( - _parent, - info, - products, - customer_name, - customer_email, - customer_phone, - customer_billing_address, - payment_method, - customer_shipping_address=None, - promocode_uuid=None, - is_business=False, + _parent, + info, + products, + customer_name, + customer_email, + customer_phone, + customer_billing_address, + payment_method, + customer_shipping_address=None, + promocode_uuid=None, + is_business=False, ): order = Order.objects.create(status="MOMENTAL") transaction = order.buy_without_registration( @@ -425,9 +425,9 @@ class BuyWishlist(BaseMutation): order = Order.objects.create(user=user, status="MOMENTAL") for product in ( - wishlist.products.all() - if user.has_perm("core.change_wishlist") - else wishlist.products.filter(is_active=True) + wishlist.products.all() + if user.has_perm("core.change_wishlist") + else wishlist.products.filter(is_active=True) ): order.add_product(product_uuid=product.pk) @@ -558,9 +558,9 @@ class DeleteAddress(BaseMutation): try: address = Address.objects.get(uuid=uuid) if ( - info.context.user.is_superuser - or info.context.user.has_perm("core.delete_address") - or info.context.user == address.user + info.context.user.is_superuser + or info.context.user.has_perm("core.delete_address") + or info.context.user == address.user ): address.delete() return DeleteAddress(success=True) diff --git a/core/graphene/object_types.py b/core/graphene/object_types.py index 16373940..5df4802c 100644 --- a/core/graphene/object_types.py +++ b/core/graphene/object_types.py @@ -162,9 +162,9 @@ class CategoryType(DjangoObjectType): return filterable_results for attr in ( - self.attributes.all() - if info.context.user.has_perm("view_attribute") - else self.attributes.filter(is_active=True) + self.attributes.all() + if info.context.user.has_perm("view_attribute") + else self.attributes.filter(is_active=True) ): distinct_vals = ( AttributeValue.objects.annotate(value_length=Length("value")) diff --git a/core/management/commands/deepl_translate.py b/core/management/commands/deepl_translate.py index bb7362be..78b5e95a 100644 --- a/core/management/commands/deepl_translate.py +++ b/core/management/commands/deepl_translate.py @@ -204,9 +204,9 @@ class Command(BaseCommand): maps.append(p_map) data = [ - ("auth_key", auth_key), - ("target_lang", api_code), - ] + [("text", t) for t in protected] + ("auth_key", auth_key), + ("target_lang", api_code), + ] + [("text", t) for t in protected] resp = requests.post("https://api.deepl.com/v2/translate", data=data) try: resp.raise_for_status() diff --git a/core/models.py b/core/models.py index 8edb090a..981bf62a 100644 --- a/core/models.py +++ b/core/models.py @@ -541,16 +541,16 @@ class Order(ExportModelOperationsMixin("order"), NiceModel): @property def total_price(self) -> float: return ( - round( - sum( - order_product.buy_price * order_product.quantity - if order_product.status not in FAILED_STATUSES and order_product.buy_price is not None - else 0.0 - for order_product in self.order_products.all() - ), - 2, - ) - or 0.0 + round( + sum( + order_product.buy_price * order_product.quantity + if order_product.status not in FAILED_STATUSES and order_product.buy_price is not None + else 0.0 + for order_product in self.order_products.all() + ), + 2, + ) + or 0.0 ) @property @@ -558,7 +558,7 @@ class Order(ExportModelOperationsMixin("order"), NiceModel): return sum([op.quantity for op in self.order_products.all()]) def add_product( - self, product_uuid: str | None = None, attributes: Optional[list] = None, update_quantity: bool = True + self, product_uuid: str | None = None, attributes: Optional[list] = None, update_quantity: bool = True ): if attributes is None: attributes = [] @@ -681,12 +681,12 @@ class Order(ExportModelOperationsMixin("order"), NiceModel): raise Http404(_("address does not exist")) def buy( - self, - force_balance: bool = False, - force_payment: bool = False, - promocode_uuid: str | None = None, - billing_address: str | None = None, - shipping_address: str | None = None, + self, + force_balance: bool = False, + force_payment: bool = False, + promocode_uuid: str | None = None, + billing_address: str | None = None, + shipping_address: str | None = None, ) -> Self | Transaction | None: if config.DISABLED_COMMERCE: raise DisabledCommerceError(_("you can not buy at this moment, please try again in a few minutes")) @@ -790,16 +790,16 @@ class Order(ExportModelOperationsMixin("order"), NiceModel): def finalize(self): if ( - self.order_products.filter( - status__in=[ - "ACCEPTED", - "FAILED", - "RETURNED", - "CANCELED", - "FINISHED", - ] - ).count() - == self.order_products.count() + self.order_products.filter( + status__in=[ + "ACCEPTED", + "FAILED", + "RETURNED", + "CANCELED", + "FINISHED", + ] + ).count() + == self.order_products.count() ): self.status = "FINISHED" self.save() @@ -1083,7 +1083,7 @@ class PromoCode(ExportModelOperationsMixin("promocode"), NiceModel): def save(self, **kwargs): if (self.discount_amount is not None and self.discount_percent is not None) or ( - self.discount_amount is None and self.discount_percent is None + self.discount_amount is None and self.discount_percent is None ): raise ValidationError( _("only one type of discount should be defined (amount or percent), but not both or neither.") diff --git a/core/vendors/__init__.py b/core/vendors/__init__.py index 3ae2ec56..e5a8f0c8 100644 --- a/core/vendors/__init__.py +++ b/core/vendors/__init__.py @@ -37,7 +37,7 @@ class AbstractVendor: if total == 0: return [] chunk_size = max(1, (total + num_chunks - 1) // num_chunks) - return [data[i: i + chunk_size] for i in range(0, total, chunk_size)] + return [data[i : i + chunk_size] for i in range(0, total, chunk_size)] @staticmethod def auto_convert_value(value): @@ -85,7 +85,7 @@ class AbstractVendor: # Try to detect a JSON object or array. stripped_value = value.strip() if (stripped_value.startswith("{") and stripped_value.endswith("}")) or ( - stripped_value.startswith("[") and stripped_value.endswith("]") + stripped_value.startswith("[") and stripped_value.endswith("]") ): with suppress(Exception): parsed = json.loads(value) diff --git a/evibes/api_urls.py b/evibes/api_urls.py index 1100a8f6..e66fdde7 100644 --- a/evibes/api_urls.py +++ b/evibes/api_urls.py @@ -11,26 +11,24 @@ from core.views import CustomGraphQLView, CustomRedocView, CustomSwaggerView, fa from evibes.settings import SPECTACULAR_PLATFORM_SETTINGS urlpatterns = [ - path(r"health/", include("health_check.urls")), - path("prometheus/", include("django_prometheus.urls")), - path(r"graphql/", csrf_exempt(CustomGraphQLView.as_view(graphiql=True, schema=schema))), - path( - r"docs/", - SpectacularAPIView.as_view(urlconf="evibes.api_urls", - custom_settings=SPECTACULAR_PLATFORM_SETTINGS), - name="schema-platform", - ), - path(r"docs/swagger/", CustomSwaggerView.as_view(url_name="schema-platform"), - name="swagger-ui-platform"), - path(r"docs/redoc/", CustomRedocView.as_view(url_name="schema-platform"), name="redoc-ui-platform"), - path(r"i18n/", include("django.conf.urls.i18n")), - path(r"favicon.ico", favicon_view), - path(r"", index), - path(r"", include("core.api_urls")), - path(r"auth/", include("vibes_auth.urls")), - path(r"payments/", include("payments.urls")), - path(r"blog/", include("blog.urls")), - ] + i18n_patterns(path("admin/", admin.site.urls)) + path(r"health/", include("health_check.urls")), + path("prometheus/", include("django_prometheus.urls")), + path(r"graphql/", csrf_exempt(CustomGraphQLView.as_view(graphiql=True, schema=schema))), + path( + r"docs/", + SpectacularAPIView.as_view(urlconf="evibes.api_urls", custom_settings=SPECTACULAR_PLATFORM_SETTINGS), + name="schema-platform", + ), + path(r"docs/swagger/", CustomSwaggerView.as_view(url_name="schema-platform"), name="swagger-ui-platform"), + path(r"docs/redoc/", CustomRedocView.as_view(url_name="schema-platform"), name="redoc-ui-platform"), + path(r"i18n/", include("django.conf.urls.i18n")), + path(r"favicon.ico", favicon_view), + path(r"", index), + path(r"", include("core.api_urls")), + path(r"auth/", include("vibes_auth.urls")), + path(r"payments/", include("payments.urls")), + path(r"blog/", include("blog.urls")), +] + i18n_patterns(path("admin/", admin.site.urls)) if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/payments/models.py b/payments/models.py index de32abb8..b200262f 100644 --- a/payments/models.py +++ b/payments/models.py @@ -45,8 +45,8 @@ class Transaction(NiceModel): def save(self, **kwargs): if self.amount != 0.0 and ( - (config.PAYMENT_GATEWAY_MINIMUM <= self.amount <= config.PAYMENT_GATEWAY_MAXIMUM) - or (config.PAYMENT_GATEWAY_MINIMUM == 0 and config.PAYMENT_GATEWAY_MAXIMUM == 0) + (config.PAYMENT_GATEWAY_MINIMUM <= self.amount <= config.PAYMENT_GATEWAY_MAXIMUM) + or (config.PAYMENT_GATEWAY_MINIMUM == 0 and config.PAYMENT_GATEWAY_MAXIMUM == 0) ): if len(str(self.amount).split(".")[1]) > 2: self.amount = round(self.amount, 2) diff --git a/vibes_auth/graphene/mutations.py b/vibes_auth/graphene/mutations.py index fae1bb69..450a7124 100644 --- a/vibes_auth/graphene/mutations.py +++ b/vibes_auth/graphene/mutations.py @@ -43,17 +43,17 @@ class CreateUser(BaseMutation): success = Boolean() def mutate( - self, - info, - email, - password, - confirm_password, - last_name=None, - first_name=None, - phone_number=None, - is_subscribed=None, - language=None, - **kwargs, + self, + info, + email, + password, + confirm_password, + last_name=None, + first_name=None, + phone_number=None, + is_subscribed=None, + language=None, + **kwargs, ): try: validate_password(password) diff --git a/vibes_auth/serializers.py b/vibes_auth/serializers.py index 3838324c..2628c1a6 100644 --- a/vibes_auth/serializers.py +++ b/vibes_auth/serializers.py @@ -192,8 +192,8 @@ class TokenVerifySerializer(Serializer): token = UntypedToken(attrs["token"]) if ( - api_settings.BLACKLIST_AFTER_ROTATION - and "rest_framework_simplejwt.token_blacklist" in settings.INSTALLED_APPS + api_settings.BLACKLIST_AFTER_ROTATION + and "rest_framework_simplejwt.token_blacklist" in settings.INSTALLED_APPS ): jti = token.get(api_settings.JTI_CLAIM) if BlacklistedToken.objects.filter(token__jti=jti).exists():