Beispiel #1
0
    def get_queryset(self):
        queryset = common.get_user_event_related_queryset(
            self.request.user, self.queryset)

        event = self.query_data.get('event', int)
        if event:
            queryset = queryset.filter(event=event)

        return queryset
Beispiel #2
0
    def get_queryset(self):
        queryset = common.get_user_event_related_queryset(
            self.request.user, self.queryset)

        event = self.query_data.get('event', int)
        if event is not None:
            queryset = queryset.filter(event=event)

        task_type = self.query_data.get('type',
                                        event_models.EventTask.Type.values())
        if task_type is not None:
            queryset = queryset.filter(type=task_type)

        from django.db.models import Count
        queryset = queryset.annotate(sloved_count=Count('eventuseranswer'))

        return queryset
Beispiel #3
0
    def get_queryset(self):
        queryset = common.get_user_event_related_queryset(
            self.request.user, self.queryset)

        user = self.query_data.get('user', int)
        if user is not None:
            queryset = queryset.filter(user=user)

        team = self.query_data.get('team', int)
        if team is not None:
            queryset = queryset.filter(team=team)

        event = self.query_data.get('event', int)
        if event is not None:
            queryset = queryset.filter(event=event)

        return queryset
Beispiel #4
0
    def get_queryset(self):
        queryset = common.get_user_event_related_queryset(
            self.request.user, self.queryset)

        event = self.query_data.get('event', int)
        if event is not None:
            queryset = queryset.filter(event=event)
        else:
            raise exceptions.ValidationError(error.EVENT_NOT_EXIST)

        table_user_answer = event_models.EventUserAnswer._meta.db_table
        table_task = event_models.EventTask._meta.db_table

        from_str = '''
            FROM {table_user_answer} 
                INNER JOIN {table_task} 
                ON {table_user_answer}.event_task_id = {table_task}.id 
                    and {table_task}.event_id = {event}
            WHERE 
                {table_user_answer}.{obj_id_attr} = {table_signup_obj}.{obj_id_attr} 
                and {table_user_answer}.status = {status_normal}
        '''.format(
            table_user_answer=table_user_answer,
            table_task=table_task,
            event=event,
            status_normal=event_models.EventUserAnswer.Status.NORMAL,
            table_signup_obj=self.queryset.model._meta.db_table,
            obj_id_attr='{}_id'.format(self._obj_name),
        )

        queryset = queryset.extra(
            select={
                'solved_count':
                'SELECT count(0) {from_str}'.format(
                    table_user_answer=table_user_answer, from_str=from_str),
                'sum_score':
                'SELECT sum({table_user_answer}.score) {from_str}'.format(
                    table_user_answer=table_user_answer, from_str=from_str),
                'last_submit_time':
                'SELECT max({table_user_answer}.time) {from_str}'.format(
                    table_user_answer=table_user_answer, from_str=from_str),
            })

        return queryset