Fix inline discussion cohorting, debug logging

This commit is contained in:
Victor Shnayder
2013-01-24 16:58:19 -05:00
parent fb7614a81c
commit 69711a91ff
2 changed files with 30 additions and 4 deletions

View File

@@ -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):
"""

View File

@@ -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: