app/soc/views/helper/templatetags/forms_helpers.py
changeset 1714 bfdef9380954
parent 1678 80411f57f31a
child 1815 7a9b69f36111
equal deleted inserted replaced
1713:e39ae44d0298 1714:bfdef9380954
    38 
    38 
    39 
    39 
    40 register = template.Library()
    40 register = template.Library()
    41 
    41 
    42 
    42 
    43 @register.inclusion_tag('soc/templatetags/_as_comments.html',
       
    44                         takes_context=True)
       
    45 def as_comments(context, work):
       
    46   """Returns a HTML representation of a work's comments.
       
    47   """
       
    48 
       
    49   context['comments'] =  work.comments
       
    50   return context
       
    51 
       
    52 @register.inclusion_tag('soc/templatetags/_as_comment.html',
       
    53                         takes_context=True)
       
    54 def as_comment(context, comment):
       
    55   """Returns a HTML representation of a comment.
       
    56   """
       
    57 
       
    58   edit_link = ''
       
    59   current_user = user_logic.logic.getForCurrentAccount()
       
    60 
       
    61   if current_user and comment.author.key() == current_user.key():
       
    62     params = {'url_name': context['comment_on_url_name']}
       
    63     edit_link = redirects.getEditRedirect(comment, params)
       
    64 
       
    65   context.update({
       
    66       'author': comment.author.name,
       
    67       'content': comment.content,
       
    68       'created': comment.created,
       
    69       'edit_link': edit_link,
       
    70       'modified_on': comment.modified,
       
    71       'modified_by': comment.modified_by.name if comment.modified_by else '',
       
    72       'comment_class': "public" if comment.is_public else "private",
       
    73       })
       
    74 
       
    75   return context
       
    76 
       
    77 @register.inclusion_tag('soc/templatetags/_field_as_table_row.html')
    43 @register.inclusion_tag('soc/templatetags/_field_as_table_row.html')
    78 def field_as_table_row(field):
    44 def field_as_table_row(field):
    79   """Prints a newforms field as a table row.
    45   """Prints a newforms field as a table row.
    80 
    46 
    81   This function actually does very little, simply passing the supplied
    47   This function actually does very little, simply passing the supplied