From 1cfa67fadac382506f1defdde55f25d53bacf0a1 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Wed, 2 Oct 2024 08:11:48 +0200 Subject: [PATCH 1/3] Update hooks, add Django 5.0 and 5.1 to the CI --- .pre-commit-config.yaml | 29 ++++------ examples/custom/settings.py | 10 ++-- .../custom/templates/plata/shop_checkout.html | 12 ++-- examples/custom/views.py | 4 +- examples/generic/settings.py | 10 ++-- .../templates/product/product_detail.html | 10 ++-- .../templates/product/product_list.html | 6 +- examples/oneprice/settings.py | 8 +-- examples/simple/settings.py | 8 +-- examples/staggered/settings.py | 8 +-- plata/__init__.py | 2 +- plata/contact/forms.py | 10 ++-- plata/contact/models.py | 2 +- plata/discount/models.py | 2 +- plata/fields.py | 2 +- plata/payment/modules/base.py | 8 +-- plata/payment/modules/check.py | 4 +- plata/payment/modules/cod.py | 2 +- plata/payment/modules/datatrans.py | 20 +++---- plata/payment/modules/ogone.py | 27 ++++----- plata/payment/modules/pagseguro.py | 21 +++---- plata/payment/modules/paypal.py | 22 +++---- plata/payment/modules/payson.py | 2 +- plata/payment/modules/postfinance.py | 27 ++++----- plata/payment/modules/prepay.py | 6 +- plata/payment/modules/stripe.py | 22 +++---- plata/product/models.py | 2 +- plata/reporting/order.py | 18 +++--- plata/reporting/pdfdocument.py | 4 +- plata/reporting/product.py | 2 +- plata/shipping/models.py | 16 ++--- plata/shop/forms.py | 9 ++- plata/shop/ga_tracking.py | 2 +- plata/shop/models.py | 6 +- plata/shop/templates/_form_errors.html | 8 +-- plata/shop/templates/_pagination.html | 2 +- plata/shop/templates/base.html | 24 ++++---- plata/shop/templates/payment/ogone_form.html | 10 ++-- .../templates/payment/pagseguro_form.html | 8 +-- plata/shop/templates/payment/paypal_form.html | 10 ++-- .../templates/payment/postfinance_form.html | 10 ++-- plata/shop/templates/payment/stripe_form.html | 8 +-- .../shop/templates/plata/_order_overview.html | 20 +++---- .../plata/notifications/contact_created.txt | 10 ++-- .../plata/notifications/order_paid.txt | 12 ++-- .../plata/notifications/packing_slip.txt | 12 ++-- plata/shop/templates/plata/shop_cart.html | 28 ++++----- plata/shop/templates/plata/shop_checkout.html | 42 +++++++------- .../templates/plata/shop_confirmation.html | 10 ++-- .../shop/templates/plata/shop_discounts.html | 12 ++-- .../plata/shop_order_payment_failure.html | 10 ++-- .../templates/plata/shop_order_success.html | 14 ++--- .../templates/plata/shop_payment_select.html | 10 ++-- .../templates/product/product_detail.html | 6 +- .../shop/templates/product/product_list.html | 6 +- plata/shop/views.py | 12 ++-- pyproject.toml | 58 ++++++++++--------- tests/testapp/base.py | 2 +- tests/testapp/test_models.py | 8 +-- tests/testapp/test_views.py | 10 ++-- tox.ini | 3 + 61 files changed, 352 insertions(+), 356 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 788a7208..ea541cfe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ exclude: ".yarn/|yarn.lock|\\.min\\.(css|js)$" repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: check-added-large-files - id: check-builtin-literals @@ -14,35 +14,26 @@ repos: - id: mixed-line-ending - id: trailing-whitespace - repo: https://github.com/adamchainz/django-upgrade - rev: 1.16.0 + rev: 1.21.0 hooks: - id: django-upgrade args: [--target-version, "3.2"] - - repo: https://github.com/MarcoGorelli/absolufy-imports - rev: v0.3.1 + - repo: https://github.com/adamchainz/djade-pre-commit + rev: "1.0.0" hooks: - - id: absolufy-imports + - id: djade + args: [--target-version, "3.2"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.3.2" + rev: "v0.6.7" hooks: - id: ruff + args: [--unsafe-fixes] - id: ruff-format - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.1.0 - hooks: - - id: prettier - args: [--list-different, --no-semi] - exclude: "^conf/|.*\\.html$" - - repo: https://github.com/biomejs/pre-commit - rev: "v0.1.0" - hooks: - - id: biome-check - additional_dependencies: ["@biomejs/biome@1.7.3"] - repo: https://github.com/tox-dev/pyproject-fmt - rev: 1.7.0 + rev: 2.2.4 hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.16 + rev: v0.19 hooks: - id: validate-pyproject diff --git a/examples/custom/settings.py b/examples/custom/settings.py index 48522373..cbd4dcea 100644 --- a/examples/custom/settings.py +++ b/examples/custom/settings.py @@ -58,13 +58,13 @@ "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = "%s.urls" % EXAMPLE +ROOT_URLCONF = f"{EXAMPLE}.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": ["%s/templates" % EXAMPLE], + "DIRS": [f"{EXAMPLE}/templates"], "APP_DIRS": True, "OPTIONS": { "context_processors": [ @@ -78,7 +78,7 @@ } ] -WSGI_APPLICATION = "%s.wsgi.application" % EXAMPLE +WSGI_APPLICATION = f"{EXAMPLE}.wsgi.application" # Database @@ -87,7 +87,7 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "%s.sqlite3" % EXAMPLE), + "NAME": os.path.join(BASE_DIR, f"{EXAMPLE}.sqlite3"), } } @@ -139,7 +139,7 @@ PLATA_REPORTING_ADDRESSLINE = "Example Corp. - 3. Example Street - 1234 Example" -PLATA_SHOP_PRODUCT = "%s.Product" % EXAMPLE +PLATA_SHOP_PRODUCT = f"{EXAMPLE}.Product" CURRENCIES = ("EUR", "CHF", "USD") TEST_RUNNER = "options.test_utils.test_runner_with_coverage" diff --git a/examples/custom/templates/plata/shop_checkout.html b/examples/custom/templates/plata/shop_checkout.html index 71366445..97e8078d 100644 --- a/examples/custom/templates/plata/shop_checkout.html +++ b/examples/custom/templates/plata/shop_checkout.html @@ -2,10 +2,10 @@ {% load i18n plata_tags %} -{% block title %}{% trans "Checkout" %} - {{ block.super }}{% endblock %} +{% block title %}{% translate "Checkout" %} - {{ block.super }}{% endblock %} {% block content %} -

{% trans "Checkout" %}

+

{% translate "Checkout" %}

{% if loginform %}
{% csrf_token %} @@ -16,7 +16,7 @@

{% trans "Checkout" %}

{{ loginform }} - +
@@ -30,7 +30,7 @@

{% trans "Checkout" %}

{% if orderform.create_account %} @@ -48,8 +48,8 @@

{% trans "Address" %}

- +
-

{% trans "Address" %}

+

{% translate "Address" %}

-{% endblock %} +{% endblock content %} diff --git a/examples/custom/views.py b/examples/custom/views.py index fd2d0bdc..609cff8b 100644 --- a/examples/custom/views.py +++ b/examples/custom/views.py @@ -14,7 +14,7 @@ class CheckoutForm(shop_forms.BaseCheckoutForm): class Meta: - fields = ["email"] + ["billing_%s" % f for f in Contact.ADDRESS_FIELDS] + fields = ["email"] + [f"billing_{f}" for f in Contact.ADDRESS_FIELDS] model = Order def __init__(self, *args, **kwargs): @@ -25,7 +25,7 @@ def __init__(self, *args, **kwargs): if contact: initial = {} for f in contact.ADDRESS_FIELDS: - initial["billing_%s" % f] = getattr(contact, f) + initial[f"billing_{f}"] = getattr(contact, f) kwargs["initial"] = initial initial["email"] = contact.user.email diff --git a/examples/generic/settings.py b/examples/generic/settings.py index 9b8f1c1f..28595b92 100644 --- a/examples/generic/settings.py +++ b/examples/generic/settings.py @@ -59,12 +59,12 @@ "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = "%s.urls" % EXAMPLE +ROOT_URLCONF = f"{EXAMPLE}.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": ["%s/templates" % EXAMPLE], + "DIRS": [f"{EXAMPLE}/templates"], "APP_DIRS": True, "OPTIONS": { "context_processors": [ @@ -78,7 +78,7 @@ } ] -WSGI_APPLICATION = "%s.wsgi.application" % EXAMPLE +WSGI_APPLICATION = f"{EXAMPLE}.wsgi.application" # Database @@ -87,7 +87,7 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "%s.sqlite3" % EXAMPLE), + "NAME": os.path.join(BASE_DIR, f"{EXAMPLE}.sqlite3"), } } @@ -139,7 +139,7 @@ PLATA_REPORTING_ADDRESSLINE = "Example Inc. - 3. Example Street - 1234 Example" -PLATA_SHOP_PRODUCT = "%s.Product" % EXAMPLE +PLATA_SHOP_PRODUCT = f"{EXAMPLE}.Product" CURRENCIES = ("EUR", "CHF", "USD") TEST_RUNNER = "options.test_utils.test_runner_with_coverage" diff --git a/examples/generic/templates/product/product_detail.html b/examples/generic/templates/product/product_detail.html index b3a9f220..bfef246c 100644 --- a/examples/generic/templates/product/product_detail.html +++ b/examples/generic/templates/product/product_detail.html @@ -2,15 +2,15 @@ {% load i18n %} -{% block title %}{{ object }} - {% trans "Products" %} - {{ block.super }}{% endblock %} +{% block title %}{{ object }} - {% translate "Products" %} - {{ block.super }}{% endblock %} {% block content %}

{{ object }}

{{ object.description|linebreaks }}
-{% if object.content_object.weight %}{% trans "Weight:" %} {{ object.content_object.weight }} kg{% endif %} -{% if object.content_type.name == "download" %}({% trans "Download" %}){% endif %} +{% if object.content_object.weight %}{% translate "Weight:" %} {{ object.content_object.weight }} kg{% endif %} +{% if object.content_type.name == "download" %}({% translate "Download" %}){% endif %}
@@ -25,7 +25,7 @@

{{ object }}

{{ form }}
- +
-{% endblock %} +{% endblock content %} diff --git a/examples/generic/templates/product/product_list.html b/examples/generic/templates/product/product_list.html index de7ae343..7604fa96 100644 --- a/examples/generic/templates/product/product_list.html +++ b/examples/generic/templates/product/product_list.html @@ -2,10 +2,10 @@ {% load i18n %} -{% block title %}{% trans "Products" %} - {{ block.super }}{% endblock %} +{% block title %}{% translate "Products" %} - {{ block.super }}{% endblock %} {% block content %} -

{% trans "Products" %}

+

{% translate "Products" %}

{% for product in object_list %}
@@ -16,4 +16,4 @@

{{ product }}

{% endfor %} {% include "_pagination.html" %} -{% endblock %} +{% endblock content %} diff --git a/examples/oneprice/settings.py b/examples/oneprice/settings.py index e41604c6..010d4338 100644 --- a/examples/oneprice/settings.py +++ b/examples/oneprice/settings.py @@ -58,7 +58,7 @@ "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = "%s.urls" % EXAMPLE +ROOT_URLCONF = f"{EXAMPLE}.urls" TEMPLATES = [ { @@ -77,7 +77,7 @@ } ] -WSGI_APPLICATION = "%s.wsgi.application" % EXAMPLE +WSGI_APPLICATION = f"{EXAMPLE}.wsgi.application" # Database @@ -86,7 +86,7 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "%s.sqlite3" % EXAMPLE), + "NAME": os.path.join(BASE_DIR, f"{EXAMPLE}.sqlite3"), } } @@ -138,7 +138,7 @@ PLATA_REPORTING_ADDRESSLINE = "Example Corp. - 3. Example Street - 1234 Example" -PLATA_SHOP_PRODUCT = "%s.Product" % EXAMPLE +PLATA_SHOP_PRODUCT = f"{EXAMPLE}.Product" CURRENCIES = ("EUR", "CHF", "USD") TEST_RUNNER = "options.test_utils.test_runner_with_coverage" diff --git a/examples/simple/settings.py b/examples/simple/settings.py index 9997854d..c923f99e 100644 --- a/examples/simple/settings.py +++ b/examples/simple/settings.py @@ -58,7 +58,7 @@ "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = "%s.urls" % EXAMPLE +ROOT_URLCONF = f"{EXAMPLE}.urls" TEMPLATES = [ { @@ -77,7 +77,7 @@ } ] -WSGI_APPLICATION = "%s.wsgi.application" % EXAMPLE +WSGI_APPLICATION = f"{EXAMPLE}.wsgi.application" # Database @@ -86,7 +86,7 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "%s.sqlite3" % EXAMPLE), + "NAME": os.path.join(BASE_DIR, f"{EXAMPLE}.sqlite3"), } } @@ -138,7 +138,7 @@ PLATA_REPORTING_ADDRESSLINE = "Example Corp. - 3. Example Street - 1234 Example" -PLATA_SHOP_PRODUCT = "%s.Product" % EXAMPLE +PLATA_SHOP_PRODUCT = f"{EXAMPLE}.Product" CURRENCIES = ("EUR", "CHF", "USD") TEST_RUNNER = "options.test_utils.test_runner_with_coverage" diff --git a/examples/staggered/settings.py b/examples/staggered/settings.py index d4073022..6a0728ec 100644 --- a/examples/staggered/settings.py +++ b/examples/staggered/settings.py @@ -58,7 +58,7 @@ "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = "%s.urls" % EXAMPLE +ROOT_URLCONF = f"{EXAMPLE}.urls" TEMPLATES = [ { @@ -77,7 +77,7 @@ } ] -WSGI_APPLICATION = "%s.wsgi.application" % EXAMPLE +WSGI_APPLICATION = f"{EXAMPLE}.wsgi.application" # Database @@ -86,7 +86,7 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "%s.sqlite3" % EXAMPLE), + "NAME": os.path.join(BASE_DIR, f"{EXAMPLE}.sqlite3"), } } @@ -138,7 +138,7 @@ PLATA_REPORTING_ADDRESSLINE = "Example Corp. - 3. Example Street - 1234 Example" -PLATA_SHOP_PRODUCT = "%s.Product" % EXAMPLE +PLATA_SHOP_PRODUCT = f"{EXAMPLE}.Product" CURRENCIES = ("EUR", "CHF", "USD") TEST_RUNNER = "options.test_utils.test_runner_with_coverage" diff --git a/plata/__init__.py b/plata/__init__.py index 2e3eafc3..0bd7efc7 100644 --- a/plata/__init__.py +++ b/plata/__init__.py @@ -32,7 +32,7 @@ def __getattr__(self, attr): def register(instance): - logger.debug("Registering shop instance: %s" % instance) + logger.debug(f"Registering shop instance: {instance}") global shop_instance_cache shop_instance_cache = instance diff --git a/plata/contact/forms.py b/plata/contact/forms.py index a0765d22..c7d09c93 100644 --- a/plata/contact/forms.py +++ b/plata/contact/forms.py @@ -8,8 +8,8 @@ class CheckoutForm(shop_forms.BaseCheckoutForm): class Meta: fields = ["notes", "email", "phone", "shipping_same_as_billing"] - fields.extend("billing_%s" % f for f in Order.ADDRESS_FIELDS) - fields.extend("shipping_%s" % f for f in Order.ADDRESS_FIELDS) + fields.extend(f"billing_{f}" for f in Order.ADDRESS_FIELDS) + fields.extend(f"shipping_{f}" for f in Order.ADDRESS_FIELDS) model = Order def __init__(self, *args, **kwargs): @@ -31,8 +31,8 @@ def __init__(self, *args, **kwargs): } for f in contact.ADDRESS_FIELDS: - initial["billing_%s" % f] = getattr(contact, "billing_%s" % f) - initial["shipping_%s" % f] = getattr(contact, "shipping_%s" % f) + initial[f"billing_{f}"] = getattr(contact, f"billing_{f}") + initial[f"shipping_{f}"] = getattr(contact, f"shipping_{f}") kwargs["initial"] = initial @@ -55,7 +55,7 @@ def clean(self): if not data.get("shipping_same_as_billing"): for f in self.REQUIRED_ADDRESS_FIELDS: - field = "shipping_%s" % f + field = f"shipping_{f}" if not data.get(field): self._errors[field] = self.error_class( [_("This field is required.")] diff --git a/plata/contact/models.py b/plata/contact/models.py index 176369b2..2f96e7a8 100644 --- a/plata/contact/models.py +++ b/plata/contact/models.py @@ -40,7 +40,7 @@ class Meta: verbose_name_plural = _("contacts") def __str__(self): - return "%s" % self.user + return f"{self.user}" def update_from_order(self, order, request=None): """ diff --git a/plata/discount/models.py b/plata/discount/models.py index ed7dd764..c87058e0 100644 --- a/plata/discount/models.py +++ b/plata/discount/models.py @@ -149,7 +149,7 @@ def apply(self, order, items, **kwargs): elif self.type == self.MEANS_OF_PAYMENT: self._apply_means_of_payment(order, items) else: - raise NotImplementedError("Unknown discount type %s" % self.type) + raise NotImplementedError(f"Unknown discount type {self.type}") def _apply_amount_discount(self, order, items, tax_included): """ diff --git a/plata/fields.py b/plata/fields.py index cdf17f09..2f0af668 100644 --- a/plata/fields.py +++ b/plata/fields.py @@ -36,7 +36,7 @@ def json_encode_default(o): return o.strftime("%Y-%m-%d") elif isinstance(o, datetime.time): return o.strftime("%H:%M:%S.%f%z") - raise TypeError("Cannot encode %r" % o) + raise TypeError(f"Cannot encode {o!r}") _PATTERNS = [ diff --git a/plata/payment/modules/base.py b/plata/payment/modules/base.py index e0295ad3..dad408ba 100644 --- a/plata/payment/modules/base.py +++ b/plata/payment/modules/base.py @@ -90,7 +90,7 @@ def clear_pending_payments(self, order): """ Clear pending payments """ - logger.info("Clearing pending payments on %s" % order) + logger.info(f"Clearing pending payments on {order}") if plata.settings.PLATA_STOCK_TRACKING: StockTransaction = plata.stock_model() for transaction in order.stock_transactions.filter( @@ -105,12 +105,12 @@ def create_pending_payment(self, order): Create a pending payment """ self.clear_pending_payments(order) - logger.info("Creating pending payment on %s" % order) + logger.info(f"Creating pending payment on {order}") return order.payments.create( currency=order.currency, amount=order.balance_remaining, payment_module_key=self.key, - payment_module="%s" % self.name, + payment_module=f"{self.name}", ) def create_transactions(self, order, stage, **kwargs): @@ -217,7 +217,7 @@ def already_paid(self, order, request=None): Does nothing if the order **status** is ``PAID`` already. """ if order.status < order.PAID: - logger.info("Order %s is already completely paid" % order) + logger.info(f"Order {order} is already completely paid") if plata.settings.PLATA_STOCK_TRACKING: StockTransaction = plata.stock_model() diff --git a/plata/payment/modules/check.py b/plata/payment/modules/check.py index 57b7a019..5f368724 100644 --- a/plata/payment/modules/check.py +++ b/plata/payment/modules/check.py @@ -46,7 +46,7 @@ def process_order_confirmed(self, request, order): if not order.balance_remaining: return self.already_paid(order) - logger.info("Processing order %s using check" % order) + logger.info(f"Processing order {order} using check") payment = self.create_pending_payment(order) @@ -82,7 +82,7 @@ def process_order_confirmed(self, request, order): first_name=order.user.first_name, last_name=order.user.last_name, email=order.email, - items=", ".join(("%s" % item) for item in order.items.all()), + items=", ".join(("{}".format(item)) for item in order.items.all()), remaining=order.balance_remaining, currency=order.currency, confirm_link=confirm_link, diff --git a/plata/payment/modules/cod.py b/plata/payment/modules/cod.py index 897b4211..4dc1abc7 100644 --- a/plata/payment/modules/cod.py +++ b/plata/payment/modules/cod.py @@ -25,7 +25,7 @@ def process_order_confirmed(self, request, order): if not order.balance_remaining: return self.already_paid(order, request=request) - logger.info("Processing order %s using COD" % order) + logger.info(f"Processing order {order} using COD") payment = self.create_pending_payment(order) diff --git a/plata/payment/modules/datatrans.py b/plata/payment/modules/datatrans.py index ca159914..fe3a4b91 100644 --- a/plata/payment/modules/datatrans.py +++ b/plata/payment/modules/datatrans.py @@ -68,7 +68,7 @@ def process_order_confirmed(self, request, order): if not order.balance_remaining: return self.already_paid(order, request=request) - logger.info("Processing order %s using Datatrans" % order) + logger.info(f"Processing order {order} using Datatrans") payment = self.create_pending_payment(order) if plata.settings.PLATA_STOCK_TRACKING: @@ -102,7 +102,7 @@ def process_order_confirmed(self, request, order): @csrf_exempt_m def datatrans_error(self, request): error_code = int(request.POST.get("errorCode")) - logger.info("Got an error during datatrans payment! code is %s" % error_code) + logger.info(f"Got an error during datatrans payment! code is {error_code}") return redirect("plata_shop_checkout") @csrf_exempt_m @@ -125,7 +125,7 @@ def datatrans_success(self, request): parameters = request.POST.copy() parameters_repr = repr(parameters).encode("utf-8") if parameters: - logger.info("IPN: Processing request data %s" % parameters_repr) + logger.info(f"IPN: Processing request data {parameters_repr}") xml = """ @@ -160,20 +160,18 @@ def datatrans_success(self, request): try: order_id, payment_id = refno.split("-") except ValueError: - logger.error("IPN: Error getting order for %s" % refno) + logger.error(f"IPN: Error getting order for {refno}") return HttpResponseForbidden("Malformed order ID") try: order = self.shop.order_model.objects.get(pk=order_id) except self.shop.order_model.DoesNotExist: - logger.error("IPN: Order %s does not exist" % order_id) - return HttpResponseForbidden("Order %s does not exist" % order_id) + logger.error(f"IPN: Order {order_id} does not exist") + return HttpResponseForbidden(f"Order {order_id} does not exist") try: payment = order.payments.get(pk=payment_id) except order.payments.model.DoesNotExist: - return HttpResponseForbidden( - "Payment %s does not exist" % payment_id - ) + return HttpResponseForbidden(f"Payment {payment_id} does not exist") payment.status = OrderPayment.PROCESSED payment.currency = currency @@ -188,7 +186,7 @@ def datatrans_success(self, request): payment.save() order = order.reload() - logger.info("IPN: Successfully processed IPN request for %s" % order) + logger.info(f"IPN: Successfully processed IPN request for {order}") if payment.authorized and plata.settings.PLATA_STOCK_TRACKING: StockTransaction = plata.stock_model() @@ -206,5 +204,5 @@ def datatrans_success(self, request): return redirect("plata_order_success") except Exception as e: - logger.error("IPN: Processing failure %s" % e) + logger.error(f"IPN: Processing failure {e}") raise diff --git a/plata/payment/modules/ogone.py b/plata/payment/modules/ogone.py index 7418db95..955e7d60 100644 --- a/plata/payment/modules/ogone.py +++ b/plata/payment/modules/ogone.py @@ -93,7 +93,7 @@ def process_order_confirmed(self, request, order): if not order.balance_remaining: return self.already_paid(order, request=request) - logger.info("Processing order %s using Ogone" % order) + logger.info(f"Processing order {order} using Ogone") payment = self.create_pending_payment(order) if plata.settings.PLATA_STOCK_TRACKING: @@ -110,8 +110,9 @@ def process_order_confirmed(self, request, order): form_params = { "PSPID": OGONE["PSPID"], "orderID": "Order-%d-%d" % (order.id, payment.id), - "amount": "%s" - % int(order.balance_remaining.quantize(Decimal("0.00")) * 100), + "amount": "{}".format( + int(order.balance_remaining.quantize(Decimal("0.00")) * 100) + ), "currency": order.currency, "language": locale.normalize(to_locale(get_language())).split(".")[0], "CN": f"{order.billing_first_name} {order.billing_last_name}", @@ -150,7 +151,7 @@ def process_order_confirmed(self, request, order): return self.shop.render( request, - "payment/%s_form.html" % self.key, + f"payment/{self.key}_form.html", { "order": order, "HTTP_HOST": request.get_host(), @@ -165,7 +166,7 @@ def ipn(self, request): try: parameters_repr = repr(request.POST.copy()).encode("utf-8") - logger.info("IPN: Processing request data %s" % parameters_repr) + logger.info(f"IPN: Processing request data {parameters_repr}") try: orderID = request.POST["orderID"] @@ -176,7 +177,7 @@ def ipn(self, request): BRAND = request.POST["BRAND"] SHASIGN = request.POST["SHASIGN"] except KeyError: - logger.error("IPN: Missing data in %s" % parameters_repr) + logger.error(f"IPN: Missing data in {parameters_repr}") return HttpResponseForbidden("Missing data") value_strings = [ @@ -189,13 +190,13 @@ def ipn(self, request): ).hexdigest() if sha1_out.lower() != SHASIGN.lower(): - logger.error("IPN: Invalid hash in %s" % parameters_repr) + logger.error(f"IPN: Invalid hash in {parameters_repr}") return HttpResponseForbidden("Hash did not validate") try: order, order_id, payment_id = orderID.split("-") except ValueError: - logger.error("IPN: Error getting order for %s" % orderID) + logger.error(f"IPN: Error getting order for {orderID}") return HttpResponseForbidden("Malformed order ID") # Try fetching the order and order payment objects @@ -204,14 +205,14 @@ def ipn(self, request): try: order = self.shop.order_model.objects.get(pk=order_id) except self.shop.order_model.DoesNotExist: - logger.error("IPN: Order %s does not exist" % order_id) - return HttpResponseForbidden("Order %s does not exist" % order_id) + logger.error(f"IPN: Order {order_id} does not exist") + return HttpResponseForbidden(f"Order {order_id} does not exist") try: payment = order.payments.get(pk=payment_id) except order.payments.model.DoesNotExist: payment = order.payments.model( - order=order, payment_module="%s" % self.name + order=order, payment_module=f"{self.name}" ) payment.status = OrderPayment.PROCESSED @@ -229,7 +230,7 @@ def ipn(self, request): payment.save() order = order.reload() - logger.info("IPN: Successfully processed IPN request for %s" % order) + logger.info(f"IPN: Successfully processed IPN request for {order}") if payment.authorized and plata.settings.PLATA_STOCK_TRACKING: StockTransaction = plata.stock_model() @@ -246,5 +247,5 @@ def ipn(self, request): return HttpResponse("OK") except Exception as e: - logger.error("IPN: Processing failure %s" % e) + logger.error(f"IPN: Processing failure {e}") raise diff --git a/plata/payment/modules/pagseguro.py b/plata/payment/modules/pagseguro.py index b42129fa..378bf07e 100644 --- a/plata/payment/modules/pagseguro.py +++ b/plata/payment/modules/pagseguro.py @@ -48,7 +48,7 @@ def process_order_confirmed(self, request, order): if not order.balance_remaining: return self.already_paid(order) - logger.info("Processing order %s using PagSeguro" % order) + logger.info(f"Processing order {order} using PagSeguro") payment = self.create_pending_payment(order) if plata.settings.PLATA_STOCK_TRACKING: @@ -85,7 +85,7 @@ def psnotify(self, request): data = {k: v.encode("ISO-8859-1") for k, v in data.items()} if data: - logger.info("Pagseguro: Processing request data %s" % data) + logger.info(f"Pagseguro: Processing request data {data}") if PAGSEGURO.get("LOG"): f = open(PAGSEGURO["LOG"], "a+") @@ -117,8 +117,9 @@ def psnotify(self, request): ) except (ValueError, IndexError): logger.error( - "Pagseguro: Can't verify notification: %s" - % result.decode("ISO-8859-1") + "Pagseguro: Can't verify notification: {}".format( + result.decode("ISO-8859-1") + ) ) return HttpResponseForbidden("Order verification failed") @@ -129,27 +130,27 @@ def psnotify(self, request): ) f.close() - logger.info("Pagseguro: Verified request %s" % result) + logger.info(f"Pagseguro: Verified request {result}") try: order, order_id, payment_id = reference.split("-") except ValueError: - logger.error("Pagseguro: Error getting order for %s" % reference) + logger.error(f"Pagseguro: Error getting order for {reference}") return HttpResponseForbidden(_("Malformed order ID")) try: order = self.shop.order_model.objects.get(pk=order_id) except self.shop.order_model.DoesNotExist: - logger.error("Pagseguro: Order %s does not exist" % order_id) + logger.error(f"Pagseguro: Order {order_id} does not exist") return HttpResponseForbidden( - _("Order %s does not exist" % order_id) + _("Order {} does not exist".format(order_id)) ) try: payment = order.payments.get(pk=payment_id) except order.payments.model.DoesNotExist: payment = order.payments.model( - order=order, payment_module="%s" % self.name + order=order, payment_module=f"{self.name}" ) payment.status = OrderPayment.PROCESSED @@ -166,7 +167,7 @@ def psnotify(self, request): order = order.reload() payment.amount = Decimal(amount) - logger.info("Pagseguro: Successfully processed request for %s" % order) + logger.info(f"Pagseguro: Successfully processed request for {order}") if payment.authorized and plata.settings.PLATA_STOCK_TRACKING: StockTransaction = plata.stock_model() diff --git a/plata/payment/modules/paypal.py b/plata/payment/modules/paypal.py index 1777629d..37dd4547 100644 --- a/plata/payment/modules/paypal.py +++ b/plata/payment/modules/paypal.py @@ -45,7 +45,7 @@ def process_order_confirmed(self, request, order): if not order.balance_remaining: return self.already_paid(order, request=request) - logger.info("Processing order %s using Paypal" % order) + logger.info(f"Processing order {order} using Paypal") payment = self.create_pending_payment(order) if plata.settings.PLATA_STOCK_TRACKING: @@ -65,7 +65,7 @@ def process_order_confirmed(self, request, order): return self.shop.render( request, - "payment/%s_form.html" % self.key, + f"payment/{self.key}_form.html", { "order": order, "payment": payment, @@ -120,9 +120,9 @@ def ipn(self, request): parameters_repr = repr(parameters).encode("utf-8") if parameters: - logger.info("IPN: Processing request data %s" % parameters_repr) + logger.info(f"IPN: Processing request data {parameters_repr}") - querystring = "cmd=_notify-validate&%s" % (request.POST.urlencode()) + querystring = f"cmd=_notify-validate&{request.POST.urlencode()}" status = urlopen(PP_URL, querystring).read() if status != b"VERIFIED": @@ -135,7 +135,7 @@ def ipn(self, request): return HttpResponseForbidden("Unable to verify") if parameters: - logger.info("IPN: Verified request %s" % parameters_repr) + logger.info(f"IPN: Verified request {parameters_repr}") reference = parameters["txn_id"] invoice_id = parameters["invoice"] currency = parameters["mc_currency"] @@ -144,20 +144,20 @@ def ipn(self, request): try: order, order_id, payment_id = invoice_id.split("-") except ValueError: - logger.error("IPN: Error getting order for %s" % invoice_id) + logger.error(f"IPN: Error getting order for {invoice_id}") return HttpResponseForbidden("Malformed order ID") try: order = self.shop.order_model.objects.get(pk=order_id) except (self.shop.order_model.DoesNotExist, ValueError): - logger.error("IPN: Order %s does not exist" % order_id) - return HttpResponseForbidden("Order %s does not exist" % order_id) + logger.error(f"IPN: Order {order_id} does not exist") + return HttpResponseForbidden(f"Order {order_id} does not exist") try: payment = order.payments.get(pk=payment_id) except (order.payments.model.DoesNotExist, ValueError): payment = order.payments.model( - order=order, payment_module="%s" % self.name + order=order, payment_module=f"{self.name}" ) payment.status = OrderPayment.PROCESSED @@ -174,7 +174,7 @@ def ipn(self, request): payment.save() order = order.reload() - logger.info("IPN: Successfully processed IPN request for %s" % order) + logger.info(f"IPN: Successfully processed IPN request for {order}") if payment.authorized and plata.settings.PLATA_STOCK_TRACKING: StockTransaction = plata.stock_model() @@ -192,7 +192,7 @@ def ipn(self, request): return HttpResponse("Ok") except Exception as e: - logger.error("IPN: Processing failure %s" % e) + logger.error(f"IPN: Processing failure {e}") raise else: logger.warning("IPN received without POST parameters") diff --git a/plata/payment/modules/payson.py b/plata/payment/modules/payson.py index 59c22724..a53d0752 100644 --- a/plata/payment/modules/payson.py +++ b/plata/payment/modules/payson.py @@ -49,7 +49,7 @@ def process_order_confirmed(self, request, order): return self.already_paid(order) if order.currency not in ("SEK", "EUR"): raise ValueError( - "Payson payments only support SEK and EUR, not %s." % order.currency + f"Payson payments only support SEK and EUR, not {order.currency}." ) # TODO: log diff --git a/plata/payment/modules/postfinance.py b/plata/payment/modules/postfinance.py index 526904f9..f173d65f 100644 --- a/plata/payment/modules/postfinance.py +++ b/plata/payment/modules/postfinance.py @@ -94,7 +94,7 @@ def process_order_confirmed(self, request, order): if not order.balance_remaining: return self.already_paid(order, request=request) - logger.info("Processing order %s using Postfinance" % order) + logger.info(f"Processing order {order} using Postfinance") payment = self.create_pending_payment(order) if plata.settings.PLATA_STOCK_TRACKING: @@ -109,8 +109,9 @@ def process_order_confirmed(self, request, order): form_params = { "orderID": "Order-%d-%d" % (order.id, payment.id), - "amount": "%s" - % int(order.balance_remaining.quantize(Decimal("0.00")) * 100), + "amount": "{}".format( + int(order.balance_remaining.quantize(Decimal("0.00")) * 100) + ), "currency": order.currency, "PSPID": POSTFINANCE["PSPID"], "mode": POSTFINANCE["LIVE"] and "prod" or "test", @@ -132,7 +133,7 @@ def process_order_confirmed(self, request, order): return self.shop.render( request, - "payment/%s_form.html" % self.key, + f"payment/{self.key}_form.html", { "order": order, "HTTP_HOST": request.get_host(), @@ -147,7 +148,7 @@ def ipn(self, request): try: parameters_repr = repr(request.POST.copy()).encode("utf-8") - logger.info("IPN: Processing request data %s" % parameters_repr) + logger.info(f"IPN: Processing request data {parameters_repr}") try: orderID = request.POST["orderID"] @@ -162,7 +163,7 @@ def ipn(self, request): BRAND = request.POST["BRAND"] SHASIGN = request.POST["SHASIGN"] except KeyError: - logger.error("IPN: Missing data in %s" % parameters_repr) + logger.error(f"IPN: Missing data in {parameters_repr}") return HttpResponseForbidden("Missing data") sha1_source = "".join( @@ -184,13 +185,13 @@ def ipn(self, request): sha1_out = sha1(sha1_source.encode("utf-8")).hexdigest() if sha1_out.lower() != SHASIGN.lower(): - logger.error("IPN: Invalid hash in %s" % parameters_repr) + logger.error(f"IPN: Invalid hash in {parameters_repr}") return HttpResponseForbidden("Hash did not validate") try: order, order_id, payment_id = orderID.split("-") except ValueError: - logger.error("IPN: Error getting order for %s" % orderID) + logger.error(f"IPN: Error getting order for {orderID}") return HttpResponseForbidden("Malformed order ID") # Try fetching the order and order payment objects @@ -199,14 +200,14 @@ def ipn(self, request): try: order = self.shop.order_model.objects.get(pk=order_id) except self.shop.order_model.DoesNotExist: - logger.error("IPN: Order %s does not exist" % order_id) - return HttpResponseForbidden("Order %s does not exist" % order_id) + logger.error(f"IPN: Order {order_id} does not exist") + return HttpResponseForbidden(f"Order {order_id} does not exist") try: payment = order.payments.get(pk=payment_id) except order.payments.model.DoesNotExist: payment = order.payments.model( - order=order, payment_module="%s" % self.name + order=order, payment_module=f"{self.name}" ) payment.status = OrderPayment.PROCESSED @@ -224,7 +225,7 @@ def ipn(self, request): payment.save() order = order.reload() - logger.info("IPN: Successfully processed IPN request for %s" % order) + logger.info(f"IPN: Successfully processed IPN request for {order}") if payment.authorized and plata.settings.PLATA_STOCK_TRACKING: StockTransaction = plata.stock_model() @@ -241,5 +242,5 @@ def ipn(self, request): return HttpResponse("OK") except Exception as e: - logger.error("IPN: Processing failure %s" % e) + logger.error(f"IPN: Processing failure {e}") raise diff --git a/plata/payment/modules/prepay.py b/plata/payment/modules/prepay.py index c3a14c54..eaec3dfe 100644 --- a/plata/payment/modules/prepay.py +++ b/plata/payment/modules/prepay.py @@ -47,9 +47,7 @@ def process_order_confirmed(self, request, order): if not order.balance_remaining: return self.already_paid(order) - logger.info( - "Processing order %s using bank transfer in advance (prepay)" % order - ) + logger.info(f"Processing order {order} using bank transfer in advance (prepay)") payment = self.create_pending_payment(order) @@ -85,7 +83,7 @@ def process_order_confirmed(self, request, order): first_name=order.user.first_name, last_name=order.user.last_name, email=order.email, - items=", ".join(("%s" % item) for item in order.items.all()), + items=", ".join(("{}".format(item)) for item in order.items.all()), remaining=order.balance_remaining, currency=order.currency, confirm_link=confirm_link, diff --git a/plata/payment/modules/stripe.py b/plata/payment/modules/stripe.py index 59b62273..575d43ed 100644 --- a/plata/payment/modules/stripe.py +++ b/plata/payment/modules/stripe.py @@ -45,43 +45,43 @@ def handle_errors(bla): body = e.json_body err = body["error"] logger.error( - ("Status %s: " % e.http_status) + (f"Status {e.http_status}: ") + 'type "{type}", code "{code}", param "{param}": {message}'.format(**err) ) except stripe.error.RateLimitError as e: # Too many requests made to the API too quickly - logger.error("RateLimitError: %s" % e) + logger.error(f"RateLimitError: {e}") except stripe.error.InvalidRequestError as e: # Invalid parameters were supplied to Stripe's API - logger.error("InvalidRequestError: %s" % e) + logger.error(f"InvalidRequestError: {e}") except stripe.error.AuthenticationError as e: # Authentication with Stripe's API failed # (maybe you changed API keys recently) - logger.error("AuthenticationError: %s" % e) + logger.error(f"AuthenticationError: {e}") except stripe.error.APIConnectionError as e: # Network communication with Stripe failed - logger.error("APIConnectionError: %s" % e) + logger.error(f"APIConnectionError: {e}") except stripe.error.StripeError as e: # Display a very generic error to the user, and maybe send # yourself an email - logger.error("StripeError: %s" % e) + logger.error(f"StripeError: {e}") except Exception as e: # Something else happened, completely unrelated to Stripe - logger.error("Exception: %s" % e) + logger.error(f"Exception: {e}") class PaymentProcessor(ProcessorBase): key = "stripe" default_name = _("Stripe") - template = "payment/%s_form.html" % key + template = f"payment/{key}_form.html" amount = 0 def get_urls(self): return [ re_path( - r"^payment/%s/$" % self.key, + rf"^payment/{self.key}/$", self.callback, - name="%s_callback" % self.key, + name=f"{self.key}_callback", ) ] @@ -129,7 +129,7 @@ def process_order_confirmed(self, request, order): { "order": order, "payment": payment, - "post_url": "/payment/%s/" % self.key, # internal, gets payment token + "post_url": f"/payment/{self.key}/", # internal, gets payment token "amount": self.amount, "currency": order.currency.lower(), "public_key": STRIPE["PUBLIC_KEY"], diff --git a/plata/product/models.py b/plata/product/models.py index b5ed47a4..1812856b 100644 --- a/plata/product/models.py +++ b/plata/product/models.py @@ -49,5 +49,5 @@ def handle_order_item(self, orderitem): sufficient for posteriority. Old orders should always be complete even if the products have been changed or deleted in the meantime. """ - orderitem.name = "%s" % self + orderitem.name = f"{self}" orderitem.sku = getattr(self, "sku", "") diff --git a/plata/reporting/order.py b/plata/reporting/order.py index a98e6257..1a05cc55 100644 --- a/plata/reporting/order.py +++ b/plata/reporting/order.py @@ -75,8 +75,8 @@ def items_with_prices(self): item.sku, item.name, item.quantity, - "%.2f" % item.unit_price, - "%.2f" % item.discounted_subtotal, + f"{item.unit_price:.2f}", + f"{item.discounted_subtotal:.2f}", ) for item in self.order.items.all() ], @@ -87,17 +87,17 @@ def items_with_prices(self): def summary(self): summary_table = [ ("", ""), - (capfirst(_("subtotal")), "%.2f" % self.order.subtotal), + (capfirst(_("subtotal")), f"{self.order.subtotal:.2f}"), ] if self.order.discount: summary_table.append( - (capfirst(_("discount")), "%.2f" % self.order.discount) + (capfirst(_("discount")), f"{self.order.discount:.2f}") ) if self.order.shipping: summary_table.append( - (capfirst(_("shipping")), "%.2f" % self.order.shipping) + (capfirst(_("shipping")), f"{self.order.shipping:.2f}") ) self.pdf.table(summary_table, (12 * cm, 4.4 * cm), self.pdf.style.table) @@ -113,7 +113,9 @@ def summary(self): [ ( "", - "{} {}".format(_("Incl. tax"), "%.1f%%" % row["tax_rate"]), + "{} {}".format( + _("Incl. tax"), "{:.1f}%".format(row["tax_rate"]) + ), row["total"].quantize(zero), row["tax_amount"].quantize(zero), "", @@ -126,7 +128,7 @@ def summary(self): ) self.pdf.table( - [(total_title, "%.2f" % self.order.total)], + [(total_title, f"{self.order.total:.2f}")], (12 * cm, 4.4 * cm), self.pdf.style.tableHead, ) @@ -177,7 +179,7 @@ def address_table(self): "FONT", (0, 0), (-1, 0), - "%s-Bold" % self.pdf.style.fontName, + f"{self.pdf.style.fontName}-Bold", self.pdf.style.fontSize, ), ("TOPPADDING", (0, 0), (-1, -1), 1), diff --git a/plata/reporting/pdfdocument.py b/plata/reporting/pdfdocument.py index c4b22251..aab37d78 100644 --- a/plata/reporting/pdfdocument.py +++ b/plata/reporting/pdfdocument.py @@ -7,7 +7,7 @@ def init_regular_font(suffix=""): name = f"{plata.settings.PLATA_PDF_FONT_NAME}{suffix}" - path = plata.settings.PLATA_PDF_FONT_PATH or "%s.ttf" % name + path = plata.settings.PLATA_PDF_FONT_PATH or f"{name}.ttf" pdfmetrics.registerFont(TTFont(name, path)) @@ -21,7 +21,7 @@ def __init__(self, *args, **kwargs): if plata.settings.PLATA_PDF_FONT_BOLD_NAME: # init bold font variant name = plata.settings.PLATA_PDF_FONT_BOLD_NAME - path = plata.settings.PLATA_PDF_FONT_BOLD_PATH or "%s.ttf" % name + path = plata.settings.PLATA_PDF_FONT_BOLD_PATH or f"{name}.ttf" pdfmetrics.registerFont(TTFont(name, path)) elif plata.settings.PLATA_PDF_FONT_NAME: # init bold font variant from regular font, bold is always needed diff --git a/plata/reporting/product.py b/plata/reporting/product.py index 84fe3754..c64402a2 100644 --- a/plata/reporting/product.py +++ b/plata/reporting/product.py @@ -33,7 +33,7 @@ def product_xls(): transactions[t["product"]][t["type"]] = t["change__sum"] titles = [capfirst(_("product")), _("SKU"), capfirst(_("stock"))] - titles.extend("%s" % row[1] for row in StockTransaction.TYPE_CHOICES) + titles.extend(f"{row[1]}" for row in StockTransaction.TYPE_CHOICES) data = [] diff --git a/plata/shipping/models.py b/plata/shipping/models.py index cd65b8a4..cf6572d2 100644 --- a/plata/shipping/models.py +++ b/plata/shipping/models.py @@ -147,32 +147,32 @@ class Postage(models.Model): default=plata.settings.PLATA_PRICE_INCLUDES_TAX, ) weight_packaging = models.PositiveIntegerField( - verbose_name=_("weight of packaging [%s]" % WEIGHT_UNIT), + verbose_name=_("weight of packaging [{}]".format(WEIGHT_UNIT)), default=0, help_text=_("The approx. weight of the necessary packaging for this package"), ) max_weight = models.PositiveIntegerField( - verbose_name=_("max. weight [%s]" % WEIGHT_UNIT), + verbose_name=_("max. weight [{}]".format(WEIGHT_UNIT)), default=0, help_text=_("Maximum weight for this tariff. 0 = ignored"), ) max_length = models.PositiveIntegerField( - verbose_name=_("max. length [%s]" % LENGTH_UNIT), + verbose_name=_("max. length [{}]".format(LENGTH_UNIT)), default=0, help_text=_("Maximum length for this tariff. 0 = ignored"), ) max_width = models.PositiveIntegerField( - verbose_name=_("max. width [%s]" % LENGTH_UNIT), + verbose_name=_("max. width [{}]".format(LENGTH_UNIT)), default=0, help_text=_("Maximum width for this tariff. 0 = ignored"), ) max_height = models.PositiveIntegerField( - verbose_name=_("max. height [%s]" % LENGTH_UNIT), + verbose_name=_("max. height [{}]".format(LENGTH_UNIT)), default=0, help_text=_("Maximum height for this tariff. 0 = ignored"), ) max_3d = models.PositiveIntegerField( - verbose_name=_("max. dimensions [%s]" % LENGTH_UNIT), + verbose_name=_("max. dimensions [{}]".format(LENGTH_UNIT)), default=0, help_text=_( "Maximum measure of length+width+height for this tariff. 0 = ignored" @@ -212,8 +212,8 @@ def max_size(self): return size max_size.help_text = _("maximum size of length + width + height") - max_size.short_description = _("max. size [%s]" % LENGTH_UNIT) - max_size.verbose_name = _("max. size [%s]" % LENGTH_UNIT) + max_size.short_description = _("max. size [{}]".format(LENGTH_UNIT)) + max_size.verbose_name = _("max. size [{}]".format(LENGTH_UNIT)) def max_size_f(self): """ diff --git a/plata/shop/forms.py b/plata/shop/forms.py index c7a05c35..1eac3b12 100644 --- a/plata/shop/forms.py +++ b/plata/shop/forms.py @@ -1,5 +1,6 @@ from django import forms from django.contrib import auth +from django.utils.crypto import get_random_string from django.utils.translation import gettext_lazy as _ from plata.shop import signals @@ -14,6 +15,10 @@ from django.contrib.auth.models import User +def _make_random_password(): + return get_random_string(10, allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789') + + class BaseCheckoutForm(forms.ModelForm): """ Needs the request and the shop object as keyword argument @@ -69,7 +74,7 @@ def save(self): email = self.cleaned_data.get("email") if not self.shop.user_is_authenticated(self.request.user): - password = User.objects.make_random_password() + password = _make_random_password() params = {"email": email, "password": password} if getattr(User, "USERNAME_FIELD", "username") == "username": params["username"] = email[:30] # FIXME @@ -263,7 +268,7 @@ def clean(self): data = super().clean() if not data.get("shipping_same_as_billing"): for f in self.REQUIRED_ADDRESS_FIELDS: - field = "shipping_%s" % f + field = f"shipping_{f}" if not data.get(field): self._errors[field] = self.error_class( [_("This field is required.")] diff --git a/plata/shop/ga_tracking.py b/plata/shop/ga_tracking.py index 8c7f48b2..e2efbc72 100644 --- a/plata/shop/ga_tracking.py +++ b/plata/shop/ga_tracking.py @@ -57,7 +57,7 @@ def on_order_paid(order, payment, request, **kwargs): transaction.tax = order.tax transaction.shipping = order.shipping transaction.city = order.billing_city.encode("utf8") - transaction.country = ("%s" % order.billing_country).encode("utf8") + transaction.country = (f"{order.billing_country}").encode() transaction.currency = order.currency for item in order.items.all(): i = Item() diff --git a/plata/shop/models.py b/plata/shop/models.py index 2e6fb1ec..279bba86 100644 --- a/plata/shop/models.py +++ b/plata/shop/models.py @@ -92,14 +92,12 @@ def addresses(self): Return a ``dict`` containing a billing and a shipping address, taking into account the value of the ``shipping_same_as_billing`` flag """ - billing = {f: getattr(self, "billing_%s" % f) for f in self.ADDRESS_FIELDS} + billing = {f: getattr(self, f"billing_{f}") for f in self.ADDRESS_FIELDS} if self.shipping_same_as_billing: shipping = billing else: - shipping = { - f: getattr(self, "shipping_%s" % f) for f in self.ADDRESS_FIELDS - } + shipping = {f: getattr(self, f"shipping_{f}") for f in self.ADDRESS_FIELDS} return {"billing": billing, "shipping": shipping} diff --git a/plata/shop/templates/_form_errors.html b/plata/shop/templates/_form_errors.html index 9153e4e4..1982e06c 100644 --- a/plata/shop/templates/_form_errors.html +++ b/plata/shop/templates/_form_errors.html @@ -1,11 +1,11 @@ {% load i18n %}
- {% trans "Please correct the following errors:" %} + {% translate "Please correct the following errors:" %}
    {% for form in forms %} {% if form.non_field_errors %} -
  • {% trans "Form errors" %}: {{ form.non_field_errors }}
  • +
  • {% translate "Form errors" %}: {{ form.non_field_errors }}
  • {% endif %} {% for field in form %} {% if field.errors %} @@ -16,12 +16,12 @@ {% for formset in formsets %} {% if formset.non_form_errors %} -
  • {% trans "Fieldset errors" %}: +
  • {% translate "Fieldset errors" %}: {{ formset.non_form_errors }}
  • {% endif %} {% for form in formset.forms %} {% if form.non_field_errors %} -
  • {% trans "Form errors" %}: {{ form.non_field_errors }}
  • +
  • {% translate "Form errors" %}: {{ form.non_field_errors }}
  • {% endif %} {% for field in form %} {% if field.errors %} diff --git a/plata/shop/templates/_pagination.html b/plata/shop/templates/_pagination.html index dff57cd5..c40b639c 100644 --- a/plata/shop/templates/_pagination.html +++ b/plata/shop/templates/_pagination.html @@ -16,7 +16,7 @@
    {{ page_obj.start_index }} - {{ page_obj.end_index }} / {{ paginator.count }}
    - {% trans "show all" %} + {% translate "show all" %}
diff --git a/plata/shop/templates/base.html b/plata/shop/templates/base.html index 42733812..8e8cff01 100644 --- a/plata/shop/templates/base.html +++ b/plata/shop/templates/base.html @@ -98,10 +98,10 @@ @@ -115,23 +115,23 @@ {% endif %} {% block content %} -{% endblock %} +{% endblock content %}
-{% trans "Go to cart" %} +{% translate "Go to cart" %}
-

{% trans "That's what we know about you:" %}

+

{% translate "That's what we know about you:" %}

- + - + - +
{% trans "User" %}{% translate "User" %} {{ user }}
{% trans "Contact" %}{% translate "Contact" %} {{ plata.contact }}
{% trans "Order" %}{% translate "Order" %} {{ plata.order }}, {{ plata.order.currency }} {{ plata.order.total|floatformat:2 }}
    @@ -141,10 +141,10 @@

    {% trans "That's what we know about you:" %}

{% if plata.order.id %} {% url "plata_reporting_invoice_pdf" plata.order.id as invoice_url %} - {% if invoice_url %}{% trans "Invoice" %}{% endif %} + {% if invoice_url %}{% translate "Invoice" %}{% endif %} {% endif %} {% url "plata_reporting_product_xls" as product_xls_url %} - {% if product_xls_url %}{% trans "Products" %}{% endif %} + {% if product_xls_url %}{% translate "Products" %}{% endif %}
diff --git a/plata/shop/templates/payment/ogone_form.html b/plata/shop/templates/payment/ogone_form.html index 0da419df..fb1b265b 100644 --- a/plata/shop/templates/payment/ogone_form.html +++ b/plata/shop/templates/payment/ogone_form.html @@ -3,9 +3,9 @@ {% load i18n %} {% block content %} -

{% trans "Payment" %}

+

{% translate "Payment" %}

-

{% trans "You will be forwarded to Ogone for payment now." %}

+

{% translate "You will be forwarded to Ogone for payment now." %}

{% block parameters %} @@ -24,8 +24,8 @@

{% trans "Payment" %}

-{% endblock %} - +{% endblock parameters %} +
-{% endblock %} +{% endblock content %} diff --git a/plata/shop/templates/payment/pagseguro_form.html b/plata/shop/templates/payment/pagseguro_form.html index 1d3adddc..99e87e38 100644 --- a/plata/shop/templates/payment/pagseguro_form.html +++ b/plata/shop/templates/payment/pagseguro_form.html @@ -2,9 +2,9 @@ {% load i18n %} {% block content %} -

{% trans "Payment" %}

+

{% translate "Payment" %}

-

{% trans "You will be forwarded to PagSeguro for payment now." %}

+

{% translate "You will be forwarded to PagSeguro for payment now." %}

@@ -33,7 +33,7 @@

{% trans "Payment" %}

- +
-{% endblock %} +{% endblock content %} diff --git a/plata/shop/templates/payment/paypal_form.html b/plata/shop/templates/payment/paypal_form.html index 8f93ee00..35d33c9a 100644 --- a/plata/shop/templates/payment/paypal_form.html +++ b/plata/shop/templates/payment/paypal_form.html @@ -3,9 +3,9 @@ {% load i18n %} {% block content %} -

{% trans "Payment" %}

+

{% translate "Payment" %}

-

{% trans "You will be forwarded to Paypal for payment now." %}

+

{% translate "You will be forwarded to Paypal for payment now." %}

{% block parameters %} @@ -59,8 +59,8 @@

{% trans "Payment" %}

- {% endblock %} - + {% endblock parameters %} +
-{% endblock %} +{% endblock content %} diff --git a/plata/shop/templates/payment/postfinance_form.html b/plata/shop/templates/payment/postfinance_form.html index 83250736..8458e92e 100644 --- a/plata/shop/templates/payment/postfinance_form.html +++ b/plata/shop/templates/payment/postfinance_form.html @@ -3,9 +3,9 @@ {% load i18n %} {% block content %} -

{% trans "Payment" %}

+

{% translate "Payment" %}

-

{% trans "You will be forwarded to Postfinance for payment now." %}

+

{% translate "You will be forwarded to Postfinance for payment now." %}

{% block parameters %} @@ -26,8 +26,8 @@

{% trans "Payment" %}

-{% endblock %} - +{% endblock parameters %} +
-{% endblock %} +{% endblock content %} diff --git a/plata/shop/templates/payment/stripe_form.html b/plata/shop/templates/payment/stripe_form.html index 15c4f681..4e50769d 100644 --- a/plata/shop/templates/payment/stripe_form.html +++ b/plata/shop/templates/payment/stripe_form.html @@ -1,11 +1,11 @@ {% extends base_template|default:"base.html" %} {% load i18n plata_tags %} -{% block title %}{% trans "Payment" %} - {{ block.super }}{% endblock %} +{% block title %}{% translate "Payment" %} - {{ block.super }}{% endblock %} {% block content %} {% if callback %} -{% trans "Thank you for your payment!" %} +{% translate "Thank you for your payment!" %} {% else %}
{% csrf_token %} @@ -13,7 +13,7 @@ {{ form.id }}