diff --git a/shop/admin/customer.py b/shop/admin/customer.py index 97f4ea90c..31a9b5a1f 100644 --- a/shop/admin/customer.py +++ b/shop/admin/customer.py @@ -46,7 +46,7 @@ def __init__(self, *args, **kwargs): initial = kwargs.get('initial', {}) instance = kwargs.get('instance') initial['email'] = instance.email or '' - super(CustomerChangeForm, self).__init__(initial=initial, *args, **kwargs) + super().__init__(initial=initial, *args, **kwargs) def clean_email(self): return self.cleaned_data.get('email').strip() @@ -88,7 +88,7 @@ class Media: js = ['shop/js/admin/customer.js'] def get_fieldsets(self, request, obj=None): - fieldsets = list(super(CustomerAdminBase, self).get_fieldsets(request, obj=obj)) + fieldsets = list(super().get_fieldsets(request, obj=obj)) if obj: fieldsets[0][1]['fields'] = ['username', 'recognized', 'password'] fieldsets[3][1]['fields'] = ['date_joined', 'last_login', 'last_access'] @@ -133,7 +133,7 @@ def is_unexpired(self, user): def save_related(self, request, form, formsets, change): if hasattr(form.instance, 'customer') and (form.instance.is_staff or form.instance.is_superuser): form.instance.customer.recognized = CustomerState.REGISTERED - super(CustomerAdminBase, self).save_related(request, form, formsets, change) + super().save_related(request, form, formsets, change) class CustomerProxy(get_user_model()): diff --git a/shop/admin/defaults/customer.py b/shop/admin/defaults/customer.py index 025c7c83a..f63f49d4c 100644 --- a/shop/admin/defaults/customer.py +++ b/shop/admin/defaults/customer.py @@ -34,7 +34,7 @@ class Media: inlines = [CustomerInlineAdmin] def get_list_display(self, request): - list_display = list(super(CustomerAdmin, self).get_list_display(request)) + list_display = list(super().get_list_display(request)) list_display.insert(1, 'salutation') return list_display diff --git a/shop/admin/defaults/order.py b/shop/admin/defaults/order.py index e53a21020..068421008 100644 --- a/shop/admin/defaults/order.py +++ b/shop/admin/defaults/order.py @@ -6,21 +6,21 @@ class OrderAdmin(BaseOrderAdmin): Admin class to be used for Order model :class:`shop.models.defaults.order` """ def get_fields(self, request, obj=None): - fields = list(super(OrderAdmin, self).get_fields(request, obj)) + fields = list(super().get_fields(request, obj)) fields.extend(['shipping_address_text', 'billing_address_text']) return fields def get_readonly_fields(self, request, obj=None): - readonly_fields = list(super(OrderAdmin, self).get_readonly_fields(request, obj)) + readonly_fields = list(super().get_readonly_fields(request, obj)) readonly_fields.extend(['shipping_address_text', 'billing_address_text']) return readonly_fields def get_search_fields(self, request): - search_fields = list(super(OrderAdmin, self).get_search_fields(request)) + search_fields = list(super().get_search_fields(request)) search_fields.extend(['number', 'shipping_address_text', 'billing_address_text']) return search_fields def get_inline_instances(self, request, obj=None): - inline_instances = list(super(OrderAdmin, self).get_inline_instances(request, obj)) + inline_instances = list(super().get_inline_instances(request, obj)) inline_instances.append(OrderPaymentInline(self.model, self.admin_site)) return inline_instances diff --git a/shop/admin/delivery.py b/shop/admin/delivery.py index 18aeb1eec..b5fe8b215 100644 --- a/shop/admin/delivery.py +++ b/shop/admin/delivery.py @@ -33,7 +33,7 @@ def __init__(self, *args, **kwargs): kwargs['initial'].update(deliver_quantity=deliver_quantity) else: deliver_quantity = None - super(OrderItemForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) if deliver_quantity == 0: self['deliver_quantity'].field.widget.attrs.update(readonly='readonly') @@ -46,7 +46,7 @@ def get_delivered(cls, instance): return aggr['delivered'] or 0 def clean(self): - cleaned_data = super(OrderItemForm, self).clean() + cleaned_data = super().clean() if cleaned_data.get('deliver_quantity') is not None: if cleaned_data['deliver_quantity'] < 0: raise ValidationError(_("Only a positive number of items can be delivered"), code='invalid') @@ -61,7 +61,7 @@ def has_changed(self): class OrderItemInlineDelivery(OrderItemInline): def get_fields(self, request, obj=None): - fields = list(super(OrderItemInlineDelivery, self).get_fields(request, obj)) + fields = list(super().get_fields(request, obj)) if obj: if obj.status == 'pick_goods' and obj.unfulfilled_items > 0: fields[1] += ('deliver_quantity', 'canceled',) @@ -70,7 +70,7 @@ def get_fields(self, request, obj=None): return fields def get_readonly_fields(self, request, obj=None): - readonly_fields = list(super(OrderItemInlineDelivery, self).get_readonly_fields(request, obj)) + readonly_fields = list(super().get_readonly_fields(request, obj)) if obj: if not (obj.status == 'pick_goods' and obj.unfulfilled_items > 0): readonly_fields.extend(['get_delivered', 'show_ready']) @@ -91,7 +91,7 @@ def get_formset(self, request, obj=None, **kwargs): form = type(str('OrderItemForm'), (OrderItemForm,), attrs) labels = {'canceled': _("Cancel this item")} kwargs.update(form=form, labels=labels) - formset = super(OrderItemInlineDelivery, self).get_formset(request, obj, **kwargs) + formset = super().get_formset(request, obj, **kwargs) return formset def get_delivered(self, obj=None): @@ -144,19 +144,19 @@ def get_max_num(self, request, obj=None, **kwargs): def get_fields(self, request, obj=None): assert obj is not None, "An Order object can not be added through the Django-Admin" - fields = list(super(DeliveryInline, self).get_fields(request, obj)) + fields = list(super().get_fields(request, obj)) if not obj.allow_partial_delivery: fields.remove('delivered_items') return fields def get_readonly_fields(self, request, obj=None): - readonly_fields = list(super(DeliveryInline, self).get_readonly_fields(request, obj)) + readonly_fields = list(super().get_readonly_fields(request, obj)) if not app_settings.SHOP_OVERRIDE_SHIPPING_METHOD or obj.status == 'ready_for_delivery': readonly_fields.append('shipping_method') return readonly_fields def get_formset(self, request, obj=None, **kwargs): - formset = super(DeliveryInline, self).get_formset(request, obj, **kwargs) + formset = super().get_formset(request, obj, **kwargs) if not app_settings.SHOP_OVERRIDE_SHIPPING_METHOD or obj.status == 'ready_for_delivery': # make readonly field optional formset.form.base_fields['shipping_method'].required = False @@ -195,7 +195,7 @@ def get_urls(self): self.admin_site.admin_view(self.render_delivery_note), name='print_delivery_note'), ] - my_urls.extend(super(DeliveryOrderAdminMixin, self).get_urls()) + my_urls.extend(super().get_urls()) return my_urls def render_delivery_note(self, request, delivery_pk=None): @@ -220,7 +220,7 @@ def get_inline_instances(self, request, obj=None): assert obj is not None, "An Order object can not be added through the Django-Admin" assert hasattr(obj, 'associate_with_delivery'), "Add 'shop.shipping.workflows.SimpleShippingWorkflowMixin' " \ "(or a class inheriting from thereof) to SHOP_ORDER_WORKFLOWS." - inline_instances = list(super(DeliveryOrderAdminMixin, self).get_inline_instances(request, obj)) + inline_instances = list(super().get_inline_instances(request, obj)) if obj.associate_with_delivery: if obj.allow_partial_delivery: # replace `OrderItemInline` by `OrderItemInlineDelivery` for that instance. @@ -232,7 +232,7 @@ def get_inline_instances(self, request, obj=None): return inline_instances def save_related(self, request, form, formsets, change): - super(DeliveryOrderAdminMixin, self).save_related(request, form, formsets, change) + super().save_related(request, form, formsets, change) if form.instance.status == 'pack_goods' and 'status' in form.changed_data: orderitem_formset = [fs for fs in formsets if issubclass(fs.model, OrderItemModel)][0] form.instance.update_or_create_delivery(orderitem_formset.cleaned_data) diff --git a/shop/admin/notification.py b/shop/admin/notification.py index 7900703c9..31d32b603 100644 --- a/shop/admin/notification.py +++ b/shop/admin/notification.py @@ -35,7 +35,7 @@ def __init__(self, *args, **kwargs): else: initial['notify_recipient'] = kwargs['instance'].notify.name kwargs.update(initial=initial) - super(NotificationForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.fields['transition_target'].widget.choices = self.get_transition_choices() self.fields['notify_recipient'].choices = self.get_recipient_choices() @@ -61,7 +61,7 @@ def get_recipient_choices(self): return choices def save(self, commit=True): - obj = super(NotificationForm, self).save(commit=commit) + obj = super().save(commit=commit) try: obj.recipient = get_user_model().objects.get(pk=self.cleaned_data['notify_recipient']) obj.notify = Notify.RECIPIENT diff --git a/shop/admin/order.py b/shop/admin/order.py index b6cd8bab6..c3816bd4d 100644 --- a/shop/admin/order.py +++ b/shop/admin/order.py @@ -28,7 +28,7 @@ def get_formset(self, request, obj=None, **kwargs): """ choices = [pm.get_choice() for pm in cart_modifiers_pool.get_payment_modifiers()] kwargs.update(widgets={'payment_method': widgets.Select(choices=choices)}) - formset = super(OrderPaymentInline, self).get_formset(request, obj, **kwargs) + formset = super().get_formset(request, obj, **kwargs) return formset def has_add_permission(self, request, obj=None): @@ -125,7 +125,7 @@ class BaseOrderAdmin(FSMTransitionMixin, admin.ModelAdmin): change_form_template = 'shop/admin/change_form.html' def __init__(self, *args, **kwargs): - super(BaseOrderAdmin, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.extra_template = select_template([ '{}/admin/order-extra.html'.format(app_settings.APP_LABEL), 'shop/admin/order-extra.html', @@ -171,7 +171,7 @@ def get_customer_link(self, obj): get_customer_link.short_description = pgettext_lazy('admin', "Customer") def get_search_fields(self, request): - search_fields = list(super(BaseOrderAdmin, self).get_search_fields(request)) + search_fields = list(super().get_search_fields(request)) search_fields.extend(['customer__user__email', 'customer__user__last_name']) try: # if CustomerModel contains a number field, let search for it @@ -182,7 +182,7 @@ def get_search_fields(self, request): return search_fields def get_form(self, request, obj=None, **kwargs): - ModelForm = super(BaseOrderAdmin, self).get_form(request, obj, **kwargs) + ModelForm = super().get_form(request, obj, **kwargs) if obj: # store the requested transition inside the instance, so that the model's `clean()` method can access it obj._fsm_requested_transition = self._get_requested_transition(request) @@ -191,7 +191,7 @@ def get_form(self, request, obj=None, **kwargs): def change_view(self, request, object_id, form_url='', extra_context=None): assert object_id, "An Order object can not be added through the Django-Admin" current_status = self.get_object(request, object_id).status - response = super(BaseOrderAdmin, self).change_view(request, object_id, form_url, extra_context) + response = super().change_view(request, object_id, form_url, extra_context) order = self.get_object(request, object_id) if current_status != order.status: transition_change_notification(order) @@ -204,12 +204,12 @@ class PrintInvoiceAdminMixin: methods for printing the the invoice. """ def get_fields(self, request, obj=None): - fields = list(super(PrintInvoiceAdminMixin, self).get_fields(request, obj)) + fields = list(super().get_fields(request, obj)) fields.append('print_out') return fields def get_readonly_fields(self, request, obj=None): - readonly_fields = list(super(PrintInvoiceAdminMixin, self).get_readonly_fields(request, obj)) + readonly_fields = list(super().get_readonly_fields(request, obj)) readonly_fields.append('print_out') return readonly_fields @@ -218,7 +218,7 @@ def get_urls(self): url(r'^(?P\d+)/print_invoice/$', self.admin_site.admin_view(self.render_invoice), name='print_invoice'), ] - my_urls.extend(super(PrintInvoiceAdminMixin, self).get_urls()) + my_urls.extend(super().get_urls()) return my_urls def _render_content(self, request, pk, template): diff --git a/shop/admin/product.py b/shop/admin/product.py index 2280fbc30..91ddb6922 100644 --- a/shop/admin/product.py +++ b/shop/admin/product.py @@ -48,19 +48,19 @@ class CMSPageAsCategoryMixin: pages when used as categories. """ def __init__(self, *args, **kwargs): - super(CMSPageAsCategoryMixin, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) if not hasattr(self.model, 'cms_pages'): raise ImproperlyConfigured("Product model requires a field named `cms_pages`") def get_fieldsets(self, request, obj=None): - fieldsets = list(super(CMSPageAsCategoryMixin, self).get_fieldsets(request, obj=obj)) + fieldsets = list(super().get_fieldsets(request, obj=obj)) fieldsets.append((_("Categories"), {'fields': ('cms_pages',)}),) return fieldsets def get_fields(self, request, obj=None): # In ``get_fieldsets()``, ``cms_pages`` is added, so remove it from ``fields`` to # avoid showing it twice. - fields = list(super(CMSPageAsCategoryMixin, self).get_fields(request, obj)) + fields = list(super().get_fields(request, obj)) try: fields.remove('cms_pages') except ValueError: @@ -79,7 +79,7 @@ def formfield_for_manytomany(self, db_field, request, **kwargs): required = not db_field.blank field = CategoryModelMultipleChoiceField(queryset=queryset, widget=widget, required=required) return field - return super(CMSPageAsCategoryMixin, self).formfield_for_manytomany(db_field, request, **kwargs) + return super().formfield_for_manytomany(db_field, request, **kwargs) def save_related(self, request, form, formsets, change): old_cms_pages = form.instance.cms_pages.all() @@ -96,7 +96,7 @@ def save_related(self, request, form, formsets, change): if page not in old_cms_pages: ProductPageModel.objects.create(product=form.instance, page=page) - return super(CMSPageAsCategoryMixin, self).save_related(request, form, formsets, change) + return super().save_related(request, form, formsets, change) class SearchProductIndexMixin: diff --git a/shop/cascade/auth.py b/shop/cascade/auth.py index aa3dec2db..e808c1739 100644 --- a/shop/cascade/auth.py +++ b/shop/cascade/auth.py @@ -55,7 +55,7 @@ class ShopAuthenticationPlugin(LinkPluginBase): @classmethod def get_identifier(cls, instance): - identifier = super(ShopAuthenticationPlugin, cls).get_identifier(instance) + identifier = super().get_identifier(instance) content = dict(ft[:2] for ft in AUTH_FORM_TYPES).get(instance.glossary.get('form_type'), _("unknown")) return format_html('{0}{1}', identifier, content) diff --git a/shop/cascade/breadcrumb.py b/shop/cascade/breadcrumb.py index 254007340..e45eccea5 100644 --- a/shop/cascade/breadcrumb.py +++ b/shop/cascade/breadcrumb.py @@ -56,6 +56,6 @@ def get_use_cache(self, context, instance, placeholder): app = apphook_pool.get_apphook(instance.page.application_urls) return app.cache_placeholders except (AttributeError, ImproperlyConfigured): - return super(BreadcrumbPlugin, self).get_use_cache(context, instance, placeholder) + return super().get_use_cache(context, instance, placeholder) plugin_pool.register_plugin(BreadcrumbPlugin) diff --git a/shop/cascade/catalog.py b/shop/cascade/catalog.py index 6ed7f99c7..d8516d752 100644 --- a/shop/cascade/catalog.py +++ b/shop/cascade/catalog.py @@ -104,7 +104,7 @@ def get_render_template(self, context, instance, placeholder): return select_template(templates) def render(self, context, instance, placeholder): - context = super(ShopAddToCartPlugin, self).render(context, instance, placeholder) + context = super().render(context, instance, placeholder) context['use_modal_dialog'] = bool(instance.glossary.get('use_modal_dialog', True)) return context diff --git a/shop/cascade/checkout.py b/shop/cascade/checkout.py index 2434ec45b..50f3e6e75 100644 --- a/shop/cascade/checkout.py +++ b/shop/cascade/checkout.py @@ -212,7 +212,7 @@ def get_form_data(self, context, instance, placeholder): @classmethod def get_identifier(cls, instance): - identifier = super(CheckoutAddressPlugin, cls).get_identifier(instance) + identifier = super().get_identifier(instance) address_form = instance.glossary.get('address_form') address_form = dict(cls.form.ADDRESS_CHOICES).get(address_form, '') return format_html(pgettext_lazy('get_identifier', "for {} {}"), address_form, identifier) @@ -332,7 +332,7 @@ def render(self, context, instance, placeholder): form_data = {'cart': cart, 'initial': dict(plugin_id=instance.pk, plugin_order=request._plugin_order)} bound_form = FormClass(**form_data) context[bound_form.form_name] = bound_form - super(AcceptConditionMixin, self).render(context, instance, placeholder) + super().render(context, instance, placeholder) accept_condition_form = context['accept_condition_form.plugin_{}'.format(instance.pk)] # transfer the stored HTML content into the widget's label accept_condition_form['accept'].field.label = mark_safe(context['body']) diff --git a/shop/cascade/processbar.py b/shop/cascade/processbar.py index 0cba972da..2e0de8f5e 100644 --- a/shop/cascade/processbar.py +++ b/shop/cascade/processbar.py @@ -35,7 +35,7 @@ class ProcessBarPlugin(TransparentWrapper, ShopPluginBase): @classmethod def get_identifier(cls, instance): - identifier = super(ProcessBarPlugin, cls).get_identifier(instance) + identifier = super().get_identifier(instance) num_cols = instance.get_children().count() content = ngettext_lazy('with {} page', 'with {} pages', num_cols).format(num_cols) return format_html('{0}{1}', identifier, content) @@ -56,7 +56,7 @@ def render(self, context, instance, placeholder): def save_model(self, request, obj, form, change): wanted_children = int(form.cleaned_data.get('num_children')) - super(ProcessBarPlugin, self).save_model(request, obj, form, change) + super().save_model(request, obj, form, change) self.extend_children(obj, wanted_children, ProcessStepPlugin) plugin_pool.register_plugin(ProcessBarPlugin) diff --git a/shop/deferred.py b/shop/deferred.py index 6d9f36394..36e7827d7 100644 --- a/shop/deferred.py +++ b/shop/deferred.py @@ -27,7 +27,7 @@ class OneToOneField(DeferredRelatedField): MaterializedField = models.OneToOneField def __init__(self, to, on_delete, **kwargs): - super(OneToOneField, self).__init__(to, on_delete=on_delete, **kwargs) + super().__init__(to, on_delete=on_delete, **kwargs) class ForeignKey(DeferredRelatedField): @@ -38,7 +38,7 @@ class ForeignKey(DeferredRelatedField): MaterializedField = models.ForeignKey def __init__(self, to, on_delete, **kwargs): - super(ForeignKey, self).__init__(to, on_delete=on_delete, **kwargs) + super().__init__(to, on_delete=on_delete, **kwargs) class ManyToManyField(DeferredRelatedField): @@ -49,7 +49,7 @@ class ManyToManyField(DeferredRelatedField): MaterializedField = models.ManyToManyField def __init__(self, to, **kwargs): - super(ManyToManyField, self).__init__(to, **kwargs) + super().__init__(to, **kwargs) through = kwargs.get('through') @@ -88,7 +88,7 @@ class Meta: if not hasattr(attrs['Meta'], 'app_label') and not getattr(attrs['Meta'], 'abstract', False): attrs['Meta'].app_label = Meta.app_label - Model = super(ForeignKeyBuilder, cls).__new__(cls, name, bases, attrs) + Model = super().__new__(cls, name, bases, attrs) if Model._meta.abstract: return Model @@ -219,7 +219,7 @@ class MaterializedModel(LazyObject): """ def __init__(self, base_model): self.__dict__['_base_model'] = base_model - super(MaterializedModel, self).__init__() + super().__init__() def _setup(self): self._wrapped = getattr(self._base_model, '_materialized_model') diff --git a/shop/exceptions.py b/shop/exceptions.py index 6705ad21d..de5eb869d 100644 --- a/shop/exceptions.py +++ b/shop/exceptions.py @@ -5,4 +5,4 @@ class ProductNotAvailable(Exception): def __init__(self, product): self.product = product msg = "Product {} isn't available anymore." - super(ProductNotAvailable, self).__init__(msg.format(product.product_code)) + super().__init__(msg.format(product.product_code)) diff --git a/shop/forms/auth.py b/shop/forms/auth.py index 62ea008f3..ce06d4ccb 100644 --- a/shop/forms/auth.py +++ b/shop/forms/auth.py @@ -62,10 +62,10 @@ def __init__(self, data=None, instance=None, *args, **kwargs): pwd_length = max(self.base_fields['password1'].min_length or 8, 8) password = get_user_model().objects.make_random_password(pwd_length) data['password1'] = data['password2'] = password - super(RegisterUserForm, self).__init__(data=data, instance=instance, *args, **kwargs) + super().__init__(data=data, instance=instance, *args, **kwargs) def clean(self): - cleaned_data = super(RegisterUserForm, self).clean() + cleaned_data = super().clean() password1 = cleaned_data.get('password1') password2 = cleaned_data.get('password2') if password1 and password2: @@ -82,7 +82,7 @@ def save(self, request=None, commit=True): self.instance.user.email = self.cleaned_data['email'] self.instance.user.set_password(self.cleaned_data['password1']) self.instance.recognize_as_registered(request, commit=False) - customer = super(RegisterUserForm, self).save(commit) + customer = super().save(commit) password = self.cleaned_data['password1'] if self.cleaned_data['preset_password']: self._send_password(request, customer.user, password) @@ -138,7 +138,7 @@ def save(self, request=None, commit=True): # set a usable password, otherwise the user later can not reset its password password = get_user_model().objects.make_random_password(length=30) self.instance.user.set_password(password) - return super(ContinueAsGuestForm, self).save(commit) + return super().save(commit) class PasswordResetRequestForm(PasswordResetForm): diff --git a/shop/forms/base.py b/shop/forms/base.py index 9d1712d85..ad4e551f1 100644 --- a/shop/forms/base.py +++ b/shop/forms/base.py @@ -21,14 +21,14 @@ def __init__(self, *args, **kwargs): kwargs.pop('cart', None) # cart object must be removed, otherwise underlying methods complain auto_name = self.form_name ## .replace('_form', '') kwargs.setdefault('auto_id', '{}-%s'.format(auto_name)) - super(DialogFormMixin, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) @classproperty def form_name(cls): return normalize_name(cls.__name__) def clean(self): - cleaned_data = dict(super(DialogFormMixin, self).clean()) + cleaned_data = dict(super().clean()) cleaned_data.pop('plugin_id', None) if cleaned_data.pop('plugin_order', None) is None: msg = "Field 'plugin_order' is a hidden but required field in each form inheriting from DialogFormMixin" diff --git a/shop/forms/checkout.py b/shop/forms/checkout.py index e528a8c25..5e1ffa216 100644 --- a/shop/forms/checkout.py +++ b/shop/forms/checkout.py @@ -28,7 +28,7 @@ def __init__(self, initial=None, instance=None, *args, **kwargs): initial = dict(initial) if initial else {} assert instance is not None initial.update(dict((f, getattr(instance, f)) for f in self.Meta.custom_fields)) - super(CustomerForm, self).__init__(initial=initial, instance=instance, *args, **kwargs) + super().__init__(initial=initial, instance=instance, *args, **kwargs) @property def media(self): @@ -37,7 +37,7 @@ def media(self): def save(self, commit=True): for f in self.Meta.custom_fields: setattr(self.instance, f, self.cleaned_data[f]) - return super(CustomerForm, self).save(commit) + return super().save(commit) @classmethod def form_factory(cls, request, data, cart): @@ -62,7 +62,7 @@ class Meta: def __init__(self, initial=None, instance=None, *args, **kwargs): if isinstance(instance, CustomerModel): instance = instance.user - super(GuestForm, self).__init__(initial=initial, instance=instance, *args, **kwargs) + super().__init__(initial=initial, instance=instance, *args, **kwargs) @classmethod def form_factory(cls, request, data, cart): @@ -103,7 +103,7 @@ def __init__(self, initial=None, instance=None, cart=None, *args, **kwargs): initial['use_primary_address'] = cart.shipping_address is None else: # address_type == billing initial['use_primary_address'] = cart.billing_address is None - super(AddressForm, self).__init__(initial=initial, instance=instance, *args, **kwargs) + super().__init__(initial=initial, instance=instance, *args, **kwargs) @property def media(self): @@ -195,14 +195,14 @@ def populate_siblings_summary(self): }) def full_clean(self): - super(AddressForm, self).full_clean() + super().full_clean() if self.is_bound and self['use_primary_address'].value(): # reset errors, since then the form is always regarded as valid self._errors = ErrorDict() def save(self, commit=True): if not self['use_primary_address'].value(): - return super(AddressForm, self).save(commit) + return super().save(commit) def get_response_data(self): return dict(self.data, siblings_summary=self.siblings_summary) @@ -211,13 +211,13 @@ def as_div(self): # Intentionally rendered without field `use_primary_address`, this must be added # on top of the form template manually self.fields.pop('use_primary_address', None) - return super(AddressForm, self).as_div() + return super().as_div() def as_text(self): bound_field = self['use_primary_address'] if bound_field.value(): return bound_field.field.widget.choice_label - return super(AddressForm, self).as_text() + return super().as_text() class ShippingAddressForm(AddressForm): @@ -231,7 +231,7 @@ class Meta(AddressForm.Meta): } def __init__(self, *args, **kwargs): - super(ShippingAddressForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.fields['use_primary_address'].label = _("Use billing address for shipping") self.fields['use_primary_address'].widget.choice_label = self.fields['use_primary_address'].label # Django < 1.11 @@ -251,7 +251,7 @@ class Meta(AddressForm.Meta): model = BillingAddressModel def __init__(self, *args, **kwargs): - super(BillingAddressForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.fields['use_primary_address'].label = _("Use shipping address for billing") self.fields['use_primary_address'].widget.choice_label = self.fields['use_primary_address'].label # Django < 1.11 @@ -281,7 +281,7 @@ def __init__(self, *args, **kwargs): kwargs['initial']['payment_modifier'] = choices[0][0] except KeyError: pass - super(PaymentMethodForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def has_choices(self): return len(self.base_fields['payment_modifier'].choices) > 0 @@ -314,7 +314,7 @@ def __init__(self, *args, **kwargs): kwargs['initial']['shipping_modifier'] = choices[0][0] except KeyError: pass - super(ShippingMethodForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def has_choices(self): return len(self.base_fields['shipping_modifier'].choices) > 0 @@ -357,8 +357,7 @@ def __init__(self, data=None, initial=None, *args, **kwargs): plugin_id = data and data.get('plugin_id') or initial and initial.get('plugin_id') or 'none' scope_prefix = '{0}.plugin_{1}'.format(self.scope_prefix, plugin_id) self.form_name = '{0}.plugin_{1}'.format(self.form_name, plugin_id) - super(AcceptConditionForm, self).__init__(data=data, initial=initial, - scope_prefix=scope_prefix, *args, **kwargs) + super().__init__(data=data, initial=initial, scope_prefix=scope_prefix, *args, **kwargs) @classmethod def form_factory(cls, request, data, cart): diff --git a/shop/forms/wizards.py b/shop/forms/wizards.py index 87f4a671b..9af34f0d3 100644 --- a/shop/forms/wizards.py +++ b/shop/forms/wizards.py @@ -22,7 +22,7 @@ class Meta: @property def media(self): minimized = '' if settings.DEBUG else '.min' - media = super(CommodityWizardForm, self).media + media = super().media css = {'all': ['admin/css/base.css', 'admin/css/forms.css']} media.add_css(css) media._js = [ @@ -46,6 +46,6 @@ def save(self, commit=True): self.instance.slug = self.cleaned_data['slug'] max_order = Commodity.objects.aggregate(max=Max('order'))['max'] self.instance.order = max_order + 1 if max_order else 1 - commodity = super(CommodityWizardForm, self).save(commit) + commodity = super().save(commit) ProductPageModel.objects.create(product=commodity, page=self.page.get_public_object()) return commodity diff --git a/shop/models/address.py b/shop/models/address.py index 27f91b765..0de54f372 100644 --- a/shop/models/address.py +++ b/shop/models/address.py @@ -330,10 +330,10 @@ def __init__(self, *args, **kwargs): 'choices': ISO_3166_CODES, } defaults.update(kwargs) - super(CountryField, self).__init__(*args, **defaults) + super().__init__(*args, **defaults) def deconstruct(self): - name, path, args, kwargs = super(CountryField, self).deconstruct() + name, path, args, kwargs = super().deconstruct() if kwargs['max_length'] == 3: kwargs.pop('max_length') if kwargs['choices'] == ISO_3166_CODES: diff --git a/shop/models/cart.py b/shop/models/cart.py index 3a9bb4b47..b6f81423c 100644 --- a/shop/models/cart.py +++ b/shop/models/cart.py @@ -102,7 +102,7 @@ class Meta: @classmethod def check(cls, **kwargs): - errors = super(BaseCartItem, cls).check(**kwargs) + errors = super().check(**kwargs) allowed_types = ['IntegerField', 'SmallIntegerField', 'PositiveIntegerField', 'PositiveSmallIntegerField', 'DecimalField', 'FloatField'] for field in cls._meta.fields: @@ -120,12 +120,12 @@ def __init__(self, *args, **kwargs): # reduce the given fields to what the model actually can consume all_field_names = [field.name for field in self._meta.get_fields(include_parents=True)] model_kwargs = {k: v for k, v in kwargs.items() if k in all_field_names} - super(BaseCartItem, self).__init__(*args, **model_kwargs) + super().__init__(*args, **model_kwargs) self.extra_rows = OrderedDict() self._dirty = True def save(self, *args, **kwargs): - super(BaseCartItem, self).save(*args, **kwargs) + super().save(*args, **kwargs) self.cart.save(update_fields=['updated_at']) self._dirty = True @@ -202,7 +202,7 @@ class Meta: verbose_name_plural = _("Shopping Carts") def __init__(self, *args, **kwargs): - super(BaseCart, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) # That will hold things like tax totals or total discount self.extra_rows = OrderedDict() self._cached_cart_items = None @@ -210,7 +210,7 @@ def __init__(self, *args, **kwargs): def save(self, force_update=False, *args, **kwargs): if self.pk or force_update is False: - super(BaseCart, self).save(force_update=force_update, *args, **kwargs) + super().save(force_update=force_update, *args, **kwargs) self._dirty = True def update(self, request, raise_exception=False): diff --git a/shop/models/customer.py b/shop/models/customer.py index 5261540c1..a508b1069 100644 --- a/shop/models/customer.py +++ b/shop/models/customer.py @@ -57,7 +57,7 @@ def _filter_or_exclude(self, negate, *args, **kwargs): raise fdne except Exception as othex: raise othex - result = super(CustomerQuerySet, self)._filter_or_exclude(negate, *args, **lookup_kwargs) + result = super()._filter_or_exclude(negate, *args, **lookup_kwargs) return result @@ -115,7 +115,7 @@ def get_queryset(self): def create(self, *args, **kwargs): if 'user' in kwargs and kwargs['user'].is_authenticated: kwargs.setdefault('recognized', CustomerState.REGISTERED) - customer = super(CustomerManager, self).create(*args, **kwargs) + customer = super().create(*args, **kwargs) return customer def _get_visiting_user(self, session_key): @@ -356,12 +356,12 @@ def get_number(self): def save(self, **kwargs): if 'update_fields' not in kwargs: self.user.save(using=kwargs.get('using', DEFAULT_DB_ALIAS)) - super(BaseCustomer, self).save(**kwargs) + super().save(**kwargs) def delete(self, *args, **kwargs): if self.user.is_active and self.recognized is CustomerState.UNRECOGNIZED: # invalid state of customer, keep the referred User - super(BaseCustomer, self).delete(*args, **kwargs) + super().delete(*args, **kwargs) else: # also delete self through cascading self.user.delete(*args, **kwargs) diff --git a/shop/models/defaults/order.py b/shop/models/defaults/order.py index 555a7a2a6..54c809d69 100644 --- a/shop/models/defaults/order.py +++ b/shop/models/defaults/order.py @@ -78,7 +78,7 @@ def secret(self): return self.token def get_absolute_url(self): - url = super(Order, self).get_absolute_url() + url = super().get_absolute_url() if self.token: if not url.endswith('/'): url += '/' @@ -94,4 +94,4 @@ def populate_from_cart(self, cart, request): self.shipping_address_text = self.billing_address_text if not self.billing_address_text: self.billing_address_text = self.shipping_address_text - super(Order, self).populate_from_cart(cart, request) + super().populate_from_cart(cart, request) diff --git a/shop/models/delivery.py b/shop/models/delivery.py index b3b2fad11..04205fb63 100644 --- a/shop/models/delivery.py +++ b/shop/models/delivery.py @@ -54,7 +54,7 @@ def __str__(self): @classmethod def check(cls, **kwargs): - errors = super(BaseDelivery, cls).check(**kwargs) + errors = super().check(**kwargs) for field in OrderItemModel._meta.fields: if field.attname == 'canceled' and field.get_internal_type() == 'BooleanField': break @@ -109,7 +109,7 @@ class Meta: @classmethod def check(cls, **kwargs): - errors = super(BaseDeliveryItem, cls).check(**kwargs) + errors = super().check(**kwargs) for order_field in OrderItemModel._meta.fields: if order_field.attname == 'quantity': break diff --git a/shop/models/fields.py b/shop/models/fields.py index 328564889..6248faf7a 100644 --- a/shop/models/fields.py +++ b/shop/models/fields.py @@ -19,10 +19,10 @@ class JSONField(_JSONField): def __init__(self, *args, **kwargs): kwargs.update({'default': dict}) - super(JSONField, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def deconstruct(self): - name, path, args, kwargs = super(JSONField, self).deconstruct() + name, path, args, kwargs = super().deconstruct() del kwargs['default'] return name, path, args, kwargs @@ -34,7 +34,7 @@ def __call__(cls, value, *args, **kwargs): value = cls.__members__[value] except KeyError: pass # let the super method complain - return super(ChoiceEnumMeta, cls).__call__(value, *args, **kwargs) + return super().__call__(value, *args, **kwargs) def __new__(metacls, classname, bases, classdict): labels = {} @@ -51,7 +51,7 @@ def __new__(metacls, classname, bases, classdict): # Use dict.__setitem__() to suppress defenses against # double assignment in enum's classdict dict.__setitem__(classdict, key, val) - cls = super(ChoiceEnumMeta, metacls).__new__(metacls, classname, bases, classdict) + cls = super().__new__(metacls, classname, bases, classdict) for key, label in labels.items(): getattr(cls, key).label = label return cls @@ -99,10 +99,10 @@ def __init__(self, *args, **kwargs): raise ValueError("enum_type must be a subclass of `ChoiceEnum`.") kwargs.update(choices=self.enum_type.choices) kwargs.setdefault('default', self.enum_type.default) - super(ChoiceEnumField, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def deconstruct(self): - name, path, args, kwargs = super(ChoiceEnumField, self).deconstruct() + name, path, args, kwargs = super().deconstruct() if 'choices' in kwargs: del kwargs['choices'] if kwargs['default'] is self.enum_type.default: diff --git a/shop/models/inventory.py b/shop/models/inventory.py index ae063b8b0..518435672 100644 --- a/shop/models/inventory.py +++ b/shop/models/inventory.py @@ -69,7 +69,7 @@ def managed_availability(self): @classmethod def check(cls, **kwargs): - errors = super(AvailableProductMixin, cls).check(**kwargs) + errors = super().check(**kwargs) for rel in cls._meta.related_objects: if rel.name == 'inventory_set': if rel.get_internal_type() != 'ForeignKey': @@ -123,7 +123,7 @@ class Meta: def check(cls, **kwargs): from shop.models.cart import CartItemModel - errors = super(BaseInventory, cls).check(**kwargs) + errors = super().check(**kwargs) for cart_field in CartItemModel._meta.fields: if cart_field.attname == 'quantity': break diff --git a/shop/models/order.py b/shop/models/order.py index 55f42952b..6196e2896 100644 --- a/shop/models/order.py +++ b/shop/models/order.py @@ -39,7 +39,7 @@ def _filter_or_exclude(self, negate, *args, **kwargs): lookup_kwargs.update({key + lookup_type: lookup}) else: lookup_kwargs.update({key: lookup}) - return super(OrderQuerySet, self)._filter_or_exclude(negate, *args, **lookup_kwargs) + return super()._filter_or_exclude(negate, *args, **lookup_kwargs) class OrderManager(models.Manager): @@ -121,7 +121,7 @@ def __new__(cls, name, bases, attrs): raise ImproperlyConfigured(msg.format(b.__name__, ', '.join(TRANSITION_TARGETS.keys()))) attrs['_transition_targets'].update(TRANSITION_TARGETS) attrs['_auto_transitions'].update(cls.add_to_auto_transitions(b)) - Model = super(WorkflowMixinMetaclass, cls).__new__(cls, name, bases, attrs) + Model = super().__new__(cls, name, bases, attrs) return Model @classmethod @@ -207,7 +207,7 @@ class Meta: abstract = True def __init__(self, *args, **kwargs): - super(BaseOrder, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.logger = logging.getLogger('shop.order') def __str__(self): @@ -335,7 +335,7 @@ def save(self, with_notification=False, **kwargs): # round the total to the given decimal_places self._subtotal = BaseOrder.round_amount(self._subtotal) self._total = BaseOrder.round_amount(self._total) - super(BaseOrder, self).save(**kwargs) + super().save(**kwargs) if with_notification: transition_change_notification(self) @@ -514,7 +514,7 @@ def __str__(self): @classmethod def check(cls, **kwargs): - errors = super(BaseOrderItem, cls).check(**kwargs) + errors = super().check(**kwargs) for cart_field in CartItemModel._meta.fields: if cart_field.attname == 'quantity': break @@ -568,6 +568,6 @@ def save(self, *args, **kwargs): """ self._unit_price = BaseOrder.round_amount(self._unit_price) self._line_total = BaseOrder.round_amount(self._line_total) - super(BaseOrderItem, self).save(*args, **kwargs) + super().save(*args, **kwargs) OrderItemModel = deferred.MaterializedModel(BaseOrderItem) diff --git a/shop/models/product.py b/shop/models/product.py index 70d09c8dd..c154027e9 100644 --- a/shop/models/product.py +++ b/shop/models/product.py @@ -93,7 +93,7 @@ def managed_availability(self): def check(cls, **kwargs): from shop.models.cart import CartItemModel - errors = super(AvailableProductMixin, cls).check(**kwargs) + errors = super().check(**kwargs) for cart_field in CartItemModel._meta.fields: if cart_field.attname == 'quantity': break @@ -124,7 +124,7 @@ def get_availability(self, request, **kwargs): """ from shop.models.cart import CartItemModel - availability = super(BaseReserveProductMixin, self).get_availability(request, **kwargs) + availability = super().get_availability(request, **kwargs) cart_items = CartItemModel.objects.filter(product=self).values('quantity') availability.quantity -= cart_items.aggregate(sum=Coalesce(Sum('quantity'), 0))['sum'] return availability @@ -338,7 +338,7 @@ def check(cls, **kwargs): Internal method to check consistency of Product model declaration on bootstrapping application. """ - errors = super(BaseProduct, cls).check(**kwargs) + errors = super().check(**kwargs) try: cls.product_name except AttributeError: diff --git a/shop/modifiers/defaults.py b/shop/modifiers/defaults.py index fd12937a2..d3595c4e7 100644 --- a/shop/modifiers/defaults.py +++ b/shop/modifiers/defaults.py @@ -31,19 +31,19 @@ def pre_process_cart_item(self, cart, cart_item, request, raise_exception=False) "{quantity} which is the maximum, currently available in stock.").\ format(product_name=cart_item.product.product_name, quantity=availability.quantity) messages.info(request, message, title=_("Verify Quantity"), delay=5) - return super(DefaultCartModifier, self).pre_process_cart_item(cart, cart_item, request, raise_exception) + return super().pre_process_cart_item(cart, cart_item, request, raise_exception) def process_cart_item(self, cart_item, request): cart_item.unit_price = cart_item.product.get_price(request) cart_item.line_total = cart_item.unit_price * cart_item.quantity - return super(DefaultCartModifier, self).process_cart_item(cart_item, request) + return super().process_cart_item(cart_item, request) def process_cart(self, cart, request): if not isinstance(cart.subtotal, AbstractMoney): # if we don't know the currency, use the default cart.subtotal = Money(cart.subtotal) cart.total = cart.subtotal - return super(DefaultCartModifier, self).process_cart(cart, request) + return super().process_cart(cart, request) class WeightedCartModifier(BaseCartModifier): @@ -59,8 +59,8 @@ class WeightedCartModifier(BaseCartModifier): def pre_process_cart(self, cart, request, raise_exception=False): cart.weight = self.initial_weight - return super(WeightedCartModifier, self).pre_process_cart(cart, request, raise_exception) + return super().pre_process_cart(cart, request, raise_exception) def pre_process_cart_item(self, cart, cart_item, request, raise_exception=False): cart.weight += Decimal(cart_item.product.get_weight() * cart_item.quantity) - return super(WeightedCartModifier, self).pre_process_cart_item(cart_item, request, raise_exception) + return super().pre_process_cart_item(cart_item, request, raise_exception) diff --git a/shop/money/fields.py b/shop/money/fields.py index 5a18f2ed2..eebf4b530 100644 --- a/shop/money/fields.py +++ b/shop/money/fields.py @@ -22,10 +22,10 @@ def __init__(self, attrs=None): defaults.update(attrs) except (KeyError, TypeError): raise ValueError("MoneyFieldWidget must be instantiated with a currency_code.") - super(MoneyFieldWidget, self).__init__(defaults) + super().__init__(defaults) def render(self, name, value, attrs=None, renderer=None): - input_field = super(MoneyFieldWidget, self).render(name, value, attrs, renderer) + input_field = super().render(name, value, attrs, renderer) return format_html('{} {}', input_field, self.currency_code) @@ -42,7 +42,7 @@ def __init__(self, money_class=None, **kwargs): self.Money = money_class if 'widget' not in kwargs: kwargs['widget'] = MoneyFieldWidget(attrs={'currency_code': money_class.currency}) - super(MoneyFormField, self).__init__(**kwargs) + super().__init__(**kwargs) def prepare_value(self, value): if isinstance(value, AbstractMoney): @@ -50,13 +50,13 @@ def prepare_value(self, value): return value def to_python(self, value): - value = super(MoneyFormField, self).to_python(value) + value = super().to_python(value) return self.Money(value) def validate(self, value): if value.currency != self.Money.currency: raise ValidationError("Can not convert different Money types.") - super(MoneyFormField, self).validate(Decimal(value)) + super().validate(Decimal(value)) return value @@ -75,7 +75,7 @@ def __init__(self, *args, **kwargs): 'decimal_places': CURRENCIES[self.currency_code][1], } defaults.update(kwargs) - super(MoneyField, self).__init__(*args, **defaults) + super().__init__(*args, **defaults) def deconstruct(self): name, path, args, kwargs = super(MoneyField, self).deconstruct() @@ -90,13 +90,13 @@ def to_python(self, value): return value if value is None: return self.Money('NaN') - value = super(MoneyField, self).to_python(value) + value = super().to_python(value) return self.Money(value) def get_prep_value(self, value): # force to type Decimal by using grandparent super value = super(models.DecimalField, self).get_prep_value(value) - return super(MoneyField, self).to_python(value) + return super().to_python(value) def from_db_value(self, value, expression, connection): if value is None: @@ -108,7 +108,7 @@ def from_db_value(self, value, expression, connection): def get_db_prep_save(self, value, connection): if isinstance(value, Decimal) and value.is_nan(): return None - return super(MoneyField, self).get_db_prep_save(value, connection) + return super().get_db_prep_save(value, connection) def get_prep_lookup(self, lookup_type, value): if isinstance(value, AbstractMoney): @@ -116,7 +116,7 @@ def get_prep_lookup(self, lookup_type, value): msg = "This field stores money in {}, but the lookup amount is in {}" raise ValueError(msg.format(value.get_currency(), self.Money.get_currency())) value = value.as_decimal() - result = super(MoneyField, self).get_prep_lookup(lookup_type, value) + result = super().get_prep_lookup(lookup_type, value) return result def value_to_string(self, obj): @@ -129,5 +129,5 @@ def formfield(self, **kwargs): widget = MoneyFieldWidget(attrs={'currency_code': self.Money.currency}) defaults = {'form_class': MoneyFormField, 'widget': widget, 'money_class': self.Money} defaults.update(**kwargs) - formfield = super(MoneyField, self).formfield(**defaults) + formfield = super().formfield(**defaults) return formfield diff --git a/shop/money/serializers.py b/shop/money/serializers.py index c2f8b9a18..3defdc3c0 100644 --- a/shop/money/serializers.py +++ b/shop/money/serializers.py @@ -17,7 +17,7 @@ class JSONEncoder(DjangoJSONEncoder): def default(self, obj): if isinstance(obj, AbstractMoney): return float(obj) - return super(JSONEncoder, self).default(obj) + return super().default(obj) class Serializer(DjangoSerializer): diff --git a/shop/patches.py b/shop/patches.py index 5b6332fec..c8cd0775b 100644 --- a/shop/patches.py +++ b/shop/patches.py @@ -9,6 +9,6 @@ class PageAttribute(BrokenPageAttribute): """ def get_value_for_context(self, context, **kwargs): try: - return super(PageAttribute, self).get_value_for_context(context, **kwargs) + return super().get_value_for_context(context, **kwargs) except Page.DoesNotExist: return '' diff --git a/shop/payment/modifiers.py b/shop/payment/modifiers.py index 6525e4225..d5e206d2b 100644 --- a/shop/payment/modifiers.py +++ b/shop/payment/modifiers.py @@ -21,7 +21,7 @@ class PaymentModifier(BaseCartModifier): def __init__(self): assert isinstance(getattr(self, 'payment_provider', None), PaymentProvider), \ "Each Payment modifier class requires a Payment Provider" - super(PaymentModifier, self).__init__() + super().__init__() @property def identifier(self): diff --git a/shop/payment/providers.py b/shop/payment/providers.py index 663472028..27b36d7a7 100644 --- a/shop/payment/providers.py +++ b/shop/payment/providers.py @@ -44,7 +44,7 @@ def __init__(self): getattr(OrderModel, 'awaiting_payment', None)))): msg = "Missing methods in Order model. Add 'shop.payment.workflows.ManualPaymentWorkflowMixin' to SHOP_ORDER_WORKFLOWS." raise ImproperlyConfigured(msg) - super(ForwardFundPayment, self).__init__() + super().__init__() def get_payment_request(self, cart, request): order = OrderModel.objects.create_from_cart(cart, request) diff --git a/shop/payment/workflows.py b/shop/payment/workflows.py index b5914a7a5..8a46dea3e 100644 --- a/shop/payment/workflows.py +++ b/shop/payment/workflows.py @@ -22,7 +22,7 @@ def __init__(self, *args, **kwargs): if not isinstance(self, BaseOrder): raise ImproperlyConfigured("class 'ManualPaymentWorkflowMixin' is not of type 'BaseOrder'") CancelOrderWorkflowMixin.CANCELABLE_SOURCES.update(self._manual_payment_transitions) - super(ManualPaymentWorkflowMixin, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) @transition(field='status', source=['created'], target='no_payment_required') def no_payment_required(self): @@ -81,7 +81,7 @@ class CancelOrderWorkflowMixin: } def cancelable(self): - return super(CancelOrderWorkflowMixin, self).cancelable() or self.status in self.CANCELABLE_SOURCES + return super().cancelable() or self.status in self.CANCELABLE_SOURCES @transition(field='status', target=RETURN_VALUE(*TRANSITION_TARGETS.keys()), conditions=[cancelable], custom=dict(admin=True, button_name=_("Cancel Order"))) diff --git a/shop/rest/fields.py b/shop/rest/fields.py index 3d922c90a..c633a2657 100644 --- a/shop/rest/fields.py +++ b/shop/rest/fields.py @@ -18,7 +18,7 @@ class JSONSerializerField(serializers.Field): Serializer field which transparently bypasses its object instead of serializing/deserializing. """ def __init__(self, encoder=None, **kwargs): - super(JSONSerializerField, self).__init__(**kwargs) + super().__init__(**kwargs) def to_representation(self, obj): return obj diff --git a/shop/rest/money.py b/shop/rest/money.py index fdcf3b4a9..5db57d8bb 100644 --- a/shop/rest/money.py +++ b/shop/rest/money.py @@ -10,7 +10,7 @@ class JSONEncoder(encoders.JSONEncoder): def default(self, obj): if isinstance(obj, AbstractMoney): return '{:f}'.format(obj) - return super(JSONEncoder, self).default(obj) + return super().default(obj) class JSONRenderer(renderers.JSONRenderer): @@ -22,7 +22,7 @@ class MoneyField(serializers.Field): def __init__(self, *args, **kwargs): kwargs.update(read_only=True) - super(MoneyField, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def to_representation(self, obj): return '{:f}'.format(obj) diff --git a/shop/serializers/bases.py b/shop/serializers/bases.py index 69e0d556a..4ea60d14b 100644 --- a/shop/serializers/bases.py +++ b/shop/serializers/bases.py @@ -45,7 +45,7 @@ class Meta: def __init__(self, *args, **kwargs): kwargs.setdefault('label', 'catalog') - super(ProductSerializer, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def get_price(self, product): price = product.get_price(self.context['request']) diff --git a/shop/serializers/cart.py b/shop/serializers/cart.py index 645ad6909..b145dea96 100644 --- a/shop/serializers/cart.py +++ b/shop/serializers/cart.py @@ -48,7 +48,7 @@ def create(self, validated_data): def to_representation(self, cart_item): cart_item.update(self.context['request']) - representation = super(BaseItemSerializer, self).to_representation(cart_item) + representation = super().to_representation(cart_item) return representation def validate_product(self, product): @@ -70,7 +70,7 @@ class Meta(BaseItemSerializer.Meta): def create(self, validated_data): validated_data['cart'] = CartModel.objects.get_or_create_from_request(self.context['request']) - return super(CartItemSerializer, self).create(validated_data) + return super().create(validated_data) class WatchItemSerializer(BaseItemSerializer): @@ -80,7 +80,7 @@ class Meta(BaseItemSerializer.Meta): def create(self, validated_data): cart = CartModel.objects.get_or_create_from_request(self.context['request']) validated_data.update(cart=cart, quantity=0) - return super(WatchItemSerializer, self).create(validated_data) + return super().create(validated_data) class CartItems(ChoiceEnum): @@ -100,7 +100,7 @@ class Meta: def to_representation(self, cart): cart.update(self.context['request']) - representation = super(BaseCartSerializer, self).to_representation(cart) + representation = super().to_representation(cart) if self.with_items: items = self.represent_items(cart) representation.update(items=items) @@ -119,7 +119,7 @@ class Meta(BaseCartSerializer.Meta): def __init__(self, *args, **kwargs): self.with_items = kwargs.pop('with_items', CartItems.without) - super(CartSerializer, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def represent_items(self, cart): if self.with_items == CartItems.unsorted: @@ -138,7 +138,7 @@ class Meta(BaseCartSerializer.Meta): def __init__(self, *args, **kwargs): self.with_items = kwargs.pop('with_items', CartItems.arranged) - super(WatchSerializer, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def represent_items(self, cart): if self.with_items == CartItems.unsorted: diff --git a/shop/serializers/catalog.py b/shop/serializers/catalog.py index b02a0b66f..ad2624e90 100644 --- a/shop/serializers/catalog.py +++ b/shop/serializers/catalog.py @@ -72,7 +72,7 @@ class ValueRelatedField(serializers.RelatedField): def __init__(self, *args, **kwargs): self.model = kwargs.pop('model') self.related_field_name = kwargs.pop('field_name', 'name') - super(ValueRelatedField, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def get_queryset(self): return self.model.objects.all() diff --git a/shop/serializers/checkout.py b/shop/serializers/checkout.py index 016735854..5c495dfb0 100644 --- a/shop/serializers/checkout.py +++ b/shop/serializers/checkout.py @@ -11,7 +11,7 @@ def __init__(self, form_class_name, **kwargs): except ImportError: msg = "Can not import Form class. Please check your settings directive SHOP_CASCADE_FORMS['{}']." raise ImproperlyConfigured(msg.format(form_class_name)) - super(SerializeFormAsTextField, self).__init__(**kwargs) + super().__init__(**kwargs) def to_representation(self, value): method = getattr(self.parent, self.method_name) diff --git a/shop/serializers/defaults/catalog.py b/shop/serializers/defaults/catalog.py index b626326ae..749815814 100644 --- a/shop/serializers/defaults/catalog.py +++ b/shop/serializers/defaults/catalog.py @@ -42,12 +42,12 @@ def __init__(self, instance=None, data=empty, **kwargs): else: quantity = self.fields['quantity'].default instance.setdefault('quantity', quantity) - super(AddToCartSerializer, self).__init__(instance, data, context=context) + super().__init__(instance, data, context=context) else: - super(AddToCartSerializer, self).__init__(instance, data, **kwargs) + super().__init__(instance, data, **kwargs) def to_representation(self, instance): - data = super(AddToCartSerializer, self).to_representation(instance) + data = super().to_representation(instance) try: data['quantity'] = self._validated_data['quantity'] except AttributeError: diff --git a/shop/serializers/delivery.py b/shop/serializers/delivery.py index f2424dd7f..70f9d64a6 100644 --- a/shop/serializers/delivery.py +++ b/shop/serializers/delivery.py @@ -12,7 +12,7 @@ class Meta: def to_representation(self, instance): data = app_settings.ORDER_ITEM_SERIALIZER(instance.item, context=self.context).data data['ordered_quantity'] = data.pop('quantity', None) - data.update(super(DeliveryItemSerializer, self).to_representation(instance)) + data.update(super().to_representation(instance)) return data diff --git a/shop/shipping/modifiers.py b/shop/shipping/modifiers.py index aea71529d..e2477c486 100644 --- a/shop/shipping/modifiers.py +++ b/shop/shipping/modifiers.py @@ -80,4 +80,4 @@ def get_choice(self): def ship_the_goods(self, delivery): if not delivery.shipping_id: delivery.shipping_id = str(delivery.id) - super(SelfCollectionModifier, self).ship_the_goods(delivery) + super().ship_the_goods(delivery) diff --git a/shop/templatetags/shop_search_tags.py b/shop/templatetags/shop_search_tags.py index cc4f007c7..b00e84ab5 100644 --- a/shop/templatetags/shop_search_tags.py +++ b/shop/templatetags/shop_search_tags.py @@ -15,7 +15,7 @@ class EmulateHttpRequest(HttpRequest): Use this class to emulate a HttpRequest object. """ def __init__(self, language_code=None): - super(EmulateHttpRequest, self).__init__() + super().__init__() self.environ = {} self.method = 'GET' if language_code: diff --git a/shop/transition.py b/shop/transition.py index 81437c32c..91d97d6af 100644 --- a/shop/transition.py +++ b/shop/transition.py @@ -19,7 +19,7 @@ class EmulateHttpRequest(HttpRequest): asynchronously, for instance when an email must be generated out of an Order object. """ def __init__(self, customer, stored_request): - super(EmulateHttpRequest, self).__init__() + super().__init__() parsedurl = urlparse(stored_request.get('absolute_base_uri')) self.path = self.path_info = parsedurl.path self.environ = {} diff --git a/shop/views/address.py b/shop/views/address.py index ca460a999..3d76a0490 100644 --- a/shop/views/address.py +++ b/shop/views/address.py @@ -20,7 +20,7 @@ class AddressEditView(GenericAPIView): form_class = None # must be overridde def __init__(self, **kwargs): - super(AddressEditView, self).__init__(**kwargs) + super().__init__(**kwargs) self.visible_fields = [f.name for f in self.form_class().visible_fields()] def get(self, request, priority=None, *args, **kwargs): diff --git a/shop/views/auth.py b/shop/views/auth.py index a5da87af0..17fc983c1 100644 --- a/shop/views/auth.py +++ b/shop/views/auth.py @@ -63,7 +63,7 @@ def login(self): previous_user = None else: previous_user = self.request.customer.user - super(LoginView, self).login() # this rotates the session_key + super().login() # this rotates the session_key if not self.serializer.data.get('stay_logged_in'): self.request.session.set_expiry(0) # log out when the browser is closed authenticated_cart = CartModel.objects.get_from_request(self.request) diff --git a/shop/views/cart.py b/shop/views/cart.py index b6056c538..2daeed7bd 100644 --- a/shop/views/cart.py +++ b/shop/views/cart.py @@ -77,7 +77,7 @@ def finalize_response(self, request, response, *args, **kwargs): """Set HTTP headers to not cache this view""" if self.action != 'render_product_summary': add_never_cache_headers(response) - return super(BaseViewSet, self).finalize_response(request, response, *args, **kwargs) + return super().finalize_response(request, response, *args, **kwargs) class CartViewSet(BaseViewSet): diff --git a/shop/views/catalog.py b/shop/views/catalog.py index dae4fab96..e66a51324 100644 --- a/shop/views/catalog.py +++ b/shop/views/catalog.py @@ -68,7 +68,7 @@ def adjust_offset(self, url, page_offset): return url def get_html_context(self): - context = super(ProductListPagination, self).get_html_context() + context = super().get_html_context() page_offset = self.get_offset(self.request) context['previous_url'] = self.adjust_offset(context['previous_url'], page_offset) context['next_url'] = self.adjust_offset(context['next_url'], page_offset) @@ -277,7 +277,7 @@ def dispatch(self, request, *args, **kwargs): forwards the request to django-CMS. """ try: - return super(ProductRetrieveView, self).dispatch(request, *args, **kwargs) + return super().dispatch(request, *args, **kwargs) except Http404: if request.current_page.node.is_root(): return details(request, kwargs.get('slug')) @@ -296,7 +296,7 @@ def get_template_names(self): ] def get_renderer_context(self): - renderer_context = super(ProductRetrieveView, self).get_renderer_context() + renderer_context = super().get_renderer_context() if renderer_context['request'].accepted_renderer.format == 'html': # add the product as Python object to the context product = self.get_object() @@ -348,7 +348,7 @@ class AddFilterContextMixin: on how to render the filter set, supplied by attribute ``filter_class``. """ def get_renderer_context(self): - renderer_context = super(AddFilterContextMixin, self).get_renderer_context() + renderer_context = super().get_renderer_context() if self.filter_class and renderer_context['request'].accepted_renderer.format == 'html': # restrict filter set to products associated to this CMS page only queryset = self.product_model.objects.filter(self.limit_choices_to) diff --git a/shop/views/checkout.py b/shop/views/checkout.py index 30122de38..645238aeb 100644 --- a/shop/views/checkout.py +++ b/shop/views/checkout.py @@ -26,7 +26,7 @@ class CheckoutViewSet(GenericViewSet): cart_serializer_class = CartSerializer def __init__(self, **kwargs): - super(CheckoutViewSet, self).__init__(**kwargs) + super().__init__(**kwargs) self.dialog_forms = set([import_string(fc) for fc in app_settings.SHOP_DIALOG_FORMS]) try: from shop.cascade.plugin_base import DialogFormPluginBase diff --git a/shop/views/order.py b/shop/views/order.py index ad5b81fcb..acdfa5d5a 100644 --- a/shop/views/order.py +++ b/shop/views/order.py @@ -63,7 +63,7 @@ def get_serializer_class(self): return self.detail_serializer_class def get_renderer_context(self): - renderer_context = super(OrderView, self).get_renderer_context() + renderer_context = super().get_renderer_context() if self.request.accepted_renderer.format == 'html': renderer_context.update(many=self.many) if not self.many: @@ -107,12 +107,12 @@ def post(self, request, *args, **kwargs): def list(self, request, *args, **kwargs): try: - return super(OrderView, self).list(request, *args, **kwargs) + return super().list(request, *args, **kwargs) except OrderModel.DoesNotExist: raise NotFound("No orders have been found for the current user.") def retrieve(self, request, *args, **kwargs): try: - return super(OrderView, self).retrieve(request, *args, **kwargs) + return super().retrieve(request, *args, **kwargs) except OrderModel.DoesNotExist: raise NotFound("No order has been found for the current user.")