diff options
| author | Christopher Long <indirecthit@gmail.com> | 2007-06-17 22:18:54 +0000 |
|---|---|---|
| committer | Christopher Long <indirecthit@gmail.com> | 2007-06-17 22:18:54 +0000 |
| commit | ae22b6d403dcf25098c77f0dfcf59ae58b186461 (patch) | |
| tree | c37fc631e99a7e4d909d6b6d236f495003731ea7 /django/contrib/comments | |
| parent | 0cf7bc439129c66df8d64601e885f83b256b4f25 (diff) | |
per-object-permissions: Merged to trunk [5486] NOTE: Not fully tested, will be working on this over the next few weeks.
git-svn-id: http://code.djangoproject.com/svn/django/branches/per-object-permissions@5488 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/contrib/comments')
| -rw-r--r-- | django/contrib/comments/feeds.py | 9 | ||||
| -rw-r--r-- | django/contrib/comments/models.py | 2 | ||||
| -rw-r--r-- | django/contrib/comments/templates/comments/form.html | 2 | ||||
| -rw-r--r-- | django/contrib/comments/templatetags/comments.py | 22 | ||||
| -rw-r--r-- | django/contrib/comments/views/comments.py | 12 |
5 files changed, 26 insertions, 21 deletions
diff --git a/django/contrib/comments/feeds.py b/django/contrib/comments/feeds.py index 34cf3d9cef..1ad638469b 100644 --- a/django/contrib/comments/feeds.py +++ b/django/contrib/comments/feeds.py @@ -23,16 +23,19 @@ class LatestFreeCommentsFeed(Feed): self._site = Site.objects.get_current() return "Latest comments on %s" % self._site.name + def get_query_set(self): + return self.comments_class.objects.filter(site__pk=settings.SITE_ID, is_public=True) + def items(self): - return self.comments_class.objects.filter(site__pk=settings.SITE_ID, is_public=True)[:40] + return self.get_query_set()[:40] class LatestCommentsFeed(LatestFreeCommentsFeed): """Feed of latest free comments on the current site""" comments_class = Comment - def items(self): - qs = LatestFreeCommentsFeed.items(self) + def get_query_set(self): + qs = super(LatestCommentsFeed, self).get_query_set() qs = qs.filter(is_removed=False) if settings.COMMENTS_BANNED_USERS_GROUP: where = ['user_id NOT IN (SELECT user_id FROM auth_users_group WHERE group_id = %s)'] diff --git a/django/contrib/comments/models.py b/django/contrib/comments/models.py index 90a84baaff..fa6c6aa363 100644 --- a/django/contrib/comments/models.py +++ b/django/contrib/comments/models.py @@ -209,7 +209,7 @@ class FreeComment(models.Model): class KarmaScoreManager(models.Manager): def vote(self, user_id, comment_id, score): try: - karma = self.objects.get(comment__pk=comment_id, user__pk=user_id) + karma = self.get(comment__pk=comment_id, user__pk=user_id) except self.model.DoesNotExist: karma = self.model(None, user_id=user_id, comment_id=comment_id, score=score, scored_date=datetime.datetime.now()) karma.save() diff --git a/django/contrib/comments/templates/comments/form.html b/django/contrib/comments/templates/comments/form.html index c5aa7686a3..11eaa8d00d 100644 --- a/django/contrib/comments/templates/comments/form.html +++ b/django/contrib/comments/templates/comments/form.html @@ -3,7 +3,7 @@ <form {% if photos_optional or photos_required %}enctype="multipart/form-data" {% endif %}action="/comments/post/" method="post"> {% if user.is_authenticated %} -<p>{% trans "Username:" %} <strong>{{ user.username }}</strong> (<a href="/accounts/logout/">{% trans "Log out" %}</a>)</p> +<p>{% trans "Username:" %} <strong>{{ user.username }}</strong> (<a href="{{ logout_url }}">{% trans "Log out" %}</a>)</p> {% else %} <p><label for="id_username">{% trans "Username:" %}</label> <input type="text" name="username" id="id_username" /><br />{% trans "Password:" %} <input type="password" name="password" id="id_password" /> (<a href="/accounts/password_reset/">{% trans "Forgotten your password?" %}</a>)</p> {% endif %} diff --git a/django/contrib/comments/templatetags/comments.py b/django/contrib/comments/templatetags/comments.py index c3a2fd40d8..a43b11f452 100644 --- a/django/contrib/comments/templatetags/comments.py +++ b/django/contrib/comments/templatetags/comments.py @@ -24,7 +24,8 @@ class CommentFormNode(template.Node): self.photo_options, self.rating_options = photo_options, rating_options self.is_public = is_public - def render(self, context): + def iter_render(self, context): + from django.conf import settings from django.utils.text import normalize_newlines import base64 context.push() @@ -32,7 +33,7 @@ class CommentFormNode(template.Node): try: self.obj_id = template.resolve_variable(self.obj_id_lookup_var, context) except template.VariableDoesNotExist: - return '' + return # Validate that this object ID is valid for this content-type. # We only have to do this validation if obj_id_lookup_var is provided, # because do_comment_form() validates hard-coded object IDs. @@ -64,10 +65,11 @@ class CommentFormNode(template.Node): if self.rating_options: context['rating_range'], context['rating_choices'] = Comment.objects.get_rating_options(self.rating_options) context['hash'] = Comment.objects.get_security_hash(context['options'], context['photo_options'], context['rating_options'], context['target']) + context['logout_url'] = settings.LOGOUT_URL default_form = loader.get_template(COMMENT_FORM) - output = default_form.render(context) + for chunk in default_form.iter_render(context): + yield chunk context.pop() - return output class CommentCountNode(template.Node): def __init__(self, package, module, context_var_name, obj_id, var_name, free): @@ -75,7 +77,7 @@ class CommentCountNode(template.Node): self.context_var_name, self.obj_id = context_var_name, obj_id self.var_name, self.free = var_name, free - def render(self, context): + def iter_render(self, context): from django.conf import settings manager = self.free and FreeComment.objects or Comment.objects if self.context_var_name is not None: @@ -84,7 +86,7 @@ class CommentCountNode(template.Node): content_type__app_label__exact=self.package, content_type__model__exact=self.module, site__id__exact=settings.SITE_ID).count() context[self.var_name] = comment_count - return '' + return () class CommentListNode(template.Node): def __init__(self, package, module, context_var_name, obj_id, var_name, free, ordering, extra_kwargs=None): @@ -94,14 +96,14 @@ class CommentListNode(template.Node): self.ordering = ordering self.extra_kwargs = extra_kwargs or {} - def render(self, context): + def iter_render(self, context): from django.conf import settings get_list_function = self.free and FreeComment.objects.filter or Comment.objects.get_list_with_karma if self.context_var_name is not None: try: self.obj_id = template.resolve_variable(self.context_var_name, context) except template.VariableDoesNotExist: - return '' + return () kwargs = { 'object_id__exact': self.obj_id, 'content_type__app_label__exact': self.package, @@ -114,7 +116,7 @@ class CommentListNode(template.Node): comment_list = get_list_function(**kwargs).order_by(self.ordering + 'submit_date').select_related() if not self.free: - if context.has_key('user') and context['user'].is_authenticated(): + if 'user' in context and context['user'].is_authenticated(): user_id = context['user'].id context['user_can_moderate_comments'] = Comment.objects.user_is_moderator(context['user']) else: @@ -125,7 +127,7 @@ class CommentListNode(template.Node): comment_list = [c for c in comment_list if not c.is_hidden or (user_id == c.user_id)] context[self.var_name] = comment_list - return '' + return () class DoCommentForm: """ diff --git a/django/contrib/comments/views/comments.py b/django/contrib/comments/views/comments.py index 12330afe41..73a9b2c480 100644 --- a/django/contrib/comments/views/comments.py +++ b/django/contrib/comments/views/comments.py @@ -217,10 +217,10 @@ def post_comment(request): errors = manipulator.get_validation_errors(new_data) # If user gave correct username/password and wasn't already logged in, log them in # so they don't have to enter a username/password again. - if manipulator.get_user() and not manipulator.get_user().is_authenticated() and new_data.has_key('password') and manipulator.get_user().check_password(new_data['password']): + if manipulator.get_user() and not manipulator.get_user().is_authenticated() and 'password' in new_data and manipulator.get_user().check_password(new_data['password']): from django.contrib.auth import login login(request, manipulator.get_user()) - if errors or request.POST.has_key('preview'): + if errors or 'preview' in request.POST: class CommentFormWrapper(oldforms.FormWrapper): def __init__(self, manipulator, new_data, errors, rating_choices): oldforms.FormWrapper.__init__(self, manipulator, new_data, errors) @@ -244,7 +244,7 @@ def post_comment(request): 'rating_range': rating_range, 'rating_choices': rating_choices, }, context_instance=RequestContext(request)) - elif request.POST.has_key('post'): + elif 'post' in request.POST: # If the IP is banned, mail the admins, do NOT save the comment, and # serve up the "Thanks for posting" page as if the comment WAS posted. if request.META['REMOTE_ADDR'] in settings.BANNED_IPS: @@ -298,7 +298,7 @@ def post_free_comment(request): new_data['is_public'] = IS_PUBLIC in option_list manipulator = PublicFreeCommentManipulator() errors = manipulator.get_validation_errors(new_data) - if errors or request.POST.has_key('preview'): + if errors or 'preview' in request.POST: comment = errors and '' or manipulator.get_comment(new_data) return render_to_response('comments/free_preview.html', { 'comment': comment, @@ -307,7 +307,7 @@ def post_free_comment(request): 'target': target, 'hash': security_hash, }, context_instance=RequestContext(request)) - elif request.POST.has_key('post'): + elif 'post' in request.POST: # If the IP is banned, mail the admins, do NOT save the comment, and # serve up the "Thanks for posting" page as if the comment WAS posted. if request.META['REMOTE_ADDR'] in settings.BANNED_IPS: @@ -330,7 +330,7 @@ def comment_was_posted(request): The object the comment was posted on """ obj = None - if request.GET.has_key('c'): + if 'c' in request.GET: content_type_id, object_id = request.GET['c'].split(':') try: content_type = ContentType.objects.get(pk=content_type_id) |
