From 652d20a28fad7f959e0b28bf5651f7696c660e64 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Sun, 8 Dec 2019 10:22:35 +0100 Subject: [PATCH] Fix Detail Form Post. Use shorthand super(). --- dpaste/forms.py | 4 ++-- dpaste/models.py | 2 +- dpaste/views.py | 20 ++++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dpaste/forms.py b/dpaste/forms.py index 93e71eb..3bb6848 100644 --- a/dpaste/forms.py +++ b/dpaste/forms.py @@ -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", []) diff --git a/dpaste/models.py b/dpaste/models.py index 180039f..d85568b 100644 --- a/dpaste/models.py +++ b/dpaste/models.py @@ -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}) diff --git a/dpaste/views.py b/dpaste/views.py index 4569330..53098c7 100644 --- a/dpaste/views.py +++ b/dpaste/views.py @@ -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