Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Converted django.contrib.comments.views.* to use load_and_render

git-svn-id: http://code.djangoproject.com/svn/django/trunk@661 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a269a2058a3e66b5c0d1a08eb2c81d31b4222327 1 parent 4175aec
Adrian Holovaty authored September 22, 2005
28  django/contrib/comments/views/comments.py
... ...
@@ -1,12 +1,12 @@
1  
-from django.core import formfields, template_loader, validators
  1
+from django.core import formfields, validators
2 2
 from django.core.mail import mail_admins, mail_managers
3 3
 from django.core.exceptions import Http404, ObjectDoesNotExist
4  
-from django.core.extensions import DjangoContext as Context
  4
+from django.core.extensions import DjangoContext, load_and_render
5 5
 from django.models.auth import users
6 6
 from django.models.comments import comments, freecomments
7 7
 from django.models.core import contenttypes
8 8
 from django.parts.auth.formfields import AuthenticationForm
9  
-from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
  9
+from django.utils.httpwrappers import HttpResponseRedirect
10 10
 from django.utils.text import normalize_newlines
11 11
 from django.conf.settings import BANNED_IPS, COMMENTS_ALLOW_PROFANITIES, COMMENTS_SKETCHY_USERS_GROUP, COMMENTS_FIRST_FEW, SITE_ID
12 12
 import base64, datetime
@@ -206,7 +206,6 @@ def post_comment(request):
206 206
     new_data['object_id'] = object_id
207 207
     new_data['ip_address'] = request.META.get('REMOTE_ADDR')
208 208
     new_data['is_public'] = comments.IS_PUBLIC in option_list
209  
-    response = HttpResponse()
210 209
     manipulator = PublicCommentManipulator(request.user,
211 210
         ratings_required=comments.RATINGS_REQUIRED in option_list,
212 211
         ratings_range=rating_range,
@@ -228,8 +227,7 @@ def ratings(self):
228 227
                 return field_list
229 228
         comment = errors and '' or manipulator.get_comment(new_data)
230 229
         comment_form = CommentFormWrapper(manipulator, new_data, errors, rating_choices)
231  
-        t = template_loader.get_template('comments/preview')
232  
-        c = Context(request, {
  230
+        return load_and_render('comments/preview', {
233 231
             'comment': comment,
234 232
             'comment_form': comment_form,
235 233
             'options': options,
@@ -240,7 +238,7 @@ def ratings(self):
240 238
             'ratings_required': comments.RATINGS_REQUIRED in option_list,
241 239
             'rating_range': rating_range,
242 240
             'rating_choices': rating_choices,
243  
-        })
  241
+        }, context_instance=DjangoContext(request))
244 242
     elif request.POST.has_key('post'):
245 243
         # If the IP is banned, mail the admins, do NOT save the comment, and
246 244
         # serve up the "Thanks for posting" page as if the comment WAS posted.
@@ -252,8 +250,6 @@ def ratings(self):
252 250
         return HttpResponseRedirect("/comments/posted/?c=%s:%s" % (content_type_id, object_id))
253 251
     else:
254 252
         raise Http404, "The comment form didn't provide either 'preview' or 'post'"
255  
-    response.write(t.render(c))
256  
-    return response
257 253
 
258 254
 def post_free_comment(request):
259 255
     """
@@ -295,19 +291,17 @@ def post_free_comment(request):
295 291
     new_data['object_id'] = object_id
296 292
     new_data['ip_address'] = request.META['REMOTE_ADDR']
297 293
     new_data['is_public'] = comments.IS_PUBLIC in option_list
298  
-    response = HttpResponse()
299 294
     manipulator = PublicFreeCommentManipulator()
300 295
     errors = manipulator.get_validation_errors(new_data)
301 296
     if errors or request.POST.has_key('preview'):
302 297
         comment = errors and '' or manipulator.get_comment(new_data)
303  
-        t = template_loader.get_template('comments/free_preview')
304  
-        c = Context(request, {
  298
+        return load_and_render('comments/free_preview', {
305 299
             'comment': comment,
306 300
             'comment_form': formfields.FormWrapper(manipulator, new_data, errors),
307 301
             'options': options,
308 302
             'target': target,
309 303
             'hash': security_hash,
310  
-        })
  304
+        }, context_instance=DjangoContext(request))
311 305
     elif request.POST.has_key('post'):
312 306
         # If the IP is banned, mail the admins, do NOT save the comment, and
313 307
         # serve up the "Thanks for posting" page as if the comment WAS posted.
@@ -320,8 +314,6 @@ def post_free_comment(request):
320 314
         return HttpResponseRedirect("/comments/posted/?c=%s:%s" % (content_type_id, object_id))
321 315
     else:
322 316
         raise Http404, "The comment form didn't provide either 'preview' or 'post'"
323  
-    response.write(t.render(c))
324  
-    return response
325 317
 
326 318
 def comment_was_posted(request):
327 319
     """
@@ -340,8 +332,4 @@ def comment_was_posted(request):
340 332
             obj = content_type.get_object_for_this_type(pk=object_id)
341 333
         except ObjectDoesNotExist:
342 334
             pass
343  
-    t = template_loader.get_template('comments/posted')
344  
-    c = Context(request, {
345  
-        'object': obj,
346  
-    })
347  
-    return HttpResponse(t.render(c))
  335
+    return load_and_render('comments/posted', {'object': obj}, context_instance=DjangoContext(request))
10  django/contrib/comments/views/karma.py
... ...
@@ -1,8 +1,6 @@
1  
-from django.core import template_loader
2  
-from django.core.extensions import DjangoContext as Context
3 1
 from django.core.exceptions import Http404
  2
+from django.core.extensions import DjangoContext, load_and_render
4 3
 from django.models.comments import comments, karma
5  
-from django.utils.httpwrappers import HttpResponse
6 4
 
7 5
 def vote(request, comment_id, vote):
8 6
     """
@@ -27,8 +25,4 @@ def vote(request, comment_id, vote):
27 25
     karma.vote(request.user.id, comment_id, rating)
28 26
     # Reload comment to ensure we have up to date karma count
29 27
     comment = comments.get_object(pk=comment_id)
30  
-    t = template_loader.get_template('comments/karma_vote_accepted')
31  
-    c = Context(request, {
32  
-        'comment': comment
33  
-    })
34  
-    return HttpResponse(t.render(c))
  28
+    return load_and_render('comments/karma_vote_accepted', {'comment': comment}, context_instance=DjangoContext(request))
29  django/contrib/comments/views/userflags.py
... ...
@@ -1,9 +1,8 @@
1  
-from django.core import template_loader
2  
-from django.core.extensions import DjangoContext as Context
  1
+from django.core.extensions import DjangoContext, load_and_render
3 2
 from django.core.exceptions import Http404
4 3
 from django.models.comments import comments, moderatordeletions, userflags
5 4
 from django.views.decorators.auth import login_required
6  
-from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
  5
+from django.utils.httpwrappers import HttpResponseRedirect
7 6
 from django.conf.settings import SITE_ID
8 7
 
9 8
 def flag(request, comment_id):
@@ -22,11 +21,7 @@ def flag(request, comment_id):
22 21
     if request.POST:
23 22
         userflags.flag(comment, request.user)
24 23
         return HttpResponseRedirect('%sdone/' % request.path)
25  
-    t = template_loader.get_template('comments/flag_verify')
26  
-    c = Context(request, {
27  
-        'comment': comment,
28  
-    })
29  
-    return HttpResponse(t.render(c))
  24
+    return load_and_render('comments/flag_verify', {'comment': comment}, context_instance=DjangoContext(request))
30 25
 flag = login_required(flag)
31 26
 
32 27
 def flag_done(request, comment_id):
@@ -34,11 +29,7 @@ def flag_done(request, comment_id):
34 29
         comment = comments.get_object(pk=comment_id, site__id__exact=SITE_ID)
35 30
     except comments.CommentDoesNotExist:
36 31
         raise Http404
37  
-    t = template_loader.get_template('comments/flag_done')
38  
-    c = Context(request, {
39  
-        'comment': comment,
40  
-    })
41  
-    return HttpResponse(t.render(c))
  32
+    return load_and_render('comments/flag_done', {'comment': comment}, context_instance=DjangoContext(request))
42 33
 
43 34
 def delete(request, comment_id):
44 35
     """
@@ -63,11 +54,7 @@ def delete(request, comment_id):
63 54
             m = moderatordeletions.ModeratorDeletion(None, request.user.id, comment.id, None)
64 55
             m.save()
65 56
         return HttpResponseRedirect('%sdone/' % request.path)
66  
-    t = template_loader.get_template('comments/delete_verify')
67  
-    c = Context(request, {
68  
-        'comment': comment,
69  
-    })
70  
-    return HttpResponse(t.render(c))
  57
+    return load_and_render('comments/delete_verify', {'comment': comment}, context_instance=DjangoContext(request))
71 58
 delete = login_required(delete)
72 59
 
73 60
 def delete_done(request, comment_id):
@@ -75,8 +62,4 @@ def delete_done(request, comment_id):
75 62
         comment = comments.get_object(pk=comment_id, site__id__exact=SITE_ID)
76 63
     except comments.CommentDoesNotExist:
77 64
         raise Http404
78  
-    t = template_loader.get_template('comments/delete_done')
79  
-    c = Context(request, {
80  
-        'comment': comment,
81  
-    })
82  
-    return HttpResponse(t.render(c))
  65
+    return load_and_render('comments/delete_done', {'comment': comment}, context_instance=DjangoContext(request))

0 notes on commit a269a20

Please sign in to comment.
Something went wrong with that request. Please try again.