Code

Opened 5 years ago

Closed 13 months 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

Description

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 urls.py and make it point to a custom wrapper around post_comment. For example:

urls.py:

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

quanda_comments/views.py:

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 5 years ago.
Patch to contrib.comments (code & documentation) to allow error template selection

Download all attachments as: .zip

Change History (9)

Changed 5 years ago by teebes

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

comment:1 Changed 5 years ago by teebes

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to teebes
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 5 years ago by teebes

comment:3 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

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 3 years ago by julien

  • Severity set to Normal
  • Type set to New feature

comment:5 Changed 3 years ago by julien

  • 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 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:7 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:8 Changed 13 months ago by jacob

  • Resolution set to wontfix
  • Status changed from assigned to closed

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 https://github.com/django/django-contrib-comments; if you want to keep using it, you could move this bug over there.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.