kopia lustrzana https://github.com/wagtail/wagtail
Used Python 3 super() syntax also in documentation. (#4246)
This disregards the release notes for earlier releases and only deals with current documentation.pull/4248/head
rodzic
c85e4a3ff0
commit
b30c722728
docs
advanced_topics/customisation
getting_started
reference
contrib
forms
modeladmin
pages
topics
|
@ -252,7 +252,7 @@ or to add custom validation logic for your models:
|
|||
address = forms.CharField()
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(EventPageForm, self).clean()
|
||||
cleaned_data = super().clean()
|
||||
|
||||
# Make sure that the event starts before it ends
|
||||
start_date = cleaned_data['start_date']
|
||||
|
@ -263,7 +263,7 @@ or to add custom validation logic for your models:
|
|||
return cleaned_data
|
||||
|
||||
def save(self, commit=True):
|
||||
page = super(EventPageForm, self).save(commit=False)
|
||||
page = super().save(commit=False)
|
||||
|
||||
# Update the duration field from the submitted dates
|
||||
page.duration = (page.end_date - page.start_date).days
|
||||
|
|
|
@ -376,7 +376,7 @@ model like this:
|
|||
|
||||
def get_context(self, request):
|
||||
# Update context to include only published posts, ordered by reverse-chron
|
||||
context = super(BlogIndexPage, self).get_context(request)
|
||||
context = super().get_context(request)
|
||||
blogpages = self.get_children().live().order_by('-first_published_at')
|
||||
context['blogpages'] = blogpages
|
||||
return context
|
||||
|
@ -649,7 +649,7 @@ will get you a 404, since we haven't yet defined a "tags" view. Add to ``models.
|
|||
blogpages = BlogPage.objects.filter(tags__name=tag)
|
||||
|
||||
# Update template context
|
||||
context = super(BlogTagIndexPage, self).get_context(request)
|
||||
context = super().get_context(request)
|
||||
context['blogpages'] = blogpages
|
||||
return context
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ The following example shows how to add a username to the CSV export:
|
|||
data_fields = [
|
||||
('username', 'Username'),
|
||||
]
|
||||
data_fields += super(FormPage, self).get_data_fields()
|
||||
data_fields += super().get_data_fields()
|
||||
|
||||
return data_fields
|
||||
|
||||
|
@ -177,7 +177,7 @@ The following example shows how to add a username to the CSV export:
|
|||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
|
||||
def get_data(self):
|
||||
form_data = super(CustomFormSubmission, self).get_data()
|
||||
form_data = super().get_data()
|
||||
form_data.update({
|
||||
'username': self.user.username,
|
||||
})
|
||||
|
@ -241,7 +241,7 @@ Example:
|
|||
self.get_context(request)
|
||||
)
|
||||
|
||||
return super(FormPage, self).serve(request, *args, **kwargs)
|
||||
return super().serve(request, *args, **kwargs)
|
||||
|
||||
def get_submission_class(self):
|
||||
return CustomFormSubmission
|
||||
|
@ -476,7 +476,7 @@ First, you need to collect results as shown below:
|
|||
]
|
||||
|
||||
def get_context(self, request, *args, **kwargs):
|
||||
context = super(FormPage, self).get_context(request, *args, **kwargs)
|
||||
context = super().get_context(request, *args, **kwargs)
|
||||
|
||||
# If you need to show results only on landing page,
|
||||
# you may need check request.method
|
||||
|
@ -588,7 +588,7 @@ Finally, we add a URL param of `id` based on the ``form_submission`` if it exist
|
|||
url += '?id=%s' % form_submission.id
|
||||
return redirect(url, permanent=False)
|
||||
# if no thank_you_page is set, render default landing page
|
||||
return super(FormPage, self).render_landing_page(request, form_submission, *args, **kwargs)
|
||||
return super().render_landing_page(request, form_submission, *args, **kwargs)
|
||||
|
||||
content_panels = AbstractEmailForm.content_panels + [
|
||||
FieldPanel('intro', classname='full'),
|
||||
|
|
|
@ -160,7 +160,7 @@ A few special cases to note about ``list_display``:
|
|||
return 'None given'
|
||||
if field_name == 'likes_cat_gifs':
|
||||
return 'Unanswered'
|
||||
return super(self, PersonAdmin).get_empty_value_display(field_name)
|
||||
return super().get_empty_value_display(field_name)
|
||||
|
||||
|
||||
The ``__str__()`` method is just as valid
|
||||
|
@ -357,7 +357,7 @@ For example:
|
|||
list_display = ('first_name', 'last_name')
|
||||
|
||||
def get_queryset(self, request):
|
||||
qs = super(PersonAdmin, self).get_queryset(request)
|
||||
qs = super().get_queryset(request)
|
||||
# Only show people managed by the current user
|
||||
return qs.filter(managed_by=request.user)
|
||||
|
||||
|
@ -489,7 +489,7 @@ help give the value more context:
|
|||
list_display = ('name', 'likes_cat_gifs')
|
||||
|
||||
def get_extra_attrs_for_field_col(self, obj, field_name=None):
|
||||
attrs = super(PersonAdmin, self).get_extra_attrs_for_field_col(obj, field_name)
|
||||
attrs = super().get_extra_attrs_for_field_col(obj, field_name)
|
||||
if field_name == 'likes_cat_gifs' and obj.likes_cat_gifs is None:
|
||||
attrs.update({
|
||||
'title': (
|
||||
|
@ -522,7 +522,7 @@ kind of interactivity using javascript:
|
|||
list_display = ('title', 'start_date', 'end_date')
|
||||
|
||||
def get_extra_attrs_for_field_col(self, obj, field_name=None):
|
||||
attrs = super(EventAdmin, self).get_extra_attrs_for_field_col(obj, field_name)
|
||||
attrs = super().get_extra_attrs_for_field_col(obj, field_name)
|
||||
if field_name == 'start_date':
|
||||
# Add the start time as data to the 'start_date' cell
|
||||
attrs.update({ 'data-time': obj.start_time.strftime('%H:%M') })
|
||||
|
|
|
@ -32,7 +32,7 @@ Consider this example from the Wagtail demo site's ``models.py``, which serves a
|
|||
return HttpResponse(message, content_type='text/plain')
|
||||
else:
|
||||
# Display event page as usual
|
||||
return super(EventPage, self).serve(request)
|
||||
return super().serve(request)
|
||||
|
||||
:meth:`~wagtail.core.models.Page.serve` takes a Django request object and returns a Django response object. Wagtail returns a ``TemplateResponse`` object with the template and context which it generates, which allows middleware to function as intended, so keep in mind that a simpler response object like a ``HttpResponse`` will not receive these benefits.
|
||||
|
||||
|
@ -166,7 +166,7 @@ Wagtail's admin provides a nice interface for inputting tags into your content,
|
|||
Now that we have the many-to-many tag relationship in place, we can fit in a way to render both sides of the relation. Here's more of the Wagtail demo site ``models.py``, where the index model for ``BlogPage`` is extended with logic for filtering the index by tag:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
||||
from django.shortcuts import render
|
||||
|
||||
class BlogIndexPage(Page):
|
||||
|
|
|
@ -216,7 +216,7 @@ and pass those through at the point where you are calling ``get_url_parts`` on `
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
super(MyPageModel, self).get_url_parts(*args, **kwargs)
|
||||
super().get_url_parts(*args, **kwargs)
|
||||
|
||||
While you could pass only the ``request`` keyword argument, passing all arguments as-is ensures compatibility with any
|
||||
future changes to these method signatures.
|
||||
|
@ -273,7 +273,7 @@ To add more variables to the template context, you can override this method:
|
|||
...
|
||||
|
||||
def get_context(self, request):
|
||||
context = super(BlogIndexPage, self).get_context(request)
|
||||
context = super().get_context(request)
|
||||
|
||||
# Add extra variables and return the updated context
|
||||
context['blog_entries'] = BlogPage.objects.child_of(self).live()
|
||||
|
|
|
@ -665,7 +665,7 @@ As well as passing variables from the parent template, block subclasses can pass
|
|||
date = blocks.DateBlock()
|
||||
|
||||
def get_context(self, value, parent_context=None):
|
||||
context = super(EventBlock, self).get_context(value, parent_context=parent_context)
|
||||
context = super().get_context(value, parent_context=parent_context)
|
||||
context['is_happening_today'] = (value['date'] == datetime.date.today())
|
||||
return context
|
||||
|
||||
|
@ -842,7 +842,7 @@ To add additional variables, you can override the block's ``get_form_context`` m
|
|||
biography = blocks.RichTextBlock()
|
||||
|
||||
def get_form_context(self, value, prefix='', errors=None):
|
||||
context = super(PersonBlock, self).get_form_context(value, prefix=prefix, errors=errors)
|
||||
context = super().get_form_context(value, prefix=prefix, errors=errors)
|
||||
context['suggested_first_names'] = ['John', 'Paul', 'George', 'Ringo']
|
||||
return context
|
||||
|
||||
|
@ -938,7 +938,7 @@ For block types that simply wrap an existing Django form field, Wagtail provides
|
|||
class IPAddressBlock(FieldBlock):
|
||||
def __init__(self, required=True, help_text=None, **kwargs):
|
||||
self.field = forms.GenericIPAddressField(required=required, help_text=help_text)
|
||||
super(IPAddressBlock, self).__init__(**kwargs)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
Migrations
|
||||
|
|
Ładowanie…
Reference in New Issue