Exemple #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'])
        )
Exemple #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
Exemple #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']))
Exemple #4
0
 def check_organizer(*args, **kwargs):
     request = args[0]
     course_id = kwargs.get("course_id")
     course_uri = course_model.course_id2uri(course_id)
     user_uri = "/uri/user/{0}".format(request.user.username)
     cohort = course_model.get_course_cohort(course_uri)
     organizer = course_model.is_cohort_organizer(user_uri, cohort["uri"])
     organizer |= request.user.is_superuser
     if not organizer:
         return http.HttpResponseForbidden(_("You need to be a course organizer."))
     return function(*args, **kwargs)
Exemple #5
0
 def check_organizer(*args, **kwargs):
     request = args[0]
     course_id = kwargs.get('course_id')
     course_uri = course_model.course_id2uri(course_id)
     user_uri = "/uri/user/{0}".format(request.user.username)
     cohort = course_model.get_course_cohort(course_uri)
     organizer = course_model.is_cohort_organizer(user_uri, cohort['uri'])
     organizer |= request.user.is_superuser
     if not organizer:
         return http.HttpResponseForbidden(
             _("You need to be a course organizer."))
     return function(*args, **kwargs)
Exemple #6
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
Exemple #7
0
def course_add_organizer( request, course_id, username ):
    cohort_uri = course_model.get_course_cohort_uri(course_id)
    user_uri = u"/uri/user/{0}".format(request.user.username)
    is_organizer = course_model.is_cohort_organizer(
        user_uri, cohort_uri
    )
    if not is_organizer and not request.user.is_superuser:
        messages.error( request, _("Only other organizers can add a new organizer") )
        return course_slug_redirect( request, course_id)
    new_organizer_uri = u"/uri/user/{0}".format(username)
    course_model.remove_user_from_cohort(cohort_uri, new_organizer_uri)
    course_model.add_user_to_cohort(cohort_uri, new_organizer_uri, "ORGANIZER")

    #TODO
    redirect_url = reverse('courses_people', kwargs={'course_id': course_id})
    return http.HttpResponseRedirect(redirect_url)
Exemple #8
0
def course_add_organizer( request, course_id, username ):
    cohort_uri = course_model.get_course_cohort_uri(course_id)
    user_uri = u"/uri/user/{0}".format(request.user.username)
    is_organizer = course_model.is_cohort_organizer(
        user_uri, cohort_uri
    )
    if not is_organizer and not request.user.is_superuser:
        messages.error( request, _("Only other organizers can add a new organizer") )
        return course_slug_redirect( request, course_id)
    new_organizer_uri = u"/uri/user/{0}".format(username)
    course_model.remove_user_from_cohort(cohort_uri, new_organizer_uri)
    course_model.add_user_to_cohort(cohort_uri, new_organizer_uri, "ORGANIZER")

    #TODO
    redirect_url = reverse('courses_people', kwargs={'course_id': course_id})
    return http.HttpResponseRedirect(redirect_url)
Exemple #9
0
def course_leave( request, course_id, username ):
    cohort_uri = course_model.get_course_cohort_uri(course_id)
    user_uri = u"/uri/user/{0}".format(request.user.username)
    is_organizer = course_model.is_cohort_organizer(
        user_uri, cohort_uri
    )
    removed = False
    error_message = _("Could not remove user")
    if username == request.user.username or is_organizer:
        removed, error_message = course_model.remove_user_from_cohort(
            cohort_uri, u"/uri/user/{0}".format(username)
        )

    if not removed:
        messages.error(request, error_message)

    if is_organizer:
        redirect_url = reverse('courses_people', kwargs={'course_id': course_id})
        return http.HttpResponseRedirect(redirect_url)

    return course_slug_redirect( request, course_id)
Exemple #10
0
def course_leave( request, course_id, username ):
    cohort_uri = course_model.get_course_cohort_uri(course_id)
    user_uri = u"/uri/user/{0}".format(request.user.username)
    # TODO site admin should also be able to remove users
    is_organizer = course_model.is_cohort_organizer(
        user_uri, cohort_uri
    )
    removed = False
    error_message = _("Could not remove user")
    if username == request.user.username or is_organizer:
        removed, error_message = course_model.remove_user_from_cohort(
            cohort_uri, u"/uri/user/{0}".format(username)
        )

    if not removed:
        messages.error(request, error_message)

    if is_organizer:
        redirect_url = reverse('courses_people', kwargs={'course_id': course_id})
        return http.HttpResponseRedirect(redirect_url)

    return course_slug_redirect( request, course_id)