author | Sverre Rabbelier <srabbelier@gmail.com> |
Wed, 08 Apr 2009 22:20:53 +0000 | |
changeset 2131 | 1d27ec29f1c7 |
parent 1897 | 634617545037 |
child 2365 | a66e1dd8ced7 |
permissions | -rw-r--r-- |
1714
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
2 |
# |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
4 |
# |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
8 |
# |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
10 |
# |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
16 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
17 |
"""A Django template tag library containing Comments helpers. |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
18 |
""" |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
19 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
21 |
'"Sverre Rabbelier" <srabbelier@gmail.com>', |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
22 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
23 |
] |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
24 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
25 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
26 |
from django import template |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
27 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
28 |
from soc.logic.models import user as user_logic |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
29 |
from soc.views.helper import redirects |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
30 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
31 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
32 |
register = template.Library() |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
33 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
34 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
35 |
@register.inclusion_tag('soc/templatetags/_as_comments.html', |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
36 |
takes_context=True) |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
37 |
def as_comments(context, work): |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
38 |
"""Returns a HTML representation of a work's comments. |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
39 |
""" |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
40 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
41 |
context['comments'] = work.comments |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
42 |
return context |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
43 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
44 |
@register.inclusion_tag('soc/templatetags/_as_comment.html', |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
45 |
takes_context=True) |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
46 |
def as_comment(context, comment): |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
47 |
"""Returns a HTML representation of a comment. |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
48 |
""" |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
49 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
50 |
edit_link = '' |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
51 |
current_user = user_logic.logic.getForCurrentAccount() |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
52 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
53 |
if current_user and comment.author.key() == current_user.key(): |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
54 |
params = {'url_name': context['comment_on_url_name']} |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
55 |
edit_link = redirects.getEditRedirect(comment, params) |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
56 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
57 |
context.update({ |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
58 |
'author': comment.author.name, |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
59 |
'content': comment.content, |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
60 |
'created': comment.created, |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
61 |
'edit_link': edit_link, |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
62 |
'modified_on': comment.modified, |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
63 |
'modified_by': comment.modified_by.name if comment.modified_by else '', |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
64 |
'comment_class': "public" if comment.is_public else "private", |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
65 |
}) |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
66 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
67 |
return context |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
68 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
69 |
@register.inclusion_tag('soc/templatetags/_as_review.html', |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
70 |
takes_context=True) |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
71 |
def as_review(context, review): |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
72 |
"""Returns a HTML representation of a review. |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
73 |
""" |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
74 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
75 |
# TODO(ljvderijk) once review editing is allowed redo this |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
76 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
77 |
context.update({ |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
78 |
'author': review.author_name(), |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
79 |
'content': review.content, |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
80 |
'created': review.created, |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
81 |
'score': review.score, |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
82 |
'is_public': review.is_public, |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
83 |
'comment_class': "public" if review.is_public else "private", |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
84 |
}) |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
85 |
|
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
86 |
return context |
bfdef9380954
Moved some template tags out of forms_helpers into comments_helpers.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
87 |
|
1897
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
88 |
@register.inclusion_tag('soc/templatetags/_as_student_proposal_review.html', |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
89 |
takes_context=True) |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
90 |
def as_student_proposal_review(context, review, student): |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
91 |
"""Returns a HTML representation of a student proposal review. |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
92 |
""" |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
93 |
|
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
94 |
# TODO(ljvderijk) once review editing is allowed redo this |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
95 |
|
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
96 |
context.update({ |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
97 |
'author': review.author_name(), |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
98 |
'content': review.content, |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
99 |
'created': review.created, |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
100 |
'score': review.score, |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
101 |
'is_public': review.is_public, |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
102 |
'from_student': review.author.key() == student.user.key() |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
103 |
}) |
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
104 |
|
634617545037
Added a new template tag to serve up background color for StudentProposals Reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1714
diff
changeset
|
105 |
return context |