Opened 7 years ago

Closed 4 years ago

#11549 closed New feature (wontfix)

contrib.comments should allow users to specify their own template on error

Reported by: Teebes Owned by: Teebes
Component: contrib.comments Version: master
Severity: Normal Keywords: comments, error, preview
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no


Currently in contrib.comments, if there is an error on the form the user is taken to a page that is generated by the preview template. This means that you can't have the user stay on the exact same page they were on if they submitted it with a mistake.

This patch introduces a new parameter to post_comment in contrib.comments.views.comments, that is None by default but that can contain an overwrite template location and extra context variable.

To get this to work, a user would just need to overwrite the comments/post url in and make it point to a custom wrapper around post_comment. For example:

    (r'^comments/post/$', 'thebes.quanda_comments.views.custom_post_comment'),


from django.contrib.comments.views.comments import post_comment
from django.http import HttpResponseRedirect

from thebes.quanda.models import Answer

def custom_post_comment(request):
    answers = Answer.objects.all()
    error_page = {
        'template': 'quanda/index.html',
        'data': { 'answers': answers },
    response = post_comment(request, error_page=error_page)
    return response

The impact is minimal, with only one file changed and no reverse compatibility issues. I've inclued both code path and documentation patch.

Attachments (1)

comments_patch.diff (3.0 KB) - added by Teebes 7 years ago.
Patch to contrib.comments (code & documentation) to allow error template selection

Download all attachments as: .zip

Change History (9)

Changed 7 years ago by Teebes

Attachment: comments_patch.diff added

Patch to contrib.comments (code & documentation) to allow error template selection

comment:1 Changed 7 years ago by Teebes

Needs documentation: unset
Needs tests: unset
Owner: changed from nobody to Teebes
Patch needs improvement: unset
Status: newassigned

comment:2 Changed 7 years ago by Teebes

comment:3 Changed 7 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

Nothing wrong with the idea, but it should be implemented in a way that maintains parity with other configurable template views (like the generic views). This means passing in a template_name and extra_context arguments, rather than a dictionary.

comment:4 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: New feature

comment:5 Changed 6 years ago by Julien Phalip

Needs documentation: set
Needs tests: set
Patch needs improvement: set

Patch needs improvement as per Russell's comment. Also needs tests and (better) doc to reflect the requested improvement.

comment:6 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:7 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:8 Changed 4 years ago by Jacob

Resolution: wontfix
Status: assignedclosed

django.contrib.comments has been deprecated and is no longer supported, so I'm closing this ticket. We're encouraging users to transition to a custom solution, or to a hosted solution like Disqus.

The code itself has moved to; if you want to keep using it, you could move this bug over there.

Note: See TracTickets for help on using tickets.
Back to Top