Fix Detail Form Post. Use shorthand super().

This commit is contained in:
Martin Mahner 2019-12-08 10:22:35 +01:00
parent 4930a4cd5a
commit 652d20a28f
3 changed files with 13 additions and 13 deletions

View file

@ -60,7 +60,7 @@ class SnippetForm(forms.ModelForm):
fields = ("content", "lexer", "rtl")
def __init__(self, request, *args, **kwargs):
super(SnippetForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.request = request
# Set the recently used lexer if we have any
@ -106,7 +106,7 @@ class SnippetForm(forms.ModelForm):
self.instance.expire_type = self.cleaned_data["expire_type"]
# Save snippet in the db
super(SnippetForm, self).save(*args, **kwargs)
super().save(*args, **kwargs)
# Add the snippet to the user session list
self.request.session.setdefault("snippet_list", [])

View file

@ -81,7 +81,7 @@ class Snippet(models.Model):
def save(self, *args, **kwargs):
if not self.secret_id:
self.secret_id = generate_secret_id(length=config.SLUG_LENGTH)
super(Snippet, self).save(*args, **kwargs)
super().save(*args, **kwargs)
def get_absolute_url(self):
return reverse("snippet_details", kwargs={"snippet_id": self.secret_id})

View file

@ -50,7 +50,7 @@ class SnippetView(FormView):
return response
def get_form_kwargs(self):
kwargs = super(SnippetView, self).get_form_kwargs()
kwargs = super().get_form_kwargs()
kwargs.update({"request": self.request})
return kwargs
@ -59,12 +59,12 @@ class SnippetView(FormView):
return HttpResponseRedirect(snippet.get_absolute_url())
def get_context_data(self, **kwargs):
ctx = super(SnippetView, self).get_context_data(**kwargs)
ctx = super().get_context_data(**kwargs)
ctx.update(config.extra_template_context)
return ctx
class SnippetDetailView(DetailView):
class SnippetDetailView(DetailView, FormView):
"""
Details list view of a snippet. Handles the actual view, reply and
tree/diff view.
@ -93,7 +93,7 @@ class SnippetDetailView(DetailView):
url = "{0}#".format(reverse("snippet_new"))
return HttpResponseRedirect(url)
return super(SnippetDetailView, self).post(request, *args, **kwargs)
return super().post(request, *args, **kwargs)
def get(self, request, *args, **kwargs):
snippet = self.get_object()
@ -113,7 +113,7 @@ class SnippetDetailView(DetailView):
snippet.view_count += 1
snippet.save(update_fields=["view_count"])
response = super(SnippetDetailView, self).get(request, *args, **kwargs)
response = super().get(request, *args, **kwargs)
# Set the Max-Age header up until the snippet would expire
if config.CACHE_HEADER:
@ -168,7 +168,7 @@ class SnippetDetailView(DetailView):
def get_context_data(self, **kwargs):
self.object = self.get_object()
ctx = super(SnippetDetailView, self).get_context_data(**kwargs)
ctx = super().get_context_data(**kwargs)
ctx.update(
{
"wordwrap": self.object.lexer in highlight.LEXER_WORDWRAP,
@ -192,7 +192,7 @@ class SnippetRawView(SnippetDetailView):
return HttpResponseForbidden(
ugettext("This dpaste installation has Raw view mode disabled.")
)
return super(SnippetRawView, self).dispatch(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
def render_plain_text(self, context, **response_kwargs):
snippet = self.get_object()
@ -204,12 +204,12 @@ class SnippetRawView(SnippetDetailView):
def render_to_response(self, context, **response_kwargs):
if config.RAW_MODE_PLAIN_TEXT:
return self.render_plain_text(config, **response_kwargs)
return super(SnippetRawView, self).render_to_response(
return super().render_to_response(
context, **response_kwargs
)
def get_context_data(self, **kwargs):
ctx = super(SnippetView, self).get_context_data(**kwargs)
ctx = super().get_context_data(**kwargs)
ctx.update(config.extra_template_context)
return ctx
@ -243,7 +243,7 @@ class SnippetHistory(TemplateView):
return HttpResponseRedirect(url)
def get_context_data(self, **kwargs):
ctx = super(SnippetHistory, self).get_context_data(**kwargs)
ctx = super().get_context_data(**kwargs)
ctx.update({"snippet_list": self.get_user_snippets()})
ctx.update(config.extra_template_context)
return ctx