Features: None;
Fixes: 1) Correct indentation in multiple modules, including mutations, models, and utility methods to maintain consistency; 2) Fix typos in function parameters and update alignment for readability; Extra: Refactored for improved code readability and adherence to PEP 8 style guidelines.
This commit is contained in:
parent
484bd95d94
commit
0153157653
9 changed files with 101 additions and 103 deletions
|
|
@ -187,15 +187,15 @@ class BuyOrder(BaseMutation):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def mutate(
|
def mutate(
|
||||||
_parent,
|
_parent,
|
||||||
info,
|
info,
|
||||||
order_uuid=None,
|
order_uuid=None,
|
||||||
order_hr_id=None,
|
order_hr_id=None,
|
||||||
force_balance=False,
|
force_balance=False,
|
||||||
force_payment=False,
|
force_payment=False,
|
||||||
promocode_uuid=None,
|
promocode_uuid=None,
|
||||||
shipping_address=None,
|
shipping_address=None,
|
||||||
billing_address=None,
|
billing_address=None,
|
||||||
):
|
):
|
||||||
if not any([order_uuid, order_hr_id]) or all([order_uuid, order_hr_id]):
|
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"))
|
raise BadRequest(_("please provide either order_uuid or order_hr_id - mutually exclusive"))
|
||||||
|
|
@ -242,12 +242,12 @@ class BulkOrderAction(BaseMutation):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def mutate(
|
def mutate(
|
||||||
_parent,
|
_parent,
|
||||||
info,
|
info,
|
||||||
action,
|
action,
|
||||||
products,
|
products,
|
||||||
order_uuid=None,
|
order_uuid=None,
|
||||||
order_hr_id=None,
|
order_hr_id=None,
|
||||||
):
|
):
|
||||||
if not any([order_uuid, order_hr_id]) or all([order_uuid, order_hr_id]):
|
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"))
|
raise BadRequest(_("please provide either order_uuid or order_hr_id - mutually exclusive"))
|
||||||
|
|
@ -293,17 +293,17 @@ class BuyUnregisteredOrder(BaseMutation):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def mutate(
|
def mutate(
|
||||||
_parent,
|
_parent,
|
||||||
info,
|
info,
|
||||||
products,
|
products,
|
||||||
customer_name,
|
customer_name,
|
||||||
customer_email,
|
customer_email,
|
||||||
customer_phone,
|
customer_phone,
|
||||||
customer_billing_address,
|
customer_billing_address,
|
||||||
payment_method,
|
payment_method,
|
||||||
customer_shipping_address=None,
|
customer_shipping_address=None,
|
||||||
promocode_uuid=None,
|
promocode_uuid=None,
|
||||||
is_business=False,
|
is_business=False,
|
||||||
):
|
):
|
||||||
order = Order.objects.create(status="MOMENTAL")
|
order = Order.objects.create(status="MOMENTAL")
|
||||||
transaction = order.buy_without_registration(
|
transaction = order.buy_without_registration(
|
||||||
|
|
@ -425,9 +425,9 @@ class BuyWishlist(BaseMutation):
|
||||||
order = Order.objects.create(user=user, status="MOMENTAL")
|
order = Order.objects.create(user=user, status="MOMENTAL")
|
||||||
|
|
||||||
for product in (
|
for product in (
|
||||||
wishlist.products.all()
|
wishlist.products.all()
|
||||||
if user.has_perm("core.change_wishlist")
|
if user.has_perm("core.change_wishlist")
|
||||||
else wishlist.products.filter(is_active=True)
|
else wishlist.products.filter(is_active=True)
|
||||||
):
|
):
|
||||||
order.add_product(product_uuid=product.pk)
|
order.add_product(product_uuid=product.pk)
|
||||||
|
|
||||||
|
|
@ -558,9 +558,9 @@ class DeleteAddress(BaseMutation):
|
||||||
try:
|
try:
|
||||||
address = Address.objects.get(uuid=uuid)
|
address = Address.objects.get(uuid=uuid)
|
||||||
if (
|
if (
|
||||||
info.context.user.is_superuser
|
info.context.user.is_superuser
|
||||||
or info.context.user.has_perm("core.delete_address")
|
or info.context.user.has_perm("core.delete_address")
|
||||||
or info.context.user == address.user
|
or info.context.user == address.user
|
||||||
):
|
):
|
||||||
address.delete()
|
address.delete()
|
||||||
return DeleteAddress(success=True)
|
return DeleteAddress(success=True)
|
||||||
|
|
|
||||||
|
|
@ -162,9 +162,9 @@ class CategoryType(DjangoObjectType):
|
||||||
return filterable_results
|
return filterable_results
|
||||||
|
|
||||||
for attr in (
|
for attr in (
|
||||||
self.attributes.all()
|
self.attributes.all()
|
||||||
if info.context.user.has_perm("view_attribute")
|
if info.context.user.has_perm("view_attribute")
|
||||||
else self.attributes.filter(is_active=True)
|
else self.attributes.filter(is_active=True)
|
||||||
):
|
):
|
||||||
distinct_vals = (
|
distinct_vals = (
|
||||||
AttributeValue.objects.annotate(value_length=Length("value"))
|
AttributeValue.objects.annotate(value_length=Length("value"))
|
||||||
|
|
|
||||||
|
|
@ -204,9 +204,9 @@ class Command(BaseCommand):
|
||||||
maps.append(p_map)
|
maps.append(p_map)
|
||||||
|
|
||||||
data = [
|
data = [
|
||||||
("auth_key", auth_key),
|
("auth_key", auth_key),
|
||||||
("target_lang", api_code),
|
("target_lang", api_code),
|
||||||
] + [("text", t) for t in protected]
|
] + [("text", t) for t in protected]
|
||||||
resp = requests.post("https://api.deepl.com/v2/translate", data=data)
|
resp = requests.post("https://api.deepl.com/v2/translate", data=data)
|
||||||
try:
|
try:
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|
|
||||||
|
|
@ -541,16 +541,16 @@ class Order(ExportModelOperationsMixin("order"), NiceModel):
|
||||||
@property
|
@property
|
||||||
def total_price(self) -> float:
|
def total_price(self) -> float:
|
||||||
return (
|
return (
|
||||||
round(
|
round(
|
||||||
sum(
|
sum(
|
||||||
order_product.buy_price * order_product.quantity
|
order_product.buy_price * order_product.quantity
|
||||||
if order_product.status not in FAILED_STATUSES and order_product.buy_price is not None
|
if order_product.status not in FAILED_STATUSES and order_product.buy_price is not None
|
||||||
else 0.0
|
else 0.0
|
||||||
for order_product in self.order_products.all()
|
for order_product in self.order_products.all()
|
||||||
),
|
),
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
or 0.0
|
or 0.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
@ -558,7 +558,7 @@ class Order(ExportModelOperationsMixin("order"), NiceModel):
|
||||||
return sum([op.quantity for op in self.order_products.all()])
|
return sum([op.quantity for op in self.order_products.all()])
|
||||||
|
|
||||||
def add_product(
|
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:
|
if attributes is None:
|
||||||
attributes = []
|
attributes = []
|
||||||
|
|
@ -681,12 +681,12 @@ class Order(ExportModelOperationsMixin("order"), NiceModel):
|
||||||
raise Http404(_("address does not exist"))
|
raise Http404(_("address does not exist"))
|
||||||
|
|
||||||
def buy(
|
def buy(
|
||||||
self,
|
self,
|
||||||
force_balance: bool = False,
|
force_balance: bool = False,
|
||||||
force_payment: bool = False,
|
force_payment: bool = False,
|
||||||
promocode_uuid: str | None = None,
|
promocode_uuid: str | None = None,
|
||||||
billing_address: str | None = None,
|
billing_address: str | None = None,
|
||||||
shipping_address: str | None = None,
|
shipping_address: str | None = None,
|
||||||
) -> Self | Transaction | None:
|
) -> Self | Transaction | None:
|
||||||
if config.DISABLED_COMMERCE:
|
if config.DISABLED_COMMERCE:
|
||||||
raise DisabledCommerceError(_("you can not buy at this moment, please try again in a few minutes"))
|
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):
|
def finalize(self):
|
||||||
if (
|
if (
|
||||||
self.order_products.filter(
|
self.order_products.filter(
|
||||||
status__in=[
|
status__in=[
|
||||||
"ACCEPTED",
|
"ACCEPTED",
|
||||||
"FAILED",
|
"FAILED",
|
||||||
"RETURNED",
|
"RETURNED",
|
||||||
"CANCELED",
|
"CANCELED",
|
||||||
"FINISHED",
|
"FINISHED",
|
||||||
]
|
]
|
||||||
).count()
|
).count()
|
||||||
== self.order_products.count()
|
== self.order_products.count()
|
||||||
):
|
):
|
||||||
self.status = "FINISHED"
|
self.status = "FINISHED"
|
||||||
self.save()
|
self.save()
|
||||||
|
|
@ -1083,7 +1083,7 @@ class PromoCode(ExportModelOperationsMixin("promocode"), NiceModel):
|
||||||
|
|
||||||
def save(self, **kwargs):
|
def save(self, **kwargs):
|
||||||
if (self.discount_amount is not None and self.discount_percent is not None) or (
|
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(
|
raise ValidationError(
|
||||||
_("only one type of discount should be defined (amount or percent), but not both or neither.")
|
_("only one type of discount should be defined (amount or percent), but not both or neither.")
|
||||||
|
|
|
||||||
4
core/vendors/__init__.py
vendored
4
core/vendors/__init__.py
vendored
|
|
@ -37,7 +37,7 @@ class AbstractVendor:
|
||||||
if total == 0:
|
if total == 0:
|
||||||
return []
|
return []
|
||||||
chunk_size = max(1, (total + num_chunks - 1) // num_chunks)
|
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
|
@staticmethod
|
||||||
def auto_convert_value(value):
|
def auto_convert_value(value):
|
||||||
|
|
@ -85,7 +85,7 @@ class AbstractVendor:
|
||||||
# Try to detect a JSON object or array.
|
# Try to detect a JSON object or array.
|
||||||
stripped_value = value.strip()
|
stripped_value = value.strip()
|
||||||
if (stripped_value.startswith("{") and stripped_value.endswith("}")) or (
|
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):
|
with suppress(Exception):
|
||||||
parsed = json.loads(value)
|
parsed = json.loads(value)
|
||||||
|
|
|
||||||
|
|
@ -11,26 +11,24 @@ from core.views import CustomGraphQLView, CustomRedocView, CustomSwaggerView, fa
|
||||||
from evibes.settings import SPECTACULAR_PLATFORM_SETTINGS
|
from evibes.settings import SPECTACULAR_PLATFORM_SETTINGS
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(r"health/", include("health_check.urls")),
|
path(r"health/", include("health_check.urls")),
|
||||||
path("prometheus/", include("django_prometheus.urls")),
|
path("prometheus/", include("django_prometheus.urls")),
|
||||||
path(r"graphql/", csrf_exempt(CustomGraphQLView.as_view(graphiql=True, schema=schema))),
|
path(r"graphql/", csrf_exempt(CustomGraphQLView.as_view(graphiql=True, schema=schema))),
|
||||||
path(
|
path(
|
||||||
r"docs/",
|
r"docs/",
|
||||||
SpectacularAPIView.as_view(urlconf="evibes.api_urls",
|
SpectacularAPIView.as_view(urlconf="evibes.api_urls", custom_settings=SPECTACULAR_PLATFORM_SETTINGS),
|
||||||
custom_settings=SPECTACULAR_PLATFORM_SETTINGS),
|
name="schema-platform",
|
||||||
name="schema-platform",
|
),
|
||||||
),
|
path(r"docs/swagger/", CustomSwaggerView.as_view(url_name="schema-platform"), name="swagger-ui-platform"),
|
||||||
path(r"docs/swagger/", CustomSwaggerView.as_view(url_name="schema-platform"),
|
path(r"docs/redoc/", CustomRedocView.as_view(url_name="schema-platform"), name="redoc-ui-platform"),
|
||||||
name="swagger-ui-platform"),
|
path(r"i18n/", include("django.conf.urls.i18n")),
|
||||||
path(r"docs/redoc/", CustomRedocView.as_view(url_name="schema-platform"), name="redoc-ui-platform"),
|
path(r"favicon.ico", favicon_view),
|
||||||
path(r"i18n/", include("django.conf.urls.i18n")),
|
path(r"", index),
|
||||||
path(r"favicon.ico", favicon_view),
|
path(r"", include("core.api_urls")),
|
||||||
path(r"", index),
|
path(r"auth/", include("vibes_auth.urls")),
|
||||||
path(r"", include("core.api_urls")),
|
path(r"payments/", include("payments.urls")),
|
||||||
path(r"auth/", include("vibes_auth.urls")),
|
path(r"blog/", include("blog.urls")),
|
||||||
path(r"payments/", include("payments.urls")),
|
] + i18n_patterns(path("admin/", admin.site.urls))
|
||||||
path(r"blog/", include("blog.urls")),
|
|
||||||
] + i18n_patterns(path("admin/", admin.site.urls))
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,8 @@ class Transaction(NiceModel):
|
||||||
|
|
||||||
def save(self, **kwargs):
|
def save(self, **kwargs):
|
||||||
if self.amount != 0.0 and (
|
if self.amount != 0.0 and (
|
||||||
(config.PAYMENT_GATEWAY_MINIMUM <= self.amount <= config.PAYMENT_GATEWAY_MAXIMUM)
|
(config.PAYMENT_GATEWAY_MINIMUM <= self.amount <= config.PAYMENT_GATEWAY_MAXIMUM)
|
||||||
or (config.PAYMENT_GATEWAY_MINIMUM == 0 and config.PAYMENT_GATEWAY_MAXIMUM == 0)
|
or (config.PAYMENT_GATEWAY_MINIMUM == 0 and config.PAYMENT_GATEWAY_MAXIMUM == 0)
|
||||||
):
|
):
|
||||||
if len(str(self.amount).split(".")[1]) > 2:
|
if len(str(self.amount).split(".")[1]) > 2:
|
||||||
self.amount = round(self.amount, 2)
|
self.amount = round(self.amount, 2)
|
||||||
|
|
|
||||||
|
|
@ -43,17 +43,17 @@ class CreateUser(BaseMutation):
|
||||||
success = Boolean()
|
success = Boolean()
|
||||||
|
|
||||||
def mutate(
|
def mutate(
|
||||||
self,
|
self,
|
||||||
info,
|
info,
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
confirm_password,
|
confirm_password,
|
||||||
last_name=None,
|
last_name=None,
|
||||||
first_name=None,
|
first_name=None,
|
||||||
phone_number=None,
|
phone_number=None,
|
||||||
is_subscribed=None,
|
is_subscribed=None,
|
||||||
language=None,
|
language=None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
validate_password(password)
|
validate_password(password)
|
||||||
|
|
|
||||||
|
|
@ -192,8 +192,8 @@ class TokenVerifySerializer(Serializer):
|
||||||
token = UntypedToken(attrs["token"])
|
token = UntypedToken(attrs["token"])
|
||||||
|
|
||||||
if (
|
if (
|
||||||
api_settings.BLACKLIST_AFTER_ROTATION
|
api_settings.BLACKLIST_AFTER_ROTATION
|
||||||
and "rest_framework_simplejwt.token_blacklist" in settings.INSTALLED_APPS
|
and "rest_framework_simplejwt.token_blacklist" in settings.INSTALLED_APPS
|
||||||
):
|
):
|
||||||
jti = token.get(api_settings.JTI_CLAIM)
|
jti = token.get(api_settings.JTI_CLAIM)
|
||||||
if BlacklistedToken.objects.filter(token__jti=jti).exists():
|
if BlacklistedToken.objects.filter(token__jti=jti).exists():
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue