Skip to content

Commit

Permalink
refactor all super() invocations to Python-3 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed May 15, 2020
1 parent 5440bfc commit e1ed7b3
Show file tree
Hide file tree
Showing 51 changed files with 152 additions and 153 deletions.
6 changes: 3 additions & 3 deletions shop/admin/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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()):
Expand Down
2 changes: 1 addition & 1 deletion shop/admin/defaults/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions shop/admin/defaults/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 11 additions & 11 deletions shop/admin/delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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')
Expand All @@ -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',)
Expand All @@ -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'])
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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.
Expand All @@ -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)
4 changes: 2 additions & 2 deletions shop/admin/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions shop/admin/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -218,7 +218,7 @@ def get_urls(self):
url(r'^(?P<pk>\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):
Expand Down
10 changes: 5 additions & 5 deletions shop/admin/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand 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:
Expand Down
2 changes: 1 addition & 1 deletion shop/cascade/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion shop/cascade/breadcrumb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion shop/cascade/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions shop/cascade/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'])
Expand Down
4 changes: 2 additions & 2 deletions shop/cascade/processbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions shop/deferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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')

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion shop/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Loading

0 comments on commit e1ed7b3

Please sign in to comment.