From 12d51334f8168ca27b6cc8b76dfab56132141b4b Mon Sep 17 00:00:00 2001 From: Rocky Duan Date: Sun, 19 Aug 2012 16:03:42 -0700 Subject: [PATCH] mustache template --- .../django_comment_client/helpers.py | 6 +- lms/djangoapps/django_comment_client/utils.py | 11 +- .../coffee/src/discussion/content.coffee | 4 +- lms/templates/discussion/_content.html | 105 +++++++----------- lms/templates/discussion/_content.mustache | 60 ++++++++++ 5 files changed, 116 insertions(+), 70 deletions(-) create mode 100644 lms/templates/discussion/_content.mustache diff --git a/lms/djangoapps/django_comment_client/helpers.py b/lms/djangoapps/django_comment_client/helpers.py index 7c98aa4742..bb3bac0926 100644 --- a/lms/djangoapps/django_comment_client/helpers.py +++ b/lms/djangoapps/django_comment_client/helpers.py @@ -1,5 +1,6 @@ from django.core.urlresolvers import reverse from mitxmako.shortcuts import render_to_string +from utils import render_mustache import urllib def pluralize(singular_term, count): @@ -26,4 +27,7 @@ def url_for_tags(course_id, tags): return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id]) + '?' + urllib.urlencode({'tags': ",".join(tags)}) def render_content(content): - return render_to_string('discussion/_content.html', {'content': content}) + context = { + 'content': content, + } + return render_mustache('discussion/_content.mustache', context) diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index 47d0a676b4..e587278ff8 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -6,12 +6,15 @@ from xmodule.modulestore.django import modulestore from django.http import HttpResponse from django.utils import simplejson from django.db import connection -import logging from django.conf import settings +from django_comment_client.permissions import check_permissions_by_view +from mitxmako import middleware + +import logging import operator import itertools +import pystache -from django_comment_client.permissions import check_permissions_by_view _FULLMODULES = None _DISCUSSIONINFO = None @@ -175,3 +178,7 @@ def get_annotated_content_infos(course_id, thread, user): _annotate(child) _annotate(thread) return infos + +def render_mustache(template_name, dictionary, *args, **kwargs): + template = middleware.lookup['main'].get_template(template_name).source + return pystache.render(template, dictionary) diff --git a/lms/static/coffee/src/discussion/content.coffee b/lms/static/coffee/src/discussion/content.coffee index f6830f0630..9924e540a2 100644 --- a/lms/static/coffee/src/discussion/content.coffee +++ b/lms/static/coffee/src/discussion/content.coffee @@ -338,7 +338,7 @@ initializeFollowThread = (thread) -> "click .admin-endorse": -> handleEndorse(this, not $content.hasClass("endorsed")) - "click .discussion-openclose": -> + "click .admin-openclose": -> handleOpenClose(this, $(this).text()) "click .admin-edit": -> @@ -404,6 +404,6 @@ initializeFollowThread = (thread) -> if not Discussion.getContentInfo id, 'can_delete' $local(".admin-delete").remove() if not Discussion.getContentInfo id, 'can_openclose' - $local(".discussion-openclose").remove() + $local(".admin-openclose").remove() #if not Discussion.getContentInfo id, 'can_vote' # $local(".discussion-vote").css "visibility", "hidden" diff --git a/lms/templates/discussion/_content.html b/lms/templates/discussion/_content.html index 2f37bd89a7..1489f5997c 100644 --- a/lms/templates/discussion/_content.html +++ b/lms/templates/discussion/_content.html @@ -9,7 +9,11 @@
- ${render_vote(content)} +
+ +
${content['votes']['point']}
+ +
% if content['type'] == "thread": - ${render_title(content)} + ${(content.get('highlighted_title') or content['title']) | h} + % endif
-
${(content.get('highlighted_body') or content['body']) | h}
- +
${(content.get('highlighted_body') or content['body']) | h}
+ % if content['type'] == "thread": - ${render_tags(content)} +
+ % for tag in content['tags']: + ${tag | h} + % endfor +
+ % endif - ${render_bottom_bar(content)} +
+
+ ${time_ago_in_words(parse(content['updated_at']))} ago by + % if content['anonymous']: + anonymous + % else: + ${content['username']} + % endif +
+
+ % if content.get('comments_count', -1) >= 0: + % if discussion_type == 'user': + Show all comments (${content['comments_count']} total) + % else: + Show ${content['comments_count']} ${pluralize('comment', content['comments_count'])} + % endif + % endif +
+ +
- -<%def name="render_title(content)"> - ${(content.get('highlighted_title') or content['title']) | h} - - - -<%def name="render_tags(content)"> -
- % for tag in content['tags']: - ${tag | h} - % endfor -
- - - -<%def name="render_bottom_bar(content)"> -
- ${render_info(content)} - -
- - -<%def name="render_info(content)"> - -
- ${time_ago_in_words(parse(content['updated_at']))} ago by - % if content['anonymous']: - anonymous - % else: - ${content['username']} - % endif -
-
- % if content.get('comments_count', -1) >= 0: - % if discussion_type == 'user': - Show all comments (${content['comments_count']} total) - % else: - Show ${content['comments_count']} ${pluralize('comment', content['comments_count'])} - % endif - % endif -
- - -<%def name="render_link(cls, html)"> - ${html} - - -<%def name="render_vote(content)"> -
- ${render_link("discussion-vote discussion-vote-up", "▲")} -
${content['votes']['point']}
- ${render_link("discussion-vote discussion-vote-down", "▼")} -
- diff --git a/lms/templates/discussion/_content.mustache b/lms/templates/discussion/_content.mustache new file mode 100644 index 0000000000..1b860af1a8 --- /dev/null +++ b/lms/templates/discussion/_content.mustache @@ -0,0 +1,60 @@ +
+
+
+ +
{{content.votes.point}}
+ +
+
+ + {{#thread}} + {{{content.displayed_title}}} + + {{/thread}} +
+ +
{{{content.displayed_body}}}
+ + {{#thread}} +
+ {{#content.tags}} + {{tag}} + {{/content.tags}} +
+ + {{/thread}} +
+
+ {{content.updated_at}} ago by + {{#content.anonymous}} + anonymous + {{/content.anonymous}} + {{^content.anonymous}} + {{content.username}} + {{/content.anonymous}} +
+
+ {{#thread}} + {{#partial_comments}} + Show all comments ({{content.comments_count}} total) + {{/partial_comments}} + {{^partial_comments}} + Show {{#pluralize}}{{content.comments_count}} comment}}{{/pluralize}} + {{/partial_comments}} + {{/thread}} +
+ +
+
+
+
+