Esempio n. 1
0
    def test_course_creation(self):
        course = course_model.create_course(
            **{
                "title": "A test course",
                "hashtag": "ATC-1",
                "description": "This course is all about ABC",
                "language": "en",
                "organizer_uri": '/uri/user/testuser'
            }
        )

        self.assertTrue(not course == None)

        # test that about content was created
        about = content_model.get_content(course['about_uri'])
        self.assertTrue(not about == None)
        self.assertEqual(about['title'], "About")

        # test that a cohort was created
        cohort = course_model.get_course_cohort(course['uri'])
        self.assertTrue(not cohort == None)

        self.assertTrue(
            course_model.user_in_cohort('/uri/user/testuser', cohort['uri'])
        )
        self.assertTrue(
            course_model.is_cohort_organizer('/uri/user/testuser', cohort['uri'])
        )
Esempio n. 2
0
def _populate_course_context( request, course_id, context ):
    course_uri = course_model.course_id2uri(course_id)
    course = _get_course_or_404(course_uri)
    context['course'] = course
    context['course_url'] = request.get_full_path()
    if 'image_uri' in course:
        context['course']['image'] = media_model.get_image(course['image_uri'])

    #NOTE if performance becomes a problem dont fetch cohort
    cohort = course_model.get_course_cohort(course_uri)
    context['cohort'] = cohort
    user_uri = "/uri/user/{0}".format(request.user.username)
    context['organizer'] = course_model.is_cohort_organizer(
        user_uri, cohort['uri']
    )
    context['organizer'] |= request.user.is_superuser
    context['can_edit'] = context['organizer'] and not course['status'] == 'archived'
    if course_model.user_in_cohort(user_uri, cohort['uri']):
        if not context['organizer']:
            context['show_leave_course'] = True
        context['learner'] = True
    elif cohort['signup'] == "OPEN":
        context['show_signup'] = True

    return context
Esempio n. 3
0
    def test_course_creation(self):
        course = course_model.create_course(
            **{
                "title": "A test course",
                "hashtag": "ATC-1",
                "description": "This course is all about ABC",
                "language": "en",
                "organizer_uri": '/uri/user/testuser'
            })

        self.assertTrue(not course == None)

        # test that about content was created
        about = content_model.get_content(course['about_uri'])
        self.assertTrue(not about == None)
        self.assertEqual(about['title'], "About")

        # test that a cohort was created
        cohort = course_model.get_course_cohort(course['uri'])
        self.assertTrue(not cohort == None)

        self.assertTrue(
            course_model.user_in_cohort('/uri/user/testuser', cohort['uri']))
        self.assertTrue(
            course_model.is_cohort_organizer('/uri/user/testuser',
                                             cohort['uri']))
Esempio n. 4
0
def _populate_course_context( request, course_id, context ):
    course_uri = course_model.course_id2uri(course_id)
    course = _get_course_or_404(course_uri)
    course['author'] = course['author_uri'].strip('/').split('/')[-1]
    context['course'] = course
    context['course_url'] = reverse('courses_show',
        kwargs={'course_id': course['id'], 'slug': course['slug']}
    )
    if 'image_uri' in course:
        context['course']['image'] = media_model.get_image(course['image_uri'])

    #NOTE if performance becomes a problem dont fetch cohort
    cohort = course_model.get_course_cohort(course_uri)
    context['cohort'] = cohort
    user_uri = u"/uri/user/{0}".format(request.user.username)
    context['organizer'] = course_model.is_cohort_organizer(
        user_uri, cohort['uri']
    )
    context['organizer'] |= request.user.is_superuser
    context['admin'] = request.user.is_superuser
    context['can_edit'] = context['organizer'] and not course['status'] == 'archived'
    context['trusted_user'] = request.user.has_perm('users.trusted_user')
    if course_model.user_in_cohort(user_uri, cohort['uri']):
        if not context['organizer']:
            context['show_leave_course'] = True
        context['learner'] = True
    elif cohort['signup'] == "OPEN":
        context['show_signup'] = True

    try:
        course_lists = learn_model.get_lists_for_course(reverse(
            'courses_slug_redirect',
            kwargs={'course_id': course_id}
        ))
        f = lambda l: l['name'] not in ['drafts', 'listed', 'archived']
        context['lists'] = filter(f, course_lists)
    except:
        log.error("Could not get lists for course!")

    if 'based_on_uri' in course:
        course['based_on'] = course_model.get_course(course['based_on_uri'])

    context['meta_data'] = lrmi_model.get_tags(course_uri)
    if 'educational_alignment' in context['meta_data']:
        context['educational_alignment'] = json.loads(context['meta_data']['educational_alignment'])
        del context['meta_data']['educational_alignment']

    return context