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


Python roles.CourseCcxCoachRole类代码示例

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


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

示例1: setUp

 def setUp(self):
     """Set up a course, coach, ccx and user"""
     super(TestGetCCXFromCCXLocator, self).setUp()
     self.course = CourseFactory.create()
     coach = self.coach = AdminFactory.create()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(coach)
开发者ID:andela-ijubril,项目名称:edx-platform,代码行数:7,代码来源:test_utils.py

示例2: test_create_ccx

    def test_create_ccx(self, ccx_name='New CCX'):
        """
        Create CCX. Follow redirect to coach dashboard, confirm we see
        the coach dashboard for the new CCX.
        """

        self.make_coach()
        url = reverse(
            'create_ccx',
            kwargs={'course_id': unicode(self.course.id)})

        response = self.client.post(url, {'name': ccx_name})
        self.assertEqual(response.status_code, 302)
        url = response.get('location')  # pylint: disable=no-member
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        # Get the ccx_key
        path = urlparse.urlparse(url).path
        resolver = resolve(path)
        ccx_key = resolver.kwargs['course_id']

        course_key = CourseKey.from_string(ccx_key)

        self.assertTrue(CourseEnrollment.is_enrolled(self.coach, course_key))
        self.assertTrue(re.search('id="ccx-schedule"', response.content))

        # check if the max amount of student that can be enrolled has been overridden
        ccx = CustomCourseForEdX.objects.get()
        course_enrollments = get_override_for_ccx(ccx, self.course, 'max_student_enrollments_allowed')
        self.assertEqual(course_enrollments, settings.CCX_MAX_STUDENTS_ALLOWED)

        # assert ccx creator has role=ccx_coach
        role = CourseCcxCoachRole(course_key)
        self.assertTrue(role.has_user(self.coach))
开发者ID:Woutifier,项目名称:edx-platform,代码行数:35,代码来源:test_views.py

示例3: has_ccx_coach_role

def has_ccx_coach_role(user, course_key):
    """
    Check if user is a coach on this ccx.

    Arguments:
        user (User): the user whose descriptor access we are checking.
        course_key (CCXLocator): Key to CCX.

    Returns:
        bool: whether user is a coach on this ccx or not.
    """
    if hasattr(course_key, 'ccx'):
        ccx_id = course_key.ccx
        role = CourseCcxCoachRole(course_key)

        if role.has_user(user):
            list_ccx = CustomCourseForEdX.objects.filter(
                course_id=course_key.to_course_locator(),
                coach=user
            )
            if list_ccx.exists():
                coach_ccx = list_ccx[0]
                return str(coach_ccx.id) == ccx_id
    else:
        raise CCXLocatorValidationException("Invalid CCX key. To verify that "
                                            "user is a coach on CCX, you must provide key to CCX")
    return False
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:27,代码来源:access.py

示例4: setUp

 def setUp(self):
     super(CCXCoachTabTestCase, self).setUp()
     self.user = UserFactory.create()
     for course in [self.ccx_enabled_course, self.ccx_disabled_course]:
         CourseEnrollmentFactory.create(user=self.user, course_id=course.id)
         role = CourseCcxCoachRole(course.id)
         role.add_users(self.user)
开发者ID:Akif-Vohra,项目名称:edx-platform,代码行数:7,代码来源:test_views.py

示例5: test_patch_detail

 def test_patch_detail(self):
     """
     Test for successful patch
     """
     outbox = self.get_outbox()
     # create a new coach
     new_coach = AdminFactory.create()
     data = {
         'max_students_allowed': 111,
         'display_name': 'CCX Title',
         'coach_email': new_coach.email
     }
     resp = self.client.patch(self.detail_url, data, format='json', HTTP_AUTHORIZATION=self.auth)
     self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
     ccx_from_db = CustomCourseForEdX.objects.get(id=self.ccx.id)
     self.assertEqual(ccx_from_db.max_student_enrollments_allowed, data['max_students_allowed'])
     self.assertEqual(ccx_from_db.display_name, data['display_name'])
     self.assertEqual(ccx_from_db.coach.email, data['coach_email'])
     # check that the coach user has coach role on the master course
     coach_role_on_master_course = CourseCcxCoachRole(self.master_course_key)
     self.assertTrue(coach_role_on_master_course.has_user(new_coach))
     # check that the coach has been enrolled in the ccx
     ccx_course_object = courses.get_course_by_id(self.ccx_key)
     self.assertTrue(
         CourseEnrollment.objects.filter(course_id=ccx_course_object.id, user=new_coach).exists()
     )
     # check that an email has been sent to the coach
     self.assertEqual(len(outbox), 1)
     self.assertIn(new_coach.email, outbox[0].recipients())  # pylint: disable=no-member
开发者ID:alabs,项目名称:edx-platform,代码行数:29,代码来源:test_views.py

示例6: setUp

 def setUp(self):
     super(CCXCoachTabTestCase, self).setUp()
     self.course = CourseFactory.create()
     self.user = UserFactory.create()
     CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id)
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(self.user)
开发者ID:ariestiyansyah,项目名称:edx-platformX,代码行数:7,代码来源:test_views.py

示例7: setUp

    def setUp(self):
        """
        Set up tests
        """
        super(TestCCXGrades, self).setUp()

        # Create instructor account
        self.coach = coach = AdminFactory.create()
        self.client.login(username=coach.username, password="test")

        # Create CCX
        role = CourseCcxCoachRole(self._course.id)
        role.add_users(coach)
        ccx = CcxFactory(course_id=self._course.id, coach=self.coach)

        # override course grading policy and make last section invisible to students
        override_field_for_ccx(
            ccx,
            self._course,
            "grading_policy",
            {
                "GRADER": [{"drop_count": 0, "min_count": 2, "short_label": "HW", "type": "Homework", "weight": 1}],
                "GRADE_CUTOFFS": {"Pass": 0.75},
            },
        )
        override_field_for_ccx(ccx, self.sections[-1], "visible_to_staff_only", True)

        # create a ccx locator and retrieve the course structure using that key
        # which emulates how a student would get access.
        self.ccx_key = CCXLocator.from_course_locator(self._course.id, ccx.id)
        self.course = get_course_by_id(self.ccx_key, depth=None)
        setup_students_and_grades(self)
        self.client.login(username=coach.username, password="test")
        self.addCleanup(RequestCache.clear_request_cache)
开发者ID:huzaifaqamer,项目名称:edx-platform,代码行数:34,代码来源:test_views.py

示例8: setUp

 def setUp(self):
     super(TestRenderMessageToString, self).setUp()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=self.course.id, coach=coach)
     self.course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id)
开发者ID:jolyonb,项目名称:edx-platform,代码行数:7,代码来源:test_enrollment.py

示例9: test_post_list

 def test_post_list(self):
     """
     Test the creation of a CCX
     """
     outbox = self.get_outbox()
     data = {
         'master_course_id': self.master_course_key_str,
         'max_students_allowed': 111,
         'display_name': 'CCX Test Title',
         'coach_email': self.coach.email
     }
     resp = self.client.post(self.list_url, data, format='json', HTTP_AUTHORIZATION=self.auth)
     self.assertEqual(resp.status_code, status.HTTP_201_CREATED)
     # check if the response has at least the same data of the request
     for key, val in data.iteritems():
         self.assertEqual(resp.data.get(key), val)  # pylint: disable=no-member
     self.assertIn('ccx_course_id', resp.data)  # pylint: disable=no-member
     # check that the new CCX actually exists
     course_key = CourseKey.from_string(resp.data.get('ccx_course_id'))  # pylint: disable=no-member
     ccx_course = CustomCourseForEdX.objects.get(pk=course_key.ccx)
     self.assertEqual(
         unicode(CCXLocator.from_course_locator(ccx_course.course.id, ccx_course.id)),
         resp.data.get('ccx_course_id')  # pylint: disable=no-member
     )
     # check that the coach user has coach role on the master course
     coach_role_on_master_course = CourseCcxCoachRole(self.master_course_key)
     self.assertTrue(coach_role_on_master_course.has_user(self.coach))
     # check that the coach has been enrolled in the ccx
     ccx_course_object = courses.get_course_by_id(course_key)
     self.assertTrue(
         CourseEnrollment.objects.filter(course_id=ccx_course_object.id, user=self.coach).exists()
     )
     # check that an email has been sent to the coach
     self.assertEqual(len(outbox), 1)
     self.assertIn(self.coach.email, outbox[0].recipients())  # pylint: disable=no-member
开发者ID:alabs,项目名称:edx-platform,代码行数:35,代码来源:test_views.py

示例10: wrapper

    def wrapper(request, course_id):
        """
        Wraps the view function, performing access check, loading the course,
        and modifying the view's call signature.
        """
        course_key = CourseKey.from_string(course_id)
        ccx = None
        if isinstance(course_key, CCXLocator):
            ccx_id = course_key.ccx
            ccx = CustomCourseForEdX.objects.get(pk=ccx_id)
            course_key = ccx.course_id

        role = CourseCcxCoachRole(course_key)
        if not role.has_user(request.user):
            return HttpResponseForbidden(
                _('You must be a CCX Coach to access this view.'))

        course = get_course_by_id(course_key, depth=None)

        # if there is a ccx, we must validate that it is the ccx for this coach
        if ccx is not None:
            coach_ccx = get_ccx_for_coach(course, request.user)
            if coach_ccx is None or coach_ccx.id != ccx.id:
                return HttpResponseForbidden(
                    _('You must be the coach for this ccx to access this view')
                )

        return view(request, course, ccx)
开发者ID:andela-ijubril,项目名称:edx-platform,代码行数:28,代码来源:views.py

示例11: test_ccx_tab_visibility_for_instructor_when_coach_master_course

 def test_ccx_tab_visibility_for_instructor_when_coach_master_course(self):
     """
     Instructor can view ccx coach dashboard only if he is coach on master course.
     """
     instructor = self.make_instructor()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(instructor)
     self.assertTrue(self.check_ccx_tab(self.course, instructor))
开发者ID:chaitanyakale,项目名称:edx-platform,代码行数:8,代码来源:test_views.py

示例12: setUp

 def setUp(self):
     """Set up a course, coach, ccx and user"""
     super(TestGetMembershipTriplets, self).setUp()
     self.course = CourseFactory.create()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=self.course.id, coach=coach)
开发者ID:benpatterson,项目名称:edx-platform,代码行数:8,代码来源:test_utils.py

示例13: setUp

 def setUp(self):
     """common setup for all tests"""
     super(TestCCX, self).setUp()
     self.course = course = CourseFactory.create()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=course.id, coach=coach)
开发者ID:alabs,项目名称:edx-platform,代码行数:8,代码来源:test_models.py

示例14: test_ccx_tab_visibility_for_staff_when_coach_master_course

 def test_ccx_tab_visibility_for_staff_when_coach_master_course(self):
     """
     Staff can view ccx coach dashboard only if he is coach on master course.
     """
     staff = self.make_staff()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(staff)
     self.assertTrue(self.check_ccx_tab(self.course, staff))
开发者ID:chaitanyakale,项目名称:edx-platform,代码行数:8,代码来源:test_views.py

示例15: is_enabled

 def is_enabled(cls, course, user=None):
     """
     Returns true if CCX has been enabled and the specified user is a coach
     """
     if not user:
         return True
     if not settings.FEATURES.get('CUSTOM_COURSES_EDX', False) or not course.enable_ccx:
         return False
     role = CourseCcxCoachRole(course.id)
     return role.has_user(user)
开发者ID:189140879,项目名称:edx-platform,代码行数:10,代码来源:plugins.py


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