Commit 3a9542eb by Arjun Singh

Move function; stop shadowing map; add todo about caching for _DISCUSSIONINFO

parent 3f58e1dd
...@@ -19,11 +19,11 @@ import urllib ...@@ -19,11 +19,11 @@ import urllib
import pystache_custom as pystache import pystache_custom as pystache
# TODO these should be cached via django's caching rather than in-memory globals
_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}
...@@ -67,6 +67,16 @@ def get_discussion_category_map(course): ...@@ -67,6 +67,16 @@ 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
...@@ -111,15 +121,6 @@ def initialize_discussion_info(course): ...@@ -111,15 +121,6 @@ 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"]}
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)
_DISCUSSIONINFO = {} _DISCUSSIONINFO = {}
......
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