fixed recent threads & tags links
This commit is contained in:
@@ -33,21 +33,22 @@ def include_mustache_templates():
|
||||
file_contents = map(read_file, filter(valid_file_name, os.listdir(mustache_dir)))
|
||||
return '\n'.join(map(wrap_in_tag, map(strip_file_name, file_contents)))
|
||||
|
||||
|
||||
def permalink(content):
|
||||
if content['type'] == 'thread':
|
||||
return reverse('django_comment_client.forum.views.single_thread',
|
||||
args=[content['course_id'], content['commentable_id'], content['id']])
|
||||
else:
|
||||
return reverse('django_comment_client.forum.views.single_thread',
|
||||
args=[content['course_id'], content['commentable_id'], content['thread_id']]) + '#' + content['id']
|
||||
|
||||
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', [])),
|
||||
'permalink': permalink(content),
|
||||
}
|
||||
print content_info
|
||||
if content['type'] == 'thread':
|
||||
content_info['permalink'] = reverse('django_comment_client.forum.views.single_thread',
|
||||
args=[content['course_id'], content['commentable_id'], content['id']])
|
||||
else:
|
||||
content_info['permalink'] = reverse('django_comment_client.forum.views.single_thread',
|
||||
args=[content['course_id'], content['commentable_id'], content['thread_id']]) + '#' + content['id']
|
||||
|
||||
context = {
|
||||
'content': merge_dict(content, content_info),
|
||||
content['type']: True,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from .utils import url_for_tags as _url_for_tags
|
||||
|
||||
import django.core.urlresolvers as urlresolvers
|
||||
import urllib
|
||||
import sys
|
||||
@@ -14,7 +16,7 @@ def url_for_user(content, user_id):
|
||||
return urlresolvers.reverse('django_comment_client.forum.views.user_profile', args=[content['course_id'], user_id])
|
||||
|
||||
def url_for_tags(content, tags): # assume that attribute 'tags' is in the format u'a, b, c'
|
||||
return urlresolvers.reverse('django_comment_client.forum.views.forum_form_discussion', args=[content['course_id']]) + '?' + urllib.urlencode({'tags': tags})
|
||||
return _url_for_tags(content['course_id'], tags)
|
||||
|
||||
def close_thread_text(content):
|
||||
if content.get('closed'):
|
||||
|
||||
@@ -7,12 +7,14 @@ from django.http import HttpResponse
|
||||
from django.utils import simplejson
|
||||
from django.db import connection
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django_comment_client.permissions import check_permissions_by_view
|
||||
from mitxmako import middleware
|
||||
|
||||
import logging
|
||||
import operator
|
||||
import itertools
|
||||
import urllib
|
||||
import pystache_custom as pystache
|
||||
|
||||
|
||||
@@ -188,6 +190,10 @@ def get_annotated_content_infos(course_id, thread, user, user_info):
|
||||
annotate(thread)
|
||||
return infos
|
||||
|
||||
# put this method in utils.py to avoid circular import dependency between helpers and mustache_helpers
|
||||
def url_for_tags(course_id, tags):
|
||||
return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id]) + '?' + urllib.urlencode({'tags': tags})
|
||||
|
||||
def render_mustache(template_name, dictionary, *args, **kwargs):
|
||||
template = middleware.lookup['main'].get_template(template_name).source
|
||||
return pystache.render(template, dictionary)
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
<%! import django_comment_client.helpers as helpers %>
|
||||
|
||||
% if recent_active_threads:
|
||||
<article class="discussion-sidebar-following sidebar-module">
|
||||
<header>
|
||||
<h4>Following</h4>
|
||||
<a href="#" class="sidebar-view-all">view all ›</a>
|
||||
<!--<a href="#" class="sidebar-view-all">view all ›</a>-->
|
||||
</header>
|
||||
<ol class="discussion-sidebar-following-list">
|
||||
% for thread in recent_active_threads:
|
||||
<li><a href="#"><span class="sidebar-following-name">${thread['title']}</span> <span class="sidebar-vote-count">${thread['votes']['point']}</span></a></li>
|
||||
<li><a href="${helpers.permalink(thread)}"><span class="sidebar-following-name">${thread['title']}</span> <span class="sidebar-vote-count">${thread['votes']['point']}</span></a></li>
|
||||
% endfor
|
||||
<ol>
|
||||
</article>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
<%! import django_comment_client.helpers as helpers %>
|
||||
|
||||
% if trending_tags:
|
||||
<article class="discussion-sidebar-tags sidebar-module">
|
||||
<header>
|
||||
@@ -5,7 +7,7 @@
|
||||
</header>
|
||||
<ol class="discussion-sidebar-tags-list">
|
||||
% for tag, count in trending_tags:
|
||||
<li><a href="#" class="thread-tag">${tag}</a><span class="sidebar-tag-count">×${count}</span></li>
|
||||
<li><a href="${helpers.url_for_tags(course.id, tag)}" class="thread-tag">${tag}</a><span class="sidebar-tag-count">×${count}</span></li>
|
||||
% endfor
|
||||
<ol>
|
||||
</article>
|
||||
|
||||
Reference in New Issue
Block a user