Exemple #1
0
def import_project( request, project_slug ):
    from projects.models import Project
    project = get_object_or_404(Project, slug=project_slug)
    from courses import utils
    course = utils.import_project(project, project.name[:3])
    cohort = course_model.get_course_cohort(course['uri'])
    user_uri = u"/uri/user/{0}".format(request.user.username)
    course_model.add_user_to_cohort(cohort['uri'], user_uri, "ORGANIZER")
    return course_slug_redirect(request, course['id'])
Exemple #2
0
def import_project( request, project_slug ):
    from projects.models import Project
    project = get_object_or_404(Project, slug=project_slug)
    from courses import utils
    course = utils.import_project(project, project.name[:3])
    cohort = course_model.get_course_cohort(course['uri'])
    user_uri = u"/uri/user/{0}".format(request.user.username)
    course_model.add_user_to_cohort(cohort['uri'], user_uri, "ORGANIZER")
    return course_slug_redirect(request, course['id'])
Exemple #3
0
def course_signup( request, course_id ):
    #NOTE: consider using cohort_id in URL to avoid cohort lookup
    cohort = course_model.get_course_cohort( course_id )
    user_uri = u"/uri/user/{0}".format(request.user.username)
    if cohort['signup'] == "OPEN":
        course_model.add_user_to_cohort(cohort['uri'], user_uri, "LEARNER", True)
        messages.success(request, _("You are now signed up for this course."))
    else:
        messages.error(request, _("This course isn't open for signup."))
    return course_slug_redirect( request, course_id )
Exemple #4
0
def course_signup( request, course_id ):
    #NOTE: consider using cohort_id in URL to avoid cohort lookup
    cohort = course_model.get_course_cohort( course_id )
    user_uri = u"/uri/user/{0}".format(request.user.username)
    if cohort['signup'] == "OPEN":
        course_model.add_user_to_cohort(cohort['uri'], user_uri, "LEARNER", True)
        messages.success(request, _("You are now signed up for this course."))
    else:
        messages.error(request, _("This course isn't open for signup."))
    return course_slug_redirect( request, course_id )
Exemple #5
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 #6
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 #7
0
def course_add_user( request, course_id ):
    cohort_uri = course_model.get_course_cohort_uri(course_id)
    redirect_url = reverse('courses_people', kwargs={'course_id': course_id})
    username = request.POST.get('username', None)

    if not username:
        messages.error(request, _("Please select a user to add."))
        return http.HttpResponseRedirect(redirect_url)

    user_uri = u"/uri/user/{0}".format(username)
    try:
        course_model.add_user_to_cohort(cohort_uri, user_uri, "LEARNER")
        messages.success(request, _("User added."))
    except course_model.ResourceNotFoundException as e:
        messages.error(request, _("User does not exist."))

    return http.HttpResponseRedirect(redirect_url)
Exemple #8
0
def course_add_user( request, course_id ):
    cohort_uri = course_model.get_course_cohort_uri(course_id)
    redirect_url = reverse('courses_people', kwargs={'course_id': course_id})
    username = request.POST.get('username', None)

    if not username:
        messages.error(request, _("Please select a user to add."))
        return http.HttpResponseRedirect(redirect_url)

    user_uri = u"/uri/user/{0}".format(username)
    try:
        course_model.add_user_to_cohort(cohort_uri, user_uri, "LEARNER")
        messages.success(request, _("User added."))
    except course_model.ResourceNotFoundException as e:
        messages.error(request, _("User does not exist."))

    return http.HttpResponseRedirect(redirect_url)
Exemple #9
0
 def test_add_user(self):
     cohort = course_model.get_course_cohort(self.course['uri'])
     course_model.add_user_to_cohort(
         cohort['uri'], '/uri/user/bob', 'ORGANIZER')
     cohort2 = course_model.get_course_cohort(self.course['uri'])
     self.assertEqual(len(cohort['users']), len(cohort2['users'])-1)
Exemple #10
0
 def test_add_user(self):
     cohort = course_model.get_course_cohort(self.course["uri"])
     course_model.add_user_to_cohort(cohort["uri"], "/uri/user/bob", "ORGANIZER")
     cohort2 = course_model.get_course_cohort(self.course["uri"])
     self.assertEqual(len(cohort["users"]), len(cohort2["users"]) - 1)
Exemple #11
0
 def test_add_user(self):
     cohort = course_model.get_course_cohort(self.course['uri'])
     course_model.add_user_to_cohort(cohort['uri'], '/uri/user/bob',
                                     'ORGANIZER')
     cohort2 = course_model.get_course_cohort(self.course['uri'])
     self.assertEqual(len(cohort['users']), len(cohort2['users']) - 1)