Esempio n. 1
0
    def get_queryset(self):
        # requirido pelo datatables.js
        self.draw_page = int(self.request.query_params.get('draw', 0))

        queryset = Course.objects.all()
        self.recordsTotal = queryset.count()
        self.recordsFiltered = self.recordsTotal

        search_value = self.request.query_params.get('search[value]')
        if search_value:
            queryset = queryset.filter(
                Q(name__icontains=search_value)
                | Q(category__name__icontains=search_value)
                | Q(instructor__name__icontains=search_value)
                | Q(description__icontains=search_value))
            self.recordsFiltered = queryset.count()

        if self.request.query_params.get('order[0][column]'):
            query_order_by = self.request.query_params.get(
                'columns[{}][data]'.format(
                    self.request.query_params.get('order[0][column]')))
        else:
            query_order_by = 'name'

        query_order_by = query_order_by.replace('.', '__')

        if self.request.query_params.get('order[0][dir]') == 'desc':
            queryset = queryset.order_by(Lower(query_order_by).desc())
        else:
            queryset = queryset.order_by(Lower(query_order_by))

        return queryset
Esempio n. 2
0
 def get_queryset(self):
     queryset = super(CountryDailyStatsListAPIView, self).get_queryset()
     country = get_object_or_404(
         Country.objects.annotate(code_lower=Lower('code')),
         code_lower=self.kwargs.get('country_code'),
     )
     return queryset.filter(country=country)
Esempio n. 3
0
 def export_csv_schools(self, request, *args, **kwargs):
     country = get_object_or_404(
         self.get_queryset().annotate(code_lower=Lower('code')),
         code_lower=self.kwargs.get('country_code'),
     )
     serializer = self.get_serializer(self.get_queryset(), many=True)
     csvwriter = SchoolsCSVWriterBackend(serializer, country)
     response = csvwriter.write()
     return response
Esempio n. 4
0
 def get_country(self):
     if not hasattr(self, '_country'):
         self._country = get_object_or_404(
             Country.objects.defer(
                 'geometry', 'geometry_simplified',
             ).select_related('last_weekly_status').annotate(code_lower=Lower('code')),
             code_lower=self.kwargs.get('country_code'),
         )
     return self._country
Esempio n. 5
0
    def get_object(self, *args, **kwargs):
        week = self.kwargs['week']
        year = self.kwargs['year']
        country = get_object_or_404(
            Country.objects.annotate(code_lower=Lower('code')),
            code_lower=self.kwargs.get('country_code'),
        )
        date = datetime.strptime(f'{year}-W{week}-1', '%Y-W%W-%w')
        instance = CountryWeeklyStatus.objects.filter(country=country,
                                                      date__lte=date).last()

        if not instance:
            raise Http404

        return instance
Esempio n. 6
0
 def alphabetized_tags(self):
     return self.tags.order_by(Lower("name"))
Esempio n. 7
0
 def get_object(self):
     return get_object_or_404(
         self.queryset.annotate(code_lower=Lower('code')),
         code_lower=self.kwargs.get('pk'))