Commit 1ad64fb6 by Arjun Singh Committed by Matthew Mongeau

populate dropdown

parent 246fbbda
...@@ -249,6 +249,7 @@ def single_thread(request, course_id, discussion_id, thread_id): ...@@ -249,6 +249,7 @@ 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')
category_map = utils.get_discussion_category_map(course)
threads, query_params = get_threads(request, course_id) threads, query_params = get_threads(request, course_id)
recent_active_threads = cc.search_recent_active_threads( recent_active_threads = cc.search_recent_active_threads(
...@@ -275,6 +276,7 @@ def single_thread(request, course_id, discussion_id, thread_id): ...@@ -275,6 +276,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
'course_id': course.id, 'course_id': course.id,
'thread_id': thread_id, 'thread_id': thread_id,
'threads': json.dumps(threads), 'threads': json.dumps(threads),
'category_map': category_map,
} }
return render_to_response('discussion/single_thread.html', context) return render_to_response('discussion/single_thread.html', context)
......
from collections import defaultdict from collections import defaultdict
from importlib import import_module from importlib import import_module
from courseware.models import StudentModuleCache from courseware.models import StudentModuleCache
from courseware.module_render import get_module from courseware.module_render import get_module
...@@ -25,7 +25,6 @@ import pystache_custom as pystache ...@@ -25,7 +25,6 @@ import pystache_custom as pystache
_FULLMODULES = None _FULLMODULES = None
_DISCUSSIONINFO = None _DISCUSSIONINFO = None
def extract(dic, keys): def extract(dic, keys):
return {k: dic.get(k) for k in keys} return {k: dic.get(k) for k in keys}
...@@ -55,11 +54,11 @@ def get_discussion_id_map(course): ...@@ -55,11 +54,11 @@ def get_discussion_id_map(course):
initialize_discussion_info(course) initialize_discussion_info(course)
return _DISCUSSIONINFO['id_map'] return _DISCUSSIONINFO['id_map']
def get_discussion_title(request, course, discussion_id): def get_discussion_title(course, discussion_id):
global _DISCUSSIONINFO global _DISCUSSIONINFO
if not _DISCUSSIONINFO: if not _DISCUSSIONINFO:
initialize_discussion_info(course) initialize_discussion_info(course)
title = _DISCUSSIONINFO['id_map'].get(discussion_id, {}).get('title', '(no title)') title = _DISCUSSIONINFO['by_id'].get(discussion_id, {}).get('title', '(no title)')
return title return title
def get_discussion_category_map(course): def get_discussion_category_map(course):
...@@ -69,16 +68,6 @@ def get_discussion_category_map(course): ...@@ -69,16 +68,6 @@ def get_discussion_category_map(course):
initialize_discussion_info(course) initialize_discussion_info(course)
return _DISCUSSIONINFO['category_map'] return _DISCUSSIONINFO['category_map']
def sort_map_entries(category_map):
things = []
for title, entry in category_map["entries"].items():
things.append((title, entry))
for title, category in category_map["subcategories"].items():
things.append((title, category))
sort_map_entries(category_map["subcategories"][title])
category_map["children"] = [x[0] for x in sorted(things, key=lambda x: x[1]["sort_key"])]
def initialize_discussion_info(course): def initialize_discussion_info(course):
global _DISCUSSIONINFO global _DISCUSSIONINFO
...@@ -123,14 +112,41 @@ def initialize_discussion_info(course): ...@@ -123,14 +112,41 @@ def initialize_discussion_info(course):
node[level]["entries"][entry["title"]] = {"id": entry["id"], node[level]["entries"][entry["title"]] = {"id": entry["id"],
"sort_key": entry["sort_key"]} "sort_key": entry["sort_key"]}
<<<<<<< HEAD
sort_map_entries(category_map)
=======
def sort_map_entries(map):
things = []
for title, entry in map["entries"].items():
things.append((title, entry))
for title, category in map["subcategories"].items():
things.append((title, category))
sort_map_entries(map["subcategories"][title])
map["children"] = [x[0] for x in sorted(things, key=lambda x: x[1]["sort_key"])]
sort_map_entries(category_map) sort_map_entries(category_map)
#for level in category_map["subcategories"].values():
# sort_map_entries(level)
>>>>>>> populate dropdown
_DISCUSSIONINFO = {} _DISCUSSIONINFO = {}
_DISCUSSIONINFO['id_map'] = discussion_id_map _DISCUSSIONINFO['id_map'] = discussion_id_map
<<<<<<< HEAD
_DISCUSSIONINFO['category_map'] = category_map
=======
_DISCUSSIONINFO['category_map'] = category_map _DISCUSSIONINFO['category_map'] = category_map
# TODO delete me when you've used me
#_DISCUSSIONINFO['categorized']['General'] = [{
# 'title': 'General',
# 'discussion_id': url_course_id,
# 'category': 'General',
#}]
>>>>>>> populate dropdown
class JsonResponse(HttpResponse): class JsonResponse(HttpResponse):
def __init__(self, data=None): def __init__(self, data=None):
content = simplejson.dumps(data) content = simplejson.dumps(data)
......
<%def name="render_dropdown(map)">
% for child in map["children"]:
% if child in map["entries"]:
${render_entry(map["entries"], child)}
%else:
${render_category(map["subcategories"], child)}
%endif
%endfor
</%def>
<%def name="render_entry(entries, entry)">
<li><a href="#"><span class="board-name" data-discussion_id="${entries[entry]}">${entry}</span> <span class="unread">1,248</span></a></li>
</%def>
<%def name="render_category(categories, category)">
<li>
<a href="#"><span class="board-name">${category}</span></a>
<ul>
${render_dropdown(categories[category])}
</ul>
</li>
</%def>
<ul class="board-drop-menu">
${render_dropdown(category_map)}
</ul>
...@@ -132,24 +132,7 @@ ...@@ -132,24 +132,7 @@
<a href="#" class="board-drop-icon"></a> <a href="#" class="board-drop-icon"></a>
<a href="#" class="board-drop-btn"><span class="current-board">Homework / Week 1</span> <span class="drop-arrow">▾</span></a> <a href="#" class="board-drop-btn"><span class="current-board">Homework / Week 1</span> <span class="drop-arrow">▾</span></a>
</div> </div>
<ul class="board-drop-menu"> <%include file="_filter_dropdown.html" />
<li><a href="#"><span class="board-name">All</span> <span class="unread">1,248</span></a></li>
<li><a href="#"><span class="board-name">Following</span></a></li>
<li><a href="#"><span class="board-name">General</span> <span class="unread">124</span></a></li>
<li>
<a href="#"><span class="board-name">Homework</span> <span class="unread">27</span></a>
<ul>
<li><a href="#"><span class="board-name">Week 1</span> <span class="unread">24</span></a></li>
<li>
<a href="#"><span class="board-name">Week 2</span> <span class="unread">27</span></a>
<ul>
<li><a href="#"><span class="board-name">Problem 1</span> <span class="unread">14</span></a></li>
<li><a href="#"><span class="board-name">Problem 2</span> <span class="unread">13</span></a></li>
</ul>
</li>
</ul>
</li>
</ul>
<div class="search"> <div class="search">
<form class="post-search"> <form class="post-search">
<input type="text" placeholder="Search all discussions" class="post-search-field"> <input type="text" placeholder="Search all discussions" class="post-search-field">
......
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