Commit 69711a91 by Victor Shnayder

Fix inline discussion cohorting, debug logging

parent fb7614a8
......@@ -40,7 +40,18 @@ def is_commentable_cohorted(course_id, commentable_id):
Http404 if the course doesn't exist.
"""
course = courses.get_course_by_id(course_id)
ans = commentable_id in course.cohorted_discussions()
if not course.is_cohorted:
# this is the easy case :)
ans = False
elif commentable_id in course.top_level_discussion_topic_ids:
# top level discussions have to be manually configured as cohorted
# (default is not)
ans = commentable_id in course.cohorted_discussions()
else:
# inline discussions are cohorted by default
ans = True
log.debug("is_commentable_cohorted({0}, {1}) = {2}".format(course_id,
commentable_id,
ans))
......@@ -49,7 +60,11 @@ def is_commentable_cohorted(course_id, commentable_id):
def get_cohort(user, course_id):
c = _get_cohort(user, course_id)
log.debug("get_cohort({0}, {1}) = {2}".format(user, course_id, c.id))
log.debug("get_cohort({0}, {1}) = {2}".format(
user, course_id,
c.id if c is not None else None))
return c
def _get_cohort(user, course_id):
"""
......
......@@ -371,10 +371,21 @@ class CourseDescriptor(SequenceDescriptor):
return bool(config.get("cohorted"))
@property
def top_level_discussion_topic_ids(self):
"""
Return list of topic ids defined in course policy.
"""
topics = self.metadata.get("discussion_topics", {})
return [d["id"] for d in topics.values()]
@property
def cohorted_discussions(self):
"""
Return the set of discussions that is cohorted. It may be the empty
set.
Return the set of discussions that is explicitly cohorted. It may be
the empty set. Note that all inline discussions are automatically
cohorted based on the course's is_cohorted setting.
"""
config = self.metadata.get("cohort_config")
if config is None:
......
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