Beispiel #1
0
 def get_object(self):
     # Because we're serializing data from both Elasticsearch and MySQL into
     # the same JSON object, we have to pass both sources of data in a dict
     # to our custom course metadata serializer.
     return {
         'es_data': RosterEntry.get_course_metadata(self.course_id),
         'engagement_ranges': ModuleEngagementMetricRanges.objects.filter(course_id=self.course_id)
     }
 def get_object(self):
     # Because we're serializing data from both Elasticsearch and MySQL into
     # the same JSON object, we have to pass both sources of data in a dict
     # to our custom course metadata serializer.
     return {
         'es_data': RosterEntry.get_course_metadata(self.course_id),
         'engagement_ranges': ModuleEngagementMetricRanges.objects.filter(course_id=self.course_id)
     }
    def get_queryset(self):
        """
        Fetches the user list and last updated from elasticsearch returned returned
        as a an array of dicts with fields "learner" and "last_updated".
        """
        self._validate_query_params()
        query_params = self.request.QUERY_PARAMS

        order_by = query_params.get('order_by')
        sort_order = query_params.get('sort_order')
        sort_policies = [{'order_by': order_by, 'sort_order': sort_order}]

        # Ordering by problem_attempts_per_completed can be ambiguous because
        # values could be infinite (e.g. divide by zero) if no problems were completed.
        # Instead, secondary sorting by attempt_ratio_order will produce a sensible ordering.
        if order_by == 'problem_attempts_per_completed':
            sort_policies.append({
                'order_by':
                'attempt_ratio_order',
                'sort_order':
                'asc' if sort_order == 'desc' else 'desc'
            })

        params = {
            'segments':
            split_query_argument(query_params.get('segments')),
            'ignore_segments':
            split_query_argument(query_params.get('ignore_segments')),
            'cohort':
            query_params.get('cohort'),
            'enrollment_mode':
            query_params.get('enrollment_mode'),
            'text_search':
            query_params.get('text_search'),
            'sort_policies':
            sort_policies,
        }
        # Remove None values from `params` so that we don't overwrite default
        # parameter values in `get_users_in_course`.
        params = {key: val for key, val in params.items() if val is not None}
        try:
            return RosterEntry.get_users_in_course(self.course_id, **params)
        except ValueError as e:
            raise ParameterValueError(e.message)
    def get_queryset(self):
        """
        Fetches the user list and last updated from elasticsearch returned returned
        as a an array of dicts with fields "learner" and "last_updated".
        """
        self._validate_query_params()
        query_params = self.request.QUERY_PARAMS

        order_by = query_params.get('order_by')
        sort_order = query_params.get('sort_order')
        sort_policies = [{
            'order_by': order_by,
            'sort_order': sort_order
        }]

        # Ordering by problem_attempts_per_completed can be ambiguous because
        # values could be infinite (e.g. divide by zero) if no problems were completed.
        # Instead, secondary sorting by attempt_ratio_order will produce a sensible ordering.
        if order_by == 'problem_attempts_per_completed':
            sort_policies.append({
                'order_by': 'attempt_ratio_order',
                'sort_order': 'asc' if sort_order == 'desc' else 'desc'
            })

        params = {
            'segments': split_query_argument(query_params.get('segments')),
            'ignore_segments': split_query_argument(query_params.get('ignore_segments')),
            'cohort': query_params.get('cohort'),
            'enrollment_mode': query_params.get('enrollment_mode'),
            'text_search': query_params.get('text_search'),
            'sort_policies': sort_policies,
        }
        # Remove None values from `params` so that we don't overwrite default
        # parameter values in `get_users_in_course`.
        params = {key: val for key, val in params.items() if val is not None}
        try:
            return RosterEntry.get_users_in_course(self.course_id, **params)
        except ValueError as e:
            raise ParameterValueError(e.message)
Beispiel #5
0
 def get_queryset(self):
     return RosterEntry.get_course_user(self.course_id, self.username)
 def get_queryset(self):
     return RosterEntry.get_course_user(self.course_id, self.username)