mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 16:12:51 +11:00
Fix Detail Form Post. Use shorthand super().
This commit is contained in:
parent
4930a4cd5a
commit
652d20a28f
3 changed files with 13 additions and 13 deletions
|
@ -60,7 +60,7 @@ class SnippetForm(forms.ModelForm):
|
||||||
fields = ("content", "lexer", "rtl")
|
fields = ("content", "lexer", "rtl")
|
||||||
|
|
||||||
def __init__(self, request, *args, **kwargs):
|
def __init__(self, request, *args, **kwargs):
|
||||||
super(SnippetForm, self).__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.request = request
|
self.request = request
|
||||||
|
|
||||||
# Set the recently used lexer if we have any
|
# 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"]
|
self.instance.expire_type = self.cleaned_data["expire_type"]
|
||||||
|
|
||||||
# Save snippet in the db
|
# Save snippet in the db
|
||||||
super(SnippetForm, self).save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
# Add the snippet to the user session list
|
# Add the snippet to the user session list
|
||||||
self.request.session.setdefault("snippet_list", [])
|
self.request.session.setdefault("snippet_list", [])
|
||||||
|
|
|
@ -81,7 +81,7 @@ class Snippet(models.Model):
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.secret_id:
|
if not self.secret_id:
|
||||||
self.secret_id = generate_secret_id(length=config.SLUG_LENGTH)
|
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):
|
def get_absolute_url(self):
|
||||||
return reverse("snippet_details", kwargs={"snippet_id": self.secret_id})
|
return reverse("snippet_details", kwargs={"snippet_id": self.secret_id})
|
||||||
|
|
|
@ -50,7 +50,7 @@ class SnippetView(FormView):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
kwargs = super(SnippetView, self).get_form_kwargs()
|
kwargs = super().get_form_kwargs()
|
||||||
kwargs.update({"request": self.request})
|
kwargs.update({"request": self.request})
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
@ -59,12 +59,12 @@ class SnippetView(FormView):
|
||||||
return HttpResponseRedirect(snippet.get_absolute_url())
|
return HttpResponseRedirect(snippet.get_absolute_url())
|
||||||
|
|
||||||
def get_context_data(self, **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)
|
ctx.update(config.extra_template_context)
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
|
||||||
class SnippetDetailView(DetailView):
|
class SnippetDetailView(DetailView, FormView):
|
||||||
"""
|
"""
|
||||||
Details list view of a snippet. Handles the actual view, reply and
|
Details list view of a snippet. Handles the actual view, reply and
|
||||||
tree/diff view.
|
tree/diff view.
|
||||||
|
@ -93,7 +93,7 @@ class SnippetDetailView(DetailView):
|
||||||
url = "{0}#".format(reverse("snippet_new"))
|
url = "{0}#".format(reverse("snippet_new"))
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
return super(SnippetDetailView, self).post(request, *args, **kwargs)
|
return super().post(request, *args, **kwargs)
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
snippet = self.get_object()
|
snippet = self.get_object()
|
||||||
|
@ -113,7 +113,7 @@ class SnippetDetailView(DetailView):
|
||||||
snippet.view_count += 1
|
snippet.view_count += 1
|
||||||
snippet.save(update_fields=["view_count"])
|
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
|
# Set the Max-Age header up until the snippet would expire
|
||||||
if config.CACHE_HEADER:
|
if config.CACHE_HEADER:
|
||||||
|
@ -168,7 +168,7 @@ class SnippetDetailView(DetailView):
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
|
|
||||||
ctx = super(SnippetDetailView, self).get_context_data(**kwargs)
|
ctx = super().get_context_data(**kwargs)
|
||||||
ctx.update(
|
ctx.update(
|
||||||
{
|
{
|
||||||
"wordwrap": self.object.lexer in highlight.LEXER_WORDWRAP,
|
"wordwrap": self.object.lexer in highlight.LEXER_WORDWRAP,
|
||||||
|
@ -192,7 +192,7 @@ class SnippetRawView(SnippetDetailView):
|
||||||
return HttpResponseForbidden(
|
return HttpResponseForbidden(
|
||||||
ugettext("This dpaste installation has Raw view mode disabled.")
|
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):
|
def render_plain_text(self, context, **response_kwargs):
|
||||||
snippet = self.get_object()
|
snippet = self.get_object()
|
||||||
|
@ -204,12 +204,12 @@ class SnippetRawView(SnippetDetailView):
|
||||||
def render_to_response(self, context, **response_kwargs):
|
def render_to_response(self, context, **response_kwargs):
|
||||||
if config.RAW_MODE_PLAIN_TEXT:
|
if config.RAW_MODE_PLAIN_TEXT:
|
||||||
return self.render_plain_text(config, **response_kwargs)
|
return self.render_plain_text(config, **response_kwargs)
|
||||||
return super(SnippetRawView, self).render_to_response(
|
return super().render_to_response(
|
||||||
context, **response_kwargs
|
context, **response_kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_context_data(self, **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)
|
ctx.update(config.extra_template_context)
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ class SnippetHistory(TemplateView):
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
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({"snippet_list": self.get_user_snippets()})
|
||||||
ctx.update(config.extra_template_context)
|
ctx.update(config.extra_template_context)
|
||||||
return ctx
|
return ctx
|
||||||
|
|
Loading…
Reference in a new issue