30 from django.forms import forms as forms_in |
30 from django.forms import forms as forms_in |
31 from django.utils.encoding import force_unicode |
31 from django.utils.encoding import force_unicode |
32 from django.utils.html import escape |
32 from django.utils.html import escape |
33 |
33 |
34 from soc.logic import dicts |
34 from soc.logic import dicts |
|
35 from soc.logic.models import user as user_logic |
|
36 from soc.views.helper import redirects |
35 from soc.views.helper import widgets |
37 from soc.views.helper import widgets |
36 |
38 |
37 |
39 |
38 register = template.Library() |
40 register = template.Library() |
39 |
41 |
|
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 |
40 |
76 |
41 @register.inclusion_tag('soc/templatetags/_field_as_table_row.html') |
77 @register.inclusion_tag('soc/templatetags/_field_as_table_row.html') |
42 def field_as_table_row(field): |
78 def field_as_table_row(field): |
43 """Prints a newforms field as a table row. |
79 """Prints a newforms field as a table row. |
44 |
80 |