def _build_digest_course(course_id, course_content, user_course_info): """ Transforms thread/item data from the comments service's response for a specific user and course. The threads returned will be filtered by a group-level access check. """ if _should_skip_org(course_id): return DigestCourse(course_id, []) else: return DigestCourse( course_id, [ _build_digest_thread(thread_id, course_id, thread_content) for thread_id, thread_content in course_content.iteritems() if ( # the user is allowed to "see all cohorts" in the course, or user_course_info['see_all_cohorts'] or # the thread is not associated with a group, or thread_content.get('group_id') is None or # the user's cohort_id matches the thread's group_id user_course_info['cohort_id'] == thread_content.get('group_id') ) ] )
def _test_unicode_data(self, input_text, expected_text, expected_html=None): user = { "id": "0", "username": "******", } digest = Digest([ DigestCourse(TEST_COURSE_ID, [ DigestThread("0", TEST_COURSE_ID, TEST_COMMENTABLE, input_text, [DigestItem("test content", None, None)]) ]) ]) (rendered_text, rendered_html) = render_digest(user, digest, "Test Title", "Test Description") self.assertIn(expected_text, rendered_text) self.assertIn(expected_html if expected_html else expected_text, rendered_html)
def course(course_id, course_dict): return DigestCourse(course_id, [ Parser.thread(thread_id, course_id, thread_content) for thread_id, thread_content in course_dict.iteritems() ])