modified mustache template working
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
from django.core.urlresolvers import reverse
|
||||
from mitxmako.shortcuts import render_to_string
|
||||
from utils import render_mustache
|
||||
from utils import *
|
||||
from mustache_helpers import mustache_helpers
|
||||
from functools import partial
|
||||
|
||||
import pystache_custom as pystache
|
||||
import urllib
|
||||
|
||||
def pluralize(singular_term, count):
|
||||
@@ -14,20 +18,17 @@ def show_if(text, condition):
|
||||
else:
|
||||
return ''
|
||||
|
||||
def close_thread_text(content):
|
||||
if content.get('closed'):
|
||||
return 'Re-open thread'
|
||||
else:
|
||||
return 'Close thread'
|
||||
|
||||
def url_for_user(course_id, user_id):
|
||||
return reverse('django_comment_client.forum.views.user_profile', args=[course_id, user_id])
|
||||
|
||||
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):
|
||||
context = {
|
||||
'content': content,
|
||||
def render_content(content, additional_context={}):
|
||||
content_info = {
|
||||
'displayed_title': content.get('highlighted_title') or content.get('title', ''),
|
||||
'displayed_body': content.get('highlighted_body') or content.get('body', ''),
|
||||
'raw_tags': ','.join(content.get('tags', [])),
|
||||
}
|
||||
context = {
|
||||
'content': merge_dict(content, content_info),
|
||||
content['type']: True,
|
||||
}
|
||||
context = merge_dict(context, additional_context)
|
||||
partial_mustache_helpers = {k: partial(v, content) for k, v in mustache_helpers.items()}
|
||||
context = merge_dict(context, partial_mustache_helpers)
|
||||
return render_mustache('discussion/_content.mustache', context)
|
||||
|
||||
28
lms/djangoapps/django_comment_client/mustache_helpers.py
Normal file
28
lms/djangoapps/django_comment_client/mustache_helpers.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from django.core.urlresolvers import reverse
|
||||
import urllib
|
||||
|
||||
def pluralize(content, text):
|
||||
num, word = text.split(' ')
|
||||
if int(num or '0') >= 2:
|
||||
return num + ' ' + word + 's'
|
||||
else:
|
||||
return num + ' ' + word
|
||||
|
||||
def url_for_user(content, user_id):
|
||||
return reverse('django_comment_client.forum.views.user_profile', args=[content['course_id'], user_id])
|
||||
|
||||
def url_for_tags(content, tags): # assume that tags is in the format u'a, b, c'
|
||||
return reverse('django_comment_client.forum.views.forum_form_discussion', args=[content['course_id']]) + '?' + urllib.urlencode({'tags': tags})
|
||||
|
||||
def close_thread_text(content):
|
||||
if content.get('closed'):
|
||||
return 'Re-open thread'
|
||||
else:
|
||||
return 'Close thread'
|
||||
|
||||
mustache_helpers = {
|
||||
'pluralize': pluralize,
|
||||
'url_for_tags': url_for_tags,
|
||||
'url_for_user': url_for_user,
|
||||
'close_thread_text': close_thread_text,
|
||||
}
|
||||
@@ -10,7 +10,9 @@
|
||||
<li><a href="javascript:void(0)" class="admin-endorse">Endorse</a></li>
|
||||
<li><a href="javascript:void(0)" class="admin-edit">Edit</a></li>
|
||||
<li><a href="javascript:void(0)" class="admin-delete">Delete</a></li>
|
||||
<li><a href="javascript:void(0)" class="admin-openclose">Close thread</a></li>
|
||||
{{#thread}}
|
||||
<li><a href="javascript:void(0)" class="admin-openclose">{{close_thread_text}}</a></li>
|
||||
{{/thread}}
|
||||
</ul>
|
||||
{{#thread}}
|
||||
<a class="thread-title" name="{{content.id}}" href="javascript:void(0)">{{{content.displayed_title}}}</a>
|
||||
@@ -18,12 +20,12 @@
|
||||
{{/thread}}
|
||||
<div class="discussion-content-view">
|
||||
<a name="{{content.id}}" style="width: 0; height: 0; padding: 0; border: none;"></a>
|
||||
<div class="content-body">{{{content.displayed_body}}}</div>
|
||||
<div class="content-raw-body" style="display: none">{{{content.body}}}</div>
|
||||
<div class="content-body {{content.type}}-body" id="content-body-{{content.id}}">{{{content.displayed_body}}}</div>
|
||||
<div class="content-raw-body {{content.type}}-raw-body" style="display: none">{{{content.body}}}</div>
|
||||
{{#thread}}
|
||||
<div class="thread-tags">
|
||||
{{#content.tags}}
|
||||
<a class="thread-tag" href="{{#url_for_tags}}{{tag}}{{/url_for_tags}}">{{tag}}</a>
|
||||
<a class="thread-tag" href="{{##url_for_tags}}{{.}}{{/url_for_tags}}">{{.}}</a>
|
||||
{{/content.tags}}
|
||||
</div>
|
||||
<div class="thread-raw-tags" style="display: none">{{content.raw_tags}}</div>
|
||||
@@ -35,7 +37,7 @@
|
||||
anonymous
|
||||
{{/content.anonymous}}
|
||||
{{^content.anonymous}}
|
||||
<a href="{{#url_for_user}}{{content.user_id}}{{/url_for_user}}">{{content.username}}</a>
|
||||
<a href="{{##url_for_user}}{{content.user_id}}{{/url_for_user}}">{{content.username}}</a>
|
||||
{{/content.anonymous}}
|
||||
</div>
|
||||
<div class="comment-count">
|
||||
@@ -44,7 +46,7 @@
|
||||
<a href="javascript:void(0)" class="discussion-show-comments first-time">Show all comments ({{content.comments_count}} total)</a>
|
||||
{{/partial_comments}}
|
||||
{{^partial_comments}}
|
||||
<a href="javascript:void(0)" class="discussion-show-comments">Show {{#pluralize}}{{content.comments_count}} comment}}{{/pluralize}}</a>
|
||||
<a href="javascript:void(0)" class="discussion-show-comments">Show {{##pluralize}}{{content.comments_count}} comment{{/pluralize}}</a>
|
||||
{{/partial_comments}}
|
||||
{{/thread}}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user