Commit 79b0ff62 by David Ormsbee

Merge pull request #512 from MITx/feature/rocky/discussion

fixed recent threads & tags links
parents daf33dbc 53c3d60e
...@@ -209,16 +209,28 @@ def single_thread(request, course_id, discussion_id, thread_id): ...@@ -209,16 +209,28 @@ def single_thread(request, course_id, discussion_id, thread_id):
else: else:
course = get_course_with_access(request.user, course_id, 'load') course = get_course_with_access(request.user, course_id, 'load')
recent_active_threads = cc.search_recent_active_threads(
course_id,
recursive=False,
query_params={'follower_id': request.user.id},
)
trending_tags = cc.search_trending_tags(
course_id,
)
context = { context = {
'discussion_id': discussion_id, 'discussion_id': discussion_id,
'csrf': csrf(request)['csrf_token'], 'csrf': csrf(request)['csrf_token'],
'init': '', 'init': '',
'content': render_single_thread(request, discussion_id, course_id, thread_id), 'content': render_single_thread(request, discussion_id, course_id, thread_id),
'course': course, 'course': course,
'recent_active_threads': recent_active_threads,
'trending_tags': trending_tags,
'course_id': course.id, 'course_id': course.id,
} }
return render_to_response('discussion/index.html', context) return render_to_response('discussion/single_thread.html', context)
def user_profile(request, course_id, user_id): def user_profile(request, course_id, user_id):
......
...@@ -33,21 +33,22 @@ def include_mustache_templates(): ...@@ -33,21 +33,22 @@ def include_mustache_templates():
file_contents = map(read_file, filter(valid_file_name, os.listdir(mustache_dir))) 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))) 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={}): def render_content(content, additional_context={}):
content_info = { content_info = {
'displayed_title': content.get('highlighted_title') or content.get('title', ''), 'displayed_title': content.get('highlighted_title') or content.get('title', ''),
'displayed_body': content.get('highlighted_body') or content.get('body', ''), 'displayed_body': content.get('highlighted_body') or content.get('body', ''),
'raw_tags': ','.join(content.get('tags', [])), '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 = { context = {
'content': merge_dict(content, content_info), 'content': merge_dict(content, content_info),
content['type']: True, content['type']: True,
......
from .utils import url_for_tags as _url_for_tags
import django.core.urlresolvers as urlresolvers import django.core.urlresolvers as urlresolvers
import urllib import urllib
import sys import sys
...@@ -14,7 +16,7 @@ def url_for_user(content, user_id): ...@@ -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]) 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' 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): def close_thread_text(content):
if content.get('closed'): if content.get('closed'):
......
...@@ -7,12 +7,14 @@ from django.http import HttpResponse ...@@ -7,12 +7,14 @@ from django.http import HttpResponse
from django.utils import simplejson from django.utils import simplejson
from django.db import connection from django.db import connection
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse
from django_comment_client.permissions import check_permissions_by_view from django_comment_client.permissions import check_permissions_by_view
from mitxmako import middleware from mitxmako import middleware
import logging import logging
import operator import operator
import itertools import itertools
import urllib
import pystache_custom as pystache import pystache_custom as pystache
...@@ -188,6 +190,10 @@ def get_annotated_content_infos(course_id, thread, user, user_info): ...@@ -188,6 +190,10 @@ def get_annotated_content_infos(course_id, thread, user, user_info):
annotate(thread) annotate(thread)
return infos 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): def render_mustache(template_name, dictionary, *args, **kwargs):
template = middleware.lookup['main'].get_template(template_name).source template = middleware.lookup['main'].get_template(template_name).source
return pystache.render(template, dictionary) return pystache.render(template, dictionary)
<%! import django_comment_client.helpers as helpers %>
% if recent_active_threads: % if recent_active_threads:
<article class="discussion-sidebar-following sidebar-module"> <article class="discussion-sidebar-following sidebar-module">
<header> <header>
<h4>Following</h4> <h4>Following</h4>
<a href="#" class="sidebar-view-all">view all &rsaquo;</a> <!--<a href="#" class="sidebar-view-all">view all &rsaquo;</a>-->
</header> </header>
<ol class="discussion-sidebar-following-list"> <ol class="discussion-sidebar-following-list">
% for thread in recent_active_threads: % 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 % endfor
<ol> <ol>
</article> </article>
......
<%! import django_comment_client.helpers as helpers %>
% if trending_tags: % if trending_tags:
<article class="discussion-sidebar-tags sidebar-module"> <article class="discussion-sidebar-tags sidebar-module">
<header> <header>
...@@ -5,7 +7,7 @@ ...@@ -5,7 +7,7 @@
</header> </header>
<ol class="discussion-sidebar-tags-list"> <ol class="discussion-sidebar-tags-list">
% for tag, count in trending_tags: % for tag, count in trending_tags:
<li><a href="#" class="thread-tag">${tag}</a><span class="sidebar-tag-count">&times;${count}</span></li> <li><a href="${helpers.url_for_tags(course.id, tag)}" class="thread-tag">${tag}</a><span class="sidebar-tag-count">&times;${count}</span></li>
% endfor % endfor
<ol> <ol>
</article> </article>
......
<%inherit file="../main.html" />
<%namespace name='static' file='../static_content.html'/>
<%block name="bodyclass">discussion</%block>
<%block name="title"><title>Discussion – MITx 6.002x</title></%block>
<%block name="headextra">
<%static:css group='course'/>
<%include file="_js_head_dependencies.html" />
</%block>
<%block name="js_extra">
<%include file="_js_body_dependencies.html" />
<%static:js group='discussion'/>
</%block>
<%include file="../courseware/course_navigation.html" args="active_page='discussion'" />
<section class="container">
<div class="course-wrapper">
<section aria-label="Course Navigation" class="course-index">
<nav>
<article class="sidebar-module discussion-sidebar">
</article>
<%include file="_recent_active_posts.html" />
<%include file="_trending_tags.html" />
</nav>
</section>
<section class="course-content">
${content}
</section>
</div>
</section>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment