| 1 | 108a109,146
|
|---|
| 2 | > class RenderCommentListNode(CommentListNode):
|
|---|
| 3 | > """ Render the comment list directly """
|
|---|
| 4 | >
|
|---|
| 5 | > #@classmethod
|
|---|
| 6 | > def handle_token(cls, parser, token):
|
|---|
| 7 | > """Class method to parse render_comment_list and return a Node."""
|
|---|
| 8 | > tokens = token.contents.split()
|
|---|
| 9 | > if tokens[1] != 'for':
|
|---|
| 10 | > raise template.TemplateSyntaxError("Second argument in %r tag must be 'for'" % tokens[0])
|
|---|
| 11 | >
|
|---|
| 12 | > # {% render_comment_list for obj %}
|
|---|
| 13 | > if len(tokens) == 3:
|
|---|
| 14 | > return cls(object_expr=parser.compile_filter(tokens[2]))
|
|---|
| 15 | >
|
|---|
| 16 | > # {% render_comment_list for app.models pk %}
|
|---|
| 17 | > elif len(tokens) == 4:
|
|---|
| 18 | > return cls(
|
|---|
| 19 | > ctype = BaseCommentNode.lookup_content_type(tokens[2], tokens[0]),
|
|---|
| 20 | > object_pk_expr = parser.compile_filter(tokens[3])
|
|---|
| 21 | > )
|
|---|
| 22 | > handle_token = classmethod(handle_token)
|
|---|
| 23 | >
|
|---|
| 24 | > def render(self, context):
|
|---|
| 25 | > ctype, object_pk = self.get_target_ctype_pk(context)
|
|---|
| 26 | > if object_pk:
|
|---|
| 27 | > template_search_list = [
|
|---|
| 28 | > "comments/%s/%s/list.html" % (ctype.app_label, ctype.model),
|
|---|
| 29 | > "comments/%s/list.html" % ctype.app_label,
|
|---|
| 30 | > "comments/list.html"
|
|---|
| 31 | > ]
|
|---|
| 32 | > qs = self.get_query_set(context)
|
|---|
| 33 | > context.push()
|
|---|
| 34 | > liststr = render_to_string(template_search_list, {"comment_list" : self.get_context_value_from_queryset(context, qs)}, context)
|
|---|
| 35 | > context.pop()
|
|---|
| 36 | > return liststr
|
|---|
| 37 | > else:
|
|---|
| 38 | > return ''
|
|---|
| 39 | >
|
|---|
| 40 | 212a251,262
|
|---|
| 41 | > def render_comment_list(parser, token):
|
|---|
| 42 | > """
|
|---|
| 43 | > Render the comment list (as returned by ``{% render_comment_list %}``) through
|
|---|
| 44 | > the ``comments/list.html`` template
|
|---|
| 45 | >
|
|---|
| 46 | > Syntax::
|
|---|
| 47 | > {% render_comment_list for [object] %}
|
|---|
| 48 | > {% render_comment_list for [app].[model] [object_id] %}
|
|---|
| 49 | > """
|
|---|
| 50 | > return RenderCommentListNode.handle_token(parser, token)
|
|---|
| 51 | >
|
|---|
| 52 | > #@register.tag
|
|---|
| 53 | 249a300
|
|---|
| 54 | > register.tag(render_comment_list)
|
|---|