--- a/app/soc/views/helper/templatetags/forms_helpers.py Thu Mar 05 19:20:02 2009 +0000
+++ b/app/soc/views/helper/templatetags/forms_helpers.py Thu Mar 05 19:21:43 2009 +0000
@@ -32,12 +32,48 @@
from django.utils.html import escape
from soc.logic import dicts
+from soc.logic.models import user as user_logic
+from soc.views.helper import redirects
from soc.views.helper import widgets
register = template.Library()
+@register.inclusion_tag('soc/templatetags/_as_comments.html',
+ takes_context=True)
+def as_comments(context, work):
+ """Returns a HTML representation of a work's comments.
+ """
+
+ context['comments'] = work.comments
+ return context
+
+@register.inclusion_tag('soc/templatetags/_as_comment.html',
+ takes_context=True)
+def as_comment(context, comment):
+ """Returns a HTML representation of a comment.
+ """
+
+ edit_link = ''
+ current_user = user_logic.logic.getForCurrentAccount()
+
+ if current_user and comment.author.key() == current_user.key():
+ params = {'url_name': context['comment_on_url_name']}
+ edit_link = redirects.getEditRedirect(comment, params)
+
+ context.update({
+ 'author': comment.author.name,
+ 'content': comment.content,
+ 'created': comment.created,
+ 'edit_link': edit_link,
+ 'modified_on': comment.modified,
+ 'modified_by': comment.modified_by.name if comment.modified_by else '',
+ 'comment_class': "public" if comment.is_public else "private",
+ })
+
+ return context
+
@register.inclusion_tag('soc/templatetags/_field_as_table_row.html')
def field_as_table_row(field):
"""Prints a newforms field as a table row.