Ticket #11549: comments_patch.diff
File comments_patch.diff, 3.0 KB (added by , 15 years ago) |
---|
-
django/contrib/comments/views/comments.py
22 22 if settings.DEBUG: 23 23 self.content = render_to_string("comments/400-debug.html", {"why": why}) 24 24 25 def post_comment(request, next=None ):25 def post_comment(request, next=None, error_page=None): 26 26 """ 27 27 Post a comment. 28 28 29 29 HTTP POST is required. If ``POST['submit'] == "preview"`` or if there are 30 30 errors a preview template, ``comments/preview.html``, will be rendered. 31 32 If error_page is given, error_page['template'] will 33 be used as the template instead of the preview page, and the key/value 34 pairs of error_page['data'] will be used as appended to the context. 31 35 """ 32 36 # Fill out some initial data fields from an authenticated user, if present 33 37 data = request.POST.copy() … … 79 83 "comments/%s_preview.html" % model._meta.app_label, 80 84 "comments/preview.html", 81 85 ] 82 return render_to_response( 83 template_list, { 86 data_dict = { 84 87 "comment" : form.data.get("comment", ""), 85 88 "form" : form, 86 89 "next": next, 87 }, 90 } 91 if form.errors and error_page: 92 # If the user has passed a custom error page, take its template 93 # and data dict and use those instead of the preview page 94 if error_page.has_key('template'): 95 template_list = [error_page['template']] + template_list 96 try: 97 for (key, value) in error_page['data'].items(): 98 data_dict[key] = value 99 except TypeError: pass 100 return render_to_response( 101 template_list, 102 data_dict, 88 103 RequestContext(request, {}) 89 104 ) 90 105 -
docs/ref/contrib/comments/custom.txt
118 118 119 119 .. _custom-comment-app-api: 120 120 121 Customizing which template renders the errors 122 ============================================= 123 124 The ``post_comment`` view in ``contrib/comments/views/comments.py`` can take an 125 extra "error_page" argument which conatins a dict contains another template 126 location and extra context data:: 127 128 error_page = { 129 'template': 'your_template_directory/template_name.html', 130 'data': { 131 'key1': value1, 132 'key2: vaue 2, 133 }, 134 } 135 136 137 This will make django load the specified template instead of the default 138 preview one. This allows you to keep the user on the same page if they forget 139 one of the comments fields by defining a wrapper around the ``post_comment`` 140 view which you point ``comments/post`` url to. 141 121 142 Custom comment app API 122 143 ====================== 123 144