major refactor of templates
This commit is contained in:
29
lms/djangoapps/django_comment_client/helpers.py
Normal file
29
lms/djangoapps/django_comment_client/helpers.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from django.core.urlresolvers import reverse
|
||||
from mitxmako.shortcuts import render_to_string
|
||||
import urllib
|
||||
|
||||
def pluralize(singular_term, count):
|
||||
if int(count) >= 2:
|
||||
return singular_term + 's'
|
||||
return singular_term
|
||||
|
||||
def show_if(text, condition):
|
||||
if condition:
|
||||
return text
|
||||
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):
|
||||
return render_to_string('discussion/_content.html', {'content': content})
|
||||
@@ -175,9 +175,3 @@ def get_annotated_content_infos(course_id, thread, user):
|
||||
_annotate(child)
|
||||
_annotate(thread)
|
||||
return infos
|
||||
|
||||
def pluralize(singular_term, count):
|
||||
if int(count) >= 2:
|
||||
return singular_term + 's'
|
||||
return singular_term
|
||||
|
||||
|
||||
96
lms/templates/discussion/_content.html
Normal file
96
lms/templates/discussion/_content.html
Normal file
@@ -0,0 +1,96 @@
|
||||
<%! from django_comment_client.helpers import url_for_tags, url_for_user %>
|
||||
<%! from datehelper import time_ago_in_words %>
|
||||
<%! from dateutil.parser import parse %>
|
||||
<%! from django_comment_client.helpers import close_thread_text, \
|
||||
url_for_tags, \
|
||||
url_for_user, \
|
||||
pluralize
|
||||
%>
|
||||
|
||||
<div class="discussion-content">
|
||||
<div class="discussion-content-wrapper">
|
||||
${render_vote(content)}
|
||||
<div class="discussion-right-wrapper">
|
||||
<ul class="admin-actions">
|
||||
% if content['type'] == 'comment':
|
||||
<li><a href="javascript:void(0)" class="admin-endorse">Endorse</a></li>
|
||||
% endif
|
||||
<li><a href="javascript:void(0)" class="admin-edit">Edit</a></li>
|
||||
<li><a href="javascript:void(0)" class="admin-delete">Delete</a></li>
|
||||
% if content['type'] == "thread":
|
||||
<li><a class="discussion-openclose" id="discussion-openclose-${content['id']}" href="javascript:void(0);">${close_thread_text(content)}</a></li>
|
||||
% endif
|
||||
</ul>
|
||||
% if content['type'] == "thread":
|
||||
${render_title(content)}
|
||||
% endif
|
||||
<div class="discussion-content-view">
|
||||
<a name="${content['id']}" style="width: 0; height: 0; padding: 0; border: none;"></a>
|
||||
<div class="content-body ${content['type']}-body" id="content-body-${content['id']}">${(content.get('highlighted_body') or content['body']) | h}</div>
|
||||
<div class="content-raw-body ${content['type']}-raw-body" style="display: none">${content['body'] | h}</div>
|
||||
% if content['type'] == "thread":
|
||||
${render_tags(content)}
|
||||
% endif
|
||||
${render_bottom_bar(content)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%def name="render_title(content)">
|
||||
<a class="thread-title" name="${content['id']}" href="javascript:void(0)">${(content.get('highlighted_title') or content['title']) | h}</a>
|
||||
<div class="thread-raw-title" style="display: none">${content['title']}</div>
|
||||
</%def>
|
||||
|
||||
<%def name="render_tags(content)">
|
||||
<div class="thread-tags">
|
||||
% for tag in content['tags']:
|
||||
<a class="thread-tag" href="${url_for_tags(content['course_id'], [tag])}">${tag | h}</a>
|
||||
% endfor
|
||||
</div>
|
||||
<div class="thread-raw-tags" style="display: none">${",".join(content['tags']) | h}</div>
|
||||
</%def>
|
||||
|
||||
<%def name="render_bottom_bar(content)">
|
||||
<div class="info">
|
||||
${render_info(content)}
|
||||
<ul class="discussion-actions">
|
||||
<li>${render_link("discussion-link discussion-reply discussion-reply-" + content['type'], "Reply")}</li>
|
||||
<li><div class="follow-wrapper"></div></li>
|
||||
<li>${render_link("discussion-link discussion-permanent-link", "Permanent Link")}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
<%def name="render_info(content)">
|
||||
|
||||
<div class="comment-time">
|
||||
${time_ago_in_words(parse(content['updated_at']))} ago by
|
||||
% if content['anonymous']:
|
||||
anonymous
|
||||
% else:
|
||||
<a href="${url_for_user(content['course_id'], content['user_id'])}">${content['username']}</a>
|
||||
% endif
|
||||
</div>
|
||||
<div class="comment-count">
|
||||
% if content.get('comments_count', -1) >= 0:
|
||||
% if discussion_type == 'user':
|
||||
<a href="javascript:void(0)" class="discussion-show-comments first-time">Show all comments (${content['comments_count']} total)</a>
|
||||
% else:
|
||||
<a href="javascript:void(0)" class="discussion-show-comments">Show ${content['comments_count']} ${pluralize('comment', content['comments_count'])}</a>
|
||||
% endif
|
||||
% endif
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
<%def name="render_link(cls, html)">
|
||||
<a class="${cls}" href="javascript:void(0)">${html}</a>
|
||||
</%def>
|
||||
|
||||
<%def name="render_vote(content)">
|
||||
<div class="discussion-votes">
|
||||
${render_link("discussion-vote discussion-vote-up", "▲")}
|
||||
<div class="discussion-votes-point">${content['votes']['point']}</div>
|
||||
${render_link("discussion-vote discussion-vote-down", "▼")}
|
||||
</div>
|
||||
</%def>
|
||||
20
lms/templates/discussion/_content_renderer.html
Normal file
20
lms/templates/discussion/_content_renderer.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<%! import django_comment_client.helpers as helpers %>
|
||||
|
||||
<%def name="render_content(content)">
|
||||
${helpers.render_content(content)}
|
||||
</%def>
|
||||
|
||||
<%def name="render_content_with_comments(content)">
|
||||
<div class="${content['type']}" _id="${content['id']}" _discussion_id="${content.get('commentable_id')}" _author_id="${helpers.show_if(content['user_id'], content.get('anonymous'))}">
|
||||
${render_content(content)}
|
||||
${render_comments(content.get('children', []))}
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
<%def name="render_comments(comments)">
|
||||
<div class="comments">
|
||||
% for comment in comments:
|
||||
${render_content_with_comments(comment)}
|
||||
% endfor
|
||||
</div>
|
||||
</%def>
|
||||
@@ -1,4 +1,4 @@
|
||||
<%namespace name="renderer" file="_thread.html"/>
|
||||
<%namespace name="renderer" file="_content_renderer.html"/>
|
||||
|
||||
<section class="discussion forum-discussion" _id="${discussion_id}">
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<%include file="_sort.html" />
|
||||
<div class="threads">
|
||||
% for thread in threads:
|
||||
${renderer.render_thread(course_id, thread, show_comments=False)}
|
||||
${renderer.render_content_with_comments(thread)}
|
||||
% endfor
|
||||
</div>
|
||||
<%include file="_paginator.html" />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%namespace name="renderer" file="_thread.html"/>
|
||||
<%namespace name="renderer" file="_content_renderer.html"/>
|
||||
|
||||
<section class="discussion inline-discussion" _id="${discussion_id}">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<div class="threads">
|
||||
% for thread in threads:
|
||||
${renderer.render_thread(course_id, thread, show_comments=False)}
|
||||
${renderer.render_content_with_comments(thread)}
|
||||
% endfor
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
<%! from django.core.urlresolvers import reverse %>
|
||||
<%! from datehelper import time_ago_in_words %>
|
||||
<%! from dateutil.parser import parse %>
|
||||
<%! from django_comment_client.utils import pluralize %>
|
||||
<%! import urllib %>
|
||||
|
||||
<%!
|
||||
def show_if(text, condition):
|
||||
if condition:
|
||||
return text
|
||||
else:
|
||||
return ''
|
||||
%>
|
||||
|
||||
<%!
|
||||
def close_thread_text(content):
|
||||
if content.get('closed'):
|
||||
return 'Re-open thread'
|
||||
else:
|
||||
return 'Close thread'
|
||||
%>
|
||||
|
||||
<%def name="render_thread(course_id, thread, show_comments=False)">
|
||||
<div class="thread" _id="${thread['id']}" _discussion_id="${thread['commentable_id']}" _author_id="${show_if(thread['user_id'], thread.get('anonymous'))}">
|
||||
${render_content(thread, "thread", show_comments=show_comments)}
|
||||
% if show_comments:
|
||||
${render_comments(thread.get('children', []))}
|
||||
% endif
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
<%def name="render_comment(comment)">
|
||||
<div class="comment ${show_if('endorsed', comment.get('endorsed'))}" _id="${comment['id']}" _author_id="${show_if(comment['user_id'], comment.get('anonymous'))}">
|
||||
${render_content(comment, "comment")}
|
||||
<div class="comments">
|
||||
${render_comments(comment.get('children', []))}
|
||||
</div>
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
<%def name="render_comments(comments)">
|
||||
<div class="comments">
|
||||
% for comment in comments:
|
||||
${render_comment(comment)}
|
||||
% endfor
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
<%def name="render_content(content, type, **kwargs)">
|
||||
<div class="discussion-content">
|
||||
<div class="discussion-content-wrapper">
|
||||
${render_vote(content)}
|
||||
<div class="discussion-right-wrapper">
|
||||
<ul class="admin-actions">
|
||||
% if type == 'comment':
|
||||
<li><a href="javascript:void(0)" class="admin-endorse">Endorse</a></li>
|
||||
% endif
|
||||
<li><a href="javascript:void(0)" class="admin-edit">Edit</a></li>
|
||||
<li><a href="javascript:void(0)" class="admin-delete">Delete</a></li>
|
||||
% if type == "thread":
|
||||
<li><a class="discussion-openclose" id="discussion-openclose-${content['id']}" href="javascript:void(0);">${close_thread_text(content)}</a></li>
|
||||
% endif
|
||||
</ul>
|
||||
${render_title(content, type, **kwargs)}
|
||||
<div class="discussion-content-view">
|
||||
<a name="${content['id']}" style="width: 0; height: 0; padding: 0; border: none;"></a>
|
||||
<div class="content-body ${type}-body" id="content-body-${content['id']}">${(content.get('highlighted_body') or content['body']) | h}</div>
|
||||
<div class="content-raw-body ${type}-raw-body" style="display: none">${content['body'] | h}</div>
|
||||
${render_tags(content, type, **kwargs)}
|
||||
${render_bottom_bar(content, type, **kwargs)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
<%def name="render_title(content, type, **kwargs)">
|
||||
% if type == "thread":
|
||||
<a class="thread-title" name="${content['id']}" href="javascript:void(0)">${(content.get('highlighted_title') or content['title']) | h}</a>
|
||||
<div class="thread-raw-title" style="display: none">${content['title']}</div>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
<%def name="render_tags(content, type, **kwargs)">
|
||||
<%
|
||||
def url_for_tags(tags):
|
||||
return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id]) + '?' + urllib.urlencode({'tags': ",".join(tags)})
|
||||
%>
|
||||
% if type == "thread":
|
||||
<div class="thread-tags">
|
||||
% for tag in content['tags']:
|
||||
<a class="thread-tag" href="${url_for_tags([tag])}">${tag | h}</a>
|
||||
% endfor
|
||||
</div>
|
||||
<div class="thread-raw-tags" style="display: none">${",".join(content['tags']) | h}</div>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
<%def name="render_bottom_bar(content, type, **kwargs)">
|
||||
<div class="info">
|
||||
${render_info(content, type, **kwargs)}
|
||||
<ul class="discussion-actions">
|
||||
<li>${render_link("discussion-link discussion-reply discussion-reply-" + type, "Reply")}</li>
|
||||
<li><div class="follow-wrapper"></div></li>
|
||||
<li>${render_link("discussion-link discussion-permanent-link", "Permanent Link")}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
<%def name="render_info(content, type, **kwargs)">
|
||||
<%
|
||||
def url_for_user(user_id):
|
||||
return reverse('django_comment_client.forum.views.user_profile', args=[course_id, user_id])
|
||||
%>
|
||||
<div class="comment-time">
|
||||
${time_ago_in_words(parse(content['updated_at']))} ago by
|
||||
% if content['anonymous']:
|
||||
anonymous
|
||||
% else:
|
||||
<a href="${url_for_user(content['user_id'])}">${content['username']}</a>
|
||||
% endif
|
||||
</div>
|
||||
<div class="comment-count">
|
||||
% if content.get('comments_count', -1) >= 0:
|
||||
% if discussion_type == 'user':
|
||||
<a href="javascript:void(0)" class="discussion-show-comments first-time">Show all comments (${content['comments_count']} total)</a>
|
||||
% else:
|
||||
<a href="javascript:void(0)" class="discussion-show-comments">Show ${content['comments_count']} ${pluralize('comment', content['comments_count'])}</a>
|
||||
% endif
|
||||
% endif
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
<%def name="render_link(cls, html)">
|
||||
<a class="${cls}" href="javascript:void(0)">${html}</a>
|
||||
</%def>
|
||||
|
||||
<%def name="render_vote(content)">
|
||||
<div class="discussion-votes">
|
||||
${render_link("discussion-vote discussion-vote-up", "▲")}
|
||||
<div class="discussion-votes-point">${content['votes']['point']}</div>
|
||||
${render_link("discussion-vote discussion-vote-down", "▼")}
|
||||
</div>
|
||||
</%def>
|
||||
@@ -1,3 +1,3 @@
|
||||
<%namespace name="renderer" file="_thread.html"/>
|
||||
<%namespace name="renderer" file="_content_renderer.html"/>
|
||||
|
||||
${renderer.render_comment(content)}
|
||||
${renderer.render_content_with_comments(content)}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<%namespace name="renderer" file="_thread.html"/>
|
||||
<%namespace name="renderer" file="_content_renderer.html"/>
|
||||
|
||||
${renderer.render_thread(course_id, content)}
|
||||
${renderer.render_content_with_comments(content)}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<%namespace name="renderer" file="_thread.html"/>
|
||||
<%namespace name="renderer" file="_content_renderer.html"/>
|
||||
|
||||
${renderer.render_content(content, "comment")}
|
||||
${renderer.render_content(content)}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<%namespace name="renderer" file="_thread.html"/>
|
||||
<%namespace name="renderer" file="_content_renderer.html"/>
|
||||
|
||||
${renderer.render_content(content, "thread")}
|
||||
${renderer.render_content(content)}
|
||||
|
||||
Reference in New Issue
Block a user