Moved some template tags out of forms_helpers into comments_helpers.py.
Patch by: Lennard de Rijk
Reviewed by: to-be-reviewed
--- a/app/soc/templates/soc/templatetags/_as_comments.html Sat Mar 07 15:19:06 2009 +0000
+++ b/app/soc/templates/soc/templatetags/_as_comments.html Sat Mar 07 15:19:53 2009 +0000
@@ -11,8 +11,7 @@
See the License for the specific language governing permissions and
limitations under the License.
{% endcomment %}
-
-{% load forms_helpers %}
+{% load comments_helpers %}
<ul>
{% for comment in comments %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/helper/templatetags/comments_helpers.py Sat Mar 07 15:19:53 2009 +0000
@@ -0,0 +1,87 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2009 the Melange authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""A Django template tag library containing Comments helpers.
+"""
+
+__authors__ = [
+ '"Sverre Rabbelier" <srabbelier@gmail.com>',
+ '"Lennard de Rijk" <ljvderijk@gmail.com>',
+ ]
+
+
+from django import template
+
+from soc.logic.models import user as user_logic
+from soc.views.helper import redirects
+
+
+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/_as_review.html',
+ takes_context=True)
+def as_review(context, review):
+ """Returns a HTML representation of a review.
+ """
+
+ # TODO(ljvderijk) once review editing is allowed redo this
+
+ context.update({
+ 'author': review.author_name(),
+ 'content': review.content,
+ 'created': review.created,
+ 'score': review.score,
+ 'is_public': review.is_public,
+ 'comment_class': "public" if review.is_public else "private",
+ })
+
+ return context
+
--- a/app/soc/views/helper/templatetags/forms_helpers.py Sat Mar 07 15:19:06 2009 +0000
+++ b/app/soc/views/helper/templatetags/forms_helpers.py Sat Mar 07 15:19:53 2009 +0000
@@ -40,40 +40,6 @@
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.