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


Python CourseEnrollment.enrollments_for_user方法代码示例

本文整理汇总了Python中student.models.CourseEnrollment.enrollments_for_user方法的典型用法代码示例。如果您正苦于以下问题:Python CourseEnrollment.enrollments_for_user方法的具体用法?Python CourseEnrollment.enrollments_for_user怎么用?Python CourseEnrollment.enrollments_for_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在student.models.CourseEnrollment的用法示例。


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

示例1: load_single_user_time

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
def load_single_user_time(request):
    user = User.objects.get(id=request.POST.get('user_id'))
    row = {}
    rts = record_time_store()
    external_time = 0
    all_external_time = 0
    user_id = str(user.id)
    course_id = str(request.POST.get('course_id', None))
    if course_id:
        for enrollment in CourseEnrollment.enrollments_for_user(user):
            try:
                course = course_from_id(enrollment.course_id)
                all_external_time += rts.get_external_time(user_id, course.id)
            except ItemNotFoundError:
                #log.error("User {0} enrolled in non-existent course {1}".format(p.user.username, enrollment.course_id))
                pass
        all_course_time, all_discussion_time, portfolio_time = rts.get_stats_time(user_id)
        adjustment_time_totle = rts.get_adjustment_time(user_id, 'total', None)
        external_time = rts.get_external_time(user_id, course_id)
        course_time = rts.get_course_time(user_id, course_id, 'courseware')
        discussion_time = rts.get_course_time(user_id, course_id, 'discussion')
        collaboration_time = all_discussion_time + portfolio_time
        all_course_time = all_course_time + all_external_time
        total_time = all_course_time + collaboration_time + adjustment_time_totle
    else:
        for enrollment in CourseEnrollment.enrollments_for_user(user):
            try:
                course = course_from_id(enrollment.course_id)
                external_time += rts.get_external_time(user_id, course.id)
            except ItemNotFoundError:
                #log.error("User {0} enrolled in non-existent course {1}".format(p.user.username, enrollment.course_id))
                pass
        adjustment_time_totle = rts.get_adjustment_time(user_id, 'total', None)
        course_time, discussion_time, portfolio_time = rts.get_stats_time(user_id)
        all_course_time = course_time + external_time
        collaboration_time = discussion_time + portfolio_time
        total_time = all_course_time + collaboration_time + adjustment_time_totle

    row = {"id": user_id,
           "total_time": study_time_format(total_time, True),
           "collaboration_time": study_time_format(collaboration_time, True),
           "discussion_time": study_time_format(discussion_time, True),
           "portfolio_time": study_time_format(portfolio_time, True),
           "external_time": study_time_format(external_time, True),
           "course_time": study_time_format(course_time, True)
           }

    return HttpResponse(json.dumps({'row': row}), content_type="application/json")
开发者ID:EduPepperPDTesting,项目名称:pepper2013-testing,代码行数:50,代码来源:time_report.py

示例2: _listen_for_id_verification_status_changed

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
def _listen_for_id_verification_status_changed(sender, user, **kwargs):  # pylint: disable=unused-argument
    """
    Catches a track change signal, determines user status,
    calls fire_ungenerated_certificate_task for passing grades
    """
    if not auto_certificate_generation_enabled():
        return

    user_enrollments = CourseEnrollment.enrollments_for_user(user=user)

    grade_factory = CourseGradeFactory()
    expected_verification_status = IDVerificationService.user_status(user)
    expected_verification_status = expected_verification_status['status']
    for enrollment in user_enrollments:
        if grade_factory.read(user=user, course=enrollment.course_overview).passed:
            if fire_ungenerated_certificate_task(user, enrollment.course_id, expected_verification_status):
                message = (
                    u'Certificate generation task initiated for {user} : {course} via track change ' +
                    u'with verification status of {status}'
                )
                log.info(message.format(
                    user=user.id,
                    course=enrollment.course_id,
                    status=expected_verification_status
                ))
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:27,代码来源:signals.py

示例3: __init__

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
    def __init__(self, site, user, enrollments=None, uuid=None, mobile_only=False):
        self.site = site
        self.user = user
        self.mobile_only = mobile_only

        self.enrollments = enrollments or list(CourseEnrollment.enrollments_for_user(self.user))
        self.enrollments.sort(key=lambda e: e.created, reverse=True)

        self.enrolled_run_modes = {}
        self.course_run_ids = []
        for enrollment in self.enrollments:
            # enrollment.course_id is really a CourseKey (╯ಠ_ಠ)╯︵ ┻━┻
            enrollment_id = unicode(enrollment.course_id)
            mode = enrollment.mode
            if mode == CourseMode.NO_ID_PROFESSIONAL_MODE:
                mode = CourseMode.PROFESSIONAL
            self.enrolled_run_modes[enrollment_id] = mode
            # We can't use dict.keys() for this because the course run ids need to be ordered
            self.course_run_ids.append(enrollment_id)

        self.entitlements = list(CourseEntitlement.unexpired_entitlements_for_user(self.user))
        self.course_uuids = [str(entitlement.course_uuid) for entitlement in self.entitlements]

        self.course_grade_factory = CourseGradeFactory()

        if uuid:
            self.programs = [get_programs(uuid=uuid)]
        else:
            self.programs = attach_program_detail_url(get_programs(self.site), self.mobile_only)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:31,代码来源:utils.py

示例4: get_course_enrollment_pairs

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
def get_course_enrollment_pairs(user, course_org_filter, org_filter_out_set):
    """
    Get the relevant set of (Course, CourseEnrollment) pairs to be displayed on
    a student's dashboard.
    """
    for enrollment in CourseEnrollment.enrollments_for_user(user):
        try:
            course = course_from_id(enrollment.course_id)

            # if we are in a Microsite, then filter out anything that is not
            # attributed (by ORG) to that Microsite
            if course_org_filter and course_org_filter != course.location.org:
                continue
            # Conversely, if we are not in a Microsite, then let's filter out any enrollments
            # with courses attributed (by ORG) to Microsites
            elif course.location.org in org_filter_out_set:
                continue
            ## offline course filter
            elif course.course_audit == 0:
                continue

            yield (course, enrollment)
        except ItemNotFoundError:
            log.error("User {0} enrolled in non-existent course {1}"
                      .format(user.username, enrollment.course_id))
开发者ID:XiaodunServerGroup,项目名称:ddyedx,代码行数:27,代码来源:views.py

示例5: validate_adjustment_time

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
def validate_adjustment_time(rts, user_id, type, adjustment_time, course_id):
    type_time = 0
    external_time = 0
    adjustment_time = int(adjustment_time)
    if adjustment_time < 0:
        if type == 'total':
            user = User.objects.get(id=user_id)
            for enrollment in CourseEnrollment.enrollments_for_user(user):
                try:
                    course = course_from_id(enrollment.course_id)
                    external_time += rts.get_external_time(user_id, course.id)
                except ItemNotFoundError:
                    log.error("User {0} enrolled in non-existent course {1}".format(user.username, enrollment.course_id))

            course_time, discussion_time, portfolio_time = rts.get_stats_time(user_id)
            adjustment_time_totle = rts.get_adjustment_time(user_id, 'total', None)
            type_time = course_time + discussion_time + portfolio_time + external_time + adjustment_time_totle
        else:
            if type == 'external':
                type_time = rts.get_external_time(user_id, course_id)
            else:
                type_time = rts.get_course_time(user_id, course_id, type)
        if type_time + adjustment_time < 0:
            return False
    return True
开发者ID:EduPepperPDTesting,项目名称:pepper2013-testing,代码行数:27,代码来源:time_report.py

示例6: midcourse_reverify_dash

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
def midcourse_reverify_dash(request):
    """
    Shows the "course reverification dashboard", which displays the reverification status (must reverify,
    pending, approved, failed, etc) of all courses in which a student has a verified enrollment.
    """
    user = request.user
    course_enrollment_pairs = []
    for enrollment in CourseEnrollment.enrollments_for_user(user):
        try:
            course_enrollment_pairs.append((modulestore().get_course(enrollment.course_id), enrollment))
        except ItemNotFoundError:
            log.error("User {0} enrolled in non-existent course {1}"
                      .format(user.username, enrollment.course_id))

    statuses = ["approved", "pending", "must_reverify", "denied"]

    reverifications = reverification_info(course_enrollment_pairs, user, statuses)

    context = {
        "user_full_name": user.profile.name,
        'reverifications': reverifications,
        'referer': request.META.get('HTTP_REFERER'),
        'billing_email': settings.PAYMENT_SUPPORT_EMAIL,
    }
    return render_to_response("verify_student/midcourse_reverify_dash.html", context)
开发者ID:nouaya,项目名称:edx-platform,代码行数:27,代码来源:views.py

示例7: get

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
    def get(self, request):
        context = {
            'platform_name': configuration_helpers.get_value('platform_name', settings.PLATFORM_NAME),
            'zendesk_api_host': settings.ZENDESK_URL,
            'access_token': 'DUMMY_ACCESS_TOKEN',  # LEARNER-3450
            'custom_fields': settings.ZENDESK_CUSTOM_FIELDS
        }

        # Tag all issues with LMS to distinguish channel in Zendesk; requested by student support team
        zendesk_tags = ['LMS']

        # Per edX support, we would like to be able to route feedback items by site via tagging
        current_site_name = configuration_helpers.get_value("SITE_NAME")
        if current_site_name:
            current_site_name = current_site_name.replace(".", "_")
            zendesk_tags.append("site_name_{site}".format(site=current_site_name))

        if request.user.is_authenticated():
            context['user_enrollments'] = CourseEnrollment.enrollments_for_user(request.user)
            enterprise_learner_data = enterprise_api.get_enterprise_learner_data(site=request.site, user=request.user)
            if enterprise_learner_data:
                zendesk_tags.append('enterprise_learner')

        context['zendesk_tags'] = zendesk_tags

        return render_to_response("support/contact_us.html", context)
开发者ID:lduarte1991,项目名称:edx-platform,代码行数:28,代码来源:contact_us.py

示例8: users

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
 def users(self, request, pk):
     """
     Add a User to an Organization
     """
     if request.method == 'GET':
         include_course_counts = request.QUERY_PARAMS.get('include_course_counts', None)
         users = User.objects.filter(organizations=pk)
         response_data = []
         if users:
             for user in users:
                 serializer = UserSerializer(user)
                 user_data = serializer.data
                 if str2bool(include_course_counts):
                     enrollments = CourseEnrollment.enrollments_for_user(user).count()
                     user_data['course_count'] = enrollments
                 response_data.append(user_data)
         return Response(response_data, status=status.HTTP_200_OK)
     else:
         user_id = request.DATA.get('id')
         try:
             user = User.objects.get(id=user_id)
         except ObjectDoesNotExist:
             message = 'User {} does not exist'.format(user_id)
             return Response({"detail": message}, status.HTTP_400_BAD_REQUEST)
         organization = self.get_object()
         organization.users.add(user)
         organization.save()
         return Response({}, status=status.HTTP_201_CREATED)
开发者ID:fmyzjs,项目名称:edx-serverapi,代码行数:30,代码来源:views.py

示例9: post

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
 def post(self, request):
     telname = request.POST.get('telname')
     user = TeleramReg.objects.filter(telname=telname).first()
     if user:
         courses = CourseEnrollment.enrollments_for_user(user)
         return JsonResponse({'courses': courses})
     else:
         return JsonResponse({'courses': 'none'})
开发者ID:raccoongang,项目名称:raccbot_client,代码行数:10,代码来源:views.py

示例10: test_success

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
    def test_success(self):
        self.login_and_enroll()

        serialized = CourseEnrollmentSerializer(CourseEnrollment.enrollments_for_user(self.user)[0]).data  # pylint: disable=no-member
        self.assertEqual(serialized['course']['video_outline'], None)
        self.assertEqual(serialized['course']['name'], self.course.display_name)
        self.assertEqual(serialized['course']['number'], self.course.id.course)
        self.assertEqual(serialized['course']['org'], self.course.id.org)
开发者ID:CrRinko,项目名称:edx-platform,代码行数:10,代码来源:tests.py

示例11: test_success

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
 def test_success(self):
     serialized = CourseEnrollmentSerializer(
         CourseEnrollment.enrollments_for_user(self.user)[0],
         context={'request': self.request},
     ).data
     self.assertEqual(serialized['course']['name'], self.course.display_name)
     self.assertEqual(serialized['course']['number'], self.course.id.course)
     self.assertEqual(serialized['course']['org'], self.course.id.org)
开发者ID:fangqian,项目名称:edx-platform,代码行数:10,代码来源:tests.py

示例12: test_course_serializer

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
 def test_course_serializer(self):
     self.client.login(username=self.username, password=self.password)
     self._enroll(self.course)
     serialized = CourseEnrollmentSerializer(CourseEnrollment.enrollments_for_user(self.user)[0]).data  # pylint: disable=E1101
     self.assertEqual(serialized['course']['video_outline'], None)
     self.assertEqual(serialized['course']['name'], self.course.display_name)
     self.assertEqual(serialized['course']['number'], self.course.id.course)
     self.assertEqual(serialized['course']['org'], self.course.id.org)
开发者ID:OmarIthawi,项目名称:edx-platform,代码行数:10,代码来源:tests.py

示例13: get

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
    def get(self, request):
        """GET /api/team/v0/team_membership"""
        specified_username_or_team = False
        username = None
        team_id = None
        requested_course_id = None
        requested_course_key = None
        accessible_course_ids = None

        if 'course_id' in request.QUERY_PARAMS:
            requested_course_id = request.QUERY_PARAMS['course_id']
            try:
                requested_course_key = CourseKey.from_string(requested_course_id)
            except InvalidKeyError:
                return Response(status=status.HTTP_404_NOT_FOUND)

        if 'team_id' in request.QUERY_PARAMS:
            specified_username_or_team = True
            team_id = request.QUERY_PARAMS['team_id']
            try:
                team = CourseTeam.objects.get(team_id=team_id)
            except CourseTeam.DoesNotExist:
                return Response(status=status.HTTP_404_NOT_FOUND)
            if requested_course_key is not None and requested_course_key != team.course_id:
                return Response(status=status.HTTP_400_BAD_REQUEST)
            if not has_team_api_access(request.user, team.course_id):
                return Response(status=status.HTTP_404_NOT_FOUND)

        if 'username' in request.QUERY_PARAMS:
            specified_username_or_team = True
            username = request.QUERY_PARAMS['username']
            if not request.user.is_staff:
                enrolled_courses = (
                    CourseEnrollment.enrollments_for_user(request.user).values_list('course_id', flat=True)
                )
                staff_courses = (
                    CourseAccessRole.objects.filter(user=request.user, role='staff').values_list('course_id', flat=True)
                )
                accessible_course_ids = [item for sublist in (enrolled_courses, staff_courses) for item in sublist]
                if requested_course_id is not None and requested_course_id not in accessible_course_ids:
                    return Response(status=status.HTTP_400_BAD_REQUEST)

        if not specified_username_or_team:
            return Response(
                build_api_error(ugettext_noop("username or team_id must be specified.")),
                status=status.HTTP_400_BAD_REQUEST
            )

        course_keys = None
        if requested_course_key is not None:
            course_keys = [requested_course_key]
        elif accessible_course_ids is not None:
            course_keys = [CourseKey.from_string(course_string) for course_string in accessible_course_ids]

        queryset = CourseTeamMembership.get_memberships(username, course_keys, team_id)
        page = self.paginate_queryset(queryset)
        serializer = self.get_pagination_serializer(page)
        return Response(serializer.data)  # pylint: disable=maybe-no-member
开发者ID:ahmedaljazzar,项目名称:edx-platform,代码行数:60,代码来源:views.py

示例14: __init__

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
    def __init__(self, user, enrollments=None):
        self.user = user

        self.enrollments = enrollments or list(CourseEnrollment.enrollments_for_user(self.user))
        self.enrollments.sort(key=lambda e: e.created, reverse=True)

        # enrollment.course_id is really a CourseKey (╯ಠ_ಠ)╯︵ ┻━┻
        self.course_run_ids = [unicode(e.course_id) for e in self.enrollments]

        self.programs = attach_program_detail_url(get_programs())
开发者ID:shevious,项目名称:edx-platform,代码行数:12,代码来源:utils.py

示例15: field_dictionary

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enrollments_for_user [as 别名]
    def field_dictionary(self, **kwargs):
        """ add course if provided otherwise add courses in which the user is enrolled in """
        field_dictionary = super(LmsSearchFilterGenerator, self).field_dictionary(**kwargs)
        if not kwargs.get('user'):
            field_dictionary['course'] = []
        elif not kwargs.get('course_id'):
            user_enrollments = CourseEnrollment.enrollments_for_user(kwargs['user'])
            field_dictionary['course'] = [unicode(enrollment.course_id) for enrollment in user_enrollments]

        return field_dictionary
开发者ID:escolaglobal,项目名称:edx-platform,代码行数:12,代码来源:lms_filter_generator.py


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