当前位置: 首页>>代码示例>>Python>>正文


Python views.change_enrollment函数代码示例

本文整理汇总了Python中student.views.change_enrollment函数的典型用法代码示例。如果您正苦于以下问题:Python change_enrollment函数的具体用法?Python change_enrollment怎么用?Python change_enrollment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了change_enrollment函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: change_enrollment

def change_enrollment(request):
    """
    This change_enrollment overloads default one. When 'enroll' action is
    specified it tries to lookup in configuration whether some url for the 
    enrolling course is set. If it is so, client is redirected to this url, 
    otherwise standard action is executed and nothing changes.
    """
    # Execute original handler
    response = student_views.change_enrollment(request)
    
    action = request.POST.get("enrollment_action")
    course_id = request.POST.get("course_id")
    callback_url = None

    # Try to lookup redirect url for course if we are enrolling
    if action is not None and action == 'enroll':
        if course_id is not None:
            try:
                callback_url = settings.ENROLL_URL_CALLBACK[course_id]
            except:
                log.debug('No url for course {0} is specified in cofiguration.'.format(course_id))
         
    # If url IS specified -- redirect there
    if callback_url is not None:
      return HttpResponse(callback_url)
    
    # Return original response
    return response
开发者ID:Gfirey,项目名称:edx-platform,代码行数:28,代码来源:views.py

示例2: test_enrollment_limit_by_domain

    def test_enrollment_limit_by_domain(self):
        """
            Tests that the enrollmentDomain setting is properly limiting enrollment to those who have
            the proper external auth
        """

        # create 2 course, one with limited enrollment one without
        shib_course = CourseFactory.create(org='Stanford', number='123', display_name='Shib Only')
        shib_course.enrollment_domain = 'shib:https://idp.stanford.edu/'
        self.store.update_item(shib_course, '**replace_user**')

        open_enroll_course = CourseFactory.create(org='MITx', number='999', display_name='Robot Super Course')
        open_enroll_course.enrollment_domain = ''
        self.store.update_item(open_enroll_course, '**replace_user**')

        # create 3 kinds of students, external_auth matching shib_course, external_auth not matching, no external auth
        shib_student = UserFactory.create()
        shib_student.save()
        extauth = ExternalAuthMap(external_id='[email protected]',
                                  external_email='',
                                  external_domain='shib:https://idp.stanford.edu/',
                                  external_credentials="",
                                  user=shib_student)
        extauth.save()

        other_ext_student = UserFactory.create()
        other_ext_student.username = "teststudent2"
        other_ext_student.email = "[email protected]"
        other_ext_student.save()
        extauth = ExternalAuthMap(external_id='[email protected]',
                                  external_email='',
                                  external_domain='shib:https://other.edu/',
                                  external_credentials="",
                                  user=other_ext_student)
        extauth.save()

        int_student = UserFactory.create()
        int_student.username = "teststudent3"
        int_student.email = "[email protected]"
        int_student.save()

        # Tests the two case for courses, limited and not
        for course in [shib_course, open_enroll_course]:
            for student in [shib_student, other_ext_student, int_student]:
                request = self.request_factory.post('/change_enrollment')
                request.POST.update({'enrollment_action': 'enroll',
                                     'course_id': course.id.to_deprecated_string()})
                request.user = student
                response = change_enrollment(request)
                # If course is not limited or student has correct shib extauth then enrollment should be allowed
                if course is open_enroll_course or student is shib_student:
                    self.assertEqual(response.status_code, 200)
                    self.assertTrue(CourseEnrollment.is_enrolled(student, course.id))
                    # Clean up
                    CourseEnrollment.unenroll(student, course.id)
                else:
                    self.assertEqual(response.status_code, 400)
                    self.assertFalse(CourseEnrollment.is_enrolled(student, course.id))
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:58,代码来源:test_shib.py

示例3: test_change_enrollment_add_to_cart

 def test_change_enrollment_add_to_cart(self):
     request = self.req_factory.post(reverse('change_enrollment'), {'course_id': self.course.id,
                                                                    'enrollment_action': 'add_to_cart'})
     request.user = self.user
     response = change_enrollment(request)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, reverse('shoppingcart.views.show_cart'))
     self.assertTrue(shoppingcart.models.PaidCourseRegistration.contained_in_order(
         shoppingcart.models.Order.get_cart_for_user(self.user), self.course.id))
开发者ID:DavidGrahamFL,项目名称:edx-platform,代码行数:9,代码来源:tests.py

示例4: test_change_enrollment_add_to_cart

 def test_change_enrollment_add_to_cart(self):
     request = self.req_factory.post(
         reverse("change_enrollment"),
         {"course_id": self.course.id.to_deprecated_string(), "enrollment_action": "add_to_cart"},
     )
     request.user = self.user
     response = change_enrollment(request)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, reverse("shoppingcart.views.show_cart"))
     self.assertTrue(
         shoppingcart.models.PaidCourseRegistration.contained_in_order(
             shoppingcart.models.Order.get_cart_for_user(self.user), self.course.id
         )
     )
开发者ID:gtomar,项目名称:edx-platform,代码行数:14,代码来源:tests.py

示例5: test_change_enrollment_add_to_cart

    def test_change_enrollment_add_to_cart(self):
        request = self.req_factory.post(
            reverse('change_enrollment'), {
                'course_id': self.course.id.to_deprecated_string(),
                'enrollment_action': 'add_to_cart'
            }
        )

        # Add a session to the request
        SessionMiddleware().process_request(request)
        request.session.save()

        request.user = self.user
        response = change_enrollment(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, reverse('shoppingcart.views.show_cart'))
        self.assertTrue(shoppingcart.models.PaidCourseRegistration.contained_in_order(
            shoppingcart.models.Order.get_cart_for_user(self.user), self.course.id))
开发者ID:CDOT-EDX,项目名称:edx-platform,代码行数:18,代码来源:tests.py

示例6: test_enrollment_limit_by_domain

    def test_enrollment_limit_by_domain(self):
        """
            Tests that the enrollmentDomain setting is properly limiting enrollment to those who have
            the proper external auth
        """

        # create 2 course, one with limited enrollment one without
        shib_course = CourseFactory.create(org="Stanford", number="123", display_name="Shib Only")
        shib_course.enrollment_domain = "shib:https://idp.stanford.edu/"
        self.store.update_item(shib_course, "**replace_user**")

        open_enroll_course = CourseFactory.create(org="MITx", number="999", display_name="Robot Super Course")
        open_enroll_course.enrollment_domain = ""
        self.store.update_item(open_enroll_course, "**replace_user**")

        # create 3 kinds of students, external_auth matching shib_course, external_auth not matching, no external auth
        shib_student = UserFactory.create()
        shib_student.save()
        extauth = ExternalAuthMap(
            external_id="[email protected]",
            external_email="",
            external_domain="shib:https://idp.stanford.edu/",
            external_credentials="",
            user=shib_student,
        )
        extauth.save()

        other_ext_student = UserFactory.create()
        other_ext_student.username = "teststudent2"
        other_ext_student.email = "[email protected]"
        other_ext_student.save()
        extauth = ExternalAuthMap(
            external_id="[email protected]",
            external_email="",
            external_domain="shib:https://other.edu/",
            external_credentials="",
            user=other_ext_student,
        )
        extauth.save()

        int_student = UserFactory.create()
        int_student.username = "teststudent3"
        int_student.email = "[email protected]"
        int_student.save()

        # Tests the two case for courses, limited and not
        for course in [shib_course, open_enroll_course]:
            for student in [shib_student, other_ext_student, int_student]:
                request = self.request_factory.post("/change_enrollment")
                request.POST.update({"enrollment_action": "enroll", "course_id": course.id})
                request.user = student
                response = change_enrollment(request)
                # If course is not limited or student has correct shib extauth then enrollment should be allowed
                if course is open_enroll_course or student is shib_student:
                    self.assertEqual(response.status_code, 200)
                    self.assertTrue(CourseEnrollment.is_enrolled(student, course.id))
                    # Clean up
                    CourseEnrollment.unenroll(student, course.id)
                else:
                    self.assertEqual(response.status_code, 400)
                    self.assertFalse(CourseEnrollment.is_enrolled(student, course.id))
开发者ID:XiaodunServerGroup,项目名称:medicalmooc,代码行数:61,代码来源:test_shib.py

示例7: course_enroll

def course_enroll(request):
    response = change_enrollment(request)
    if isinstance(response, (HttpResponseBadRequest, HttpResponseForbidden)):
        return JsonResponse({ 'status': False, 'reason': response.content })
    else:
        return JsonResponse({ 'status': True })
开发者ID:louyihua,项目名称:edx-buaa,代码行数:6,代码来源:views.py


注:本文中的student.views.change_enrollment函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。