Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Suggested change to include a limit to the number of comments returned, ... #2

Closed
wants to merge 1 commit into from

2 participants

@tselaty

...which serves purpose in the case of a "LOAD MORE COMMENTS" button with Ajax.

@tselaty tselaty Suggested change to include a limit to the number of comments returne…
…d, which serves purpose in the case of a "LOAD MORE COMMENTS" button with Ajax.
be1f8b3
@paltman
Owner

@tselaty Thanks for this patch. I think it looks good. Just want the chance to download and test it myself before I accept the pull request. Will do so this week hopefully.

@tselaty
@tselaty
@paltman paltman closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 6, 2012
  1. @tselaty

    Suggested change to include a limit to the number of comments returne…

    tselaty authored
    …d, which serves purpose in the case of a "LOAD MORE COMMENTS" button with Ajax.
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 6 deletions.
  1. +12 −6 dialogos/templatetags/dialogos_tags.py
View
18 dialogos/templatetags/dialogos_tags.py
@@ -24,7 +24,7 @@ def can_delete_comment(comment, user):
class BaseCommentNode(template.Node):
-
+
@classmethod
def handle_token(cls, parser, token):
bits = token.split_contents()
@@ -34,23 +34,29 @@ def handle_token(cls, parser, token):
if bits[2] != "as":
raise template.TemplateSyntaxError("%r's 2nd argument must be 'as'" % bits[0])
return cls(parser.compile_filter(bits[1]), bits[3])
+ elif len(bits) == 5:
+ return cls(parser.compile_filter(bits[1]), bits[3], bits[4])
if cls.requires_as_var:
args = "1 argument"
else:
args = "either 1 or 3 arguments"
raise template.TemplateSyntaxError("%r takes %s" % (bits[0], args))
-
- def __init__(self, obj, varname=None):
+
+ def __init__(self, obj, varname=None, limit=None):
self.obj = obj
self.varname = varname
-
+ self.limit = limit
+
def get_comments(self, context):
obj = self.obj.resolve(context)
comments = Comment.objects.filter(
object_id=obj.pk,
content_type=ContentType.objects.get_for_model(obj)
- )
- return comments.order_by("submit_date")
+ ).order_by("submit_date")
+
+ if self.limit:
+ comments = comments[:self.limit]
+ return comments
class CommentCountNode(BaseCommentNode):
Something went wrong with that request. Please try again.