Example #1
0
    def render_to_fragment(self, request, course_id=None, **kwargs):  # lint-amnesty, pylint: disable=arguments-differ
        """
        Renders the course's home page as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_with_access(request.user,
                                        'load',
                                        course_key,
                                        check_if_enrolled=True)
        course_url_name = default_course_url_name(course.id)
        course_url = reverse(course_url_name,
                             kwargs={'course_id': str(course.id)})

        ordered_updates = get_ordered_updates(request, course)
        plain_html_updates = ''
        if ordered_updates:
            plain_html_updates = self.get_plain_html_updates(request, course)

        # Render the course home fragment
        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'course_url': course_url,
            'updates': ordered_updates,
            'plain_html_updates': plain_html_updates,
            'disable_courseware_js': True,
        }
        html = render_to_string(
            'course_experience/course-updates-fragment.html', context)
        return Fragment(html)
Example #2
0
 def test_replace_urls(self):
     """We should be replacing static URLs with course specific ones."""
     self.create_course_update("<img src='/static/img.png'>")
     updates = get_ordered_updates(self.request, self.course)
     expected = "<img src='/asset-v1:{org}+{course}+{run}+type@asset+block/img.png'>".format(
         org=self.course.id.org,
         course=self.course.id.course,
         run=self.course.id.run,
     )
     self.assertEqual(updates[0]['content'], expected)
Example #3
0
 def test_update_structure(self):
     """Test that returned item dictionary is as we expect."""
     content = '<em>HTML Content</em>'
     date = 'January 1, 2000'
     self.create_course_update(content, date=date)
     updates = get_ordered_updates(self.request, self.course)
     self.assertListEqual(updates, [{
         'id': 1,
         'content': content,
         'date': date,
         'status': 'visible',
     }])
Example #4
0
 def test_ordered_updates(self):
     """Test that order of returned items follows our rules."""
     first = self.create_course_update('2000', date='January 1, 2000')
     second = self.create_course_update('2017', date='January 1, 2017')
     third = self.create_course_update('Also 2017', date='January 1, 2017')
     injected = self.create_course_update('Injected out of order',
                                          date='January 1, 2010')
     ill_formed = self.create_course_update(
         'Ill-formed date is parsed as now()', date='foobar')
     self.create_course_update('Deleted is ignored', deleted=True)
     updates = get_ordered_updates(self.request, self.course)
     self.assertListEqual(updates,
                          [ill_formed, third, second, injected, first])
Example #5
0
 def test_ordered_update_includes_dismissed_updates(self):
     """Ordered update list should still have dismissed updates."""
     self.create_course_update('Dismissed')
     dismiss_current_update_for_user(self.request, self.course)
     updates = get_ordered_updates(self.request, self.course)
     self.assertEqual(len(updates), 1)
Example #6
0
 def has_updates(self, request, course):  # lint-amnesty, pylint: disable=bad-classmethod-argument
     return len(get_ordered_updates(request, course)) > 0
Example #7
0
 def has_updates(self, request, course):
     return len(get_ordered_updates(request, course)) > 0