Beispiel #1
0
    def get(self, request, **kwargs):

        cqs = Checkin.objects.filter(
            position__order__event=self.event,
            position__subevent=self.subevent,
            position__order__status__in=[Order.STATUS_PAID] +
            ([Order.STATUS_PENDING]
             if self.config.list.include_pending else []),
            list=self.config.list)
        pqs = OrderPosition.objects.filter(
            order__event=self.event,
            order__status__in=[Order.STATUS_PAID] +
            ([Order.STATUS_PENDING]
             if self.config.list.include_pending else []),
            subevent=self.subevent,
        )
        if not self.config.list.all_products:
            pqs = pqs.filter(item__in=self.config.list.limit_products.
                             values_list('id', flat=True))

        ev = self.subevent or self.event
        response = {
            'version': API_VERSION,
            'event': {
                'name': str(ev.name),
                'list': self.config.list.name,
                'slug': self.event.slug,
                'organizer': {
                    'name': str(self.event.organizer),
                    'slug': self.event.organizer.slug
                },
                'subevent':
                self.subevent.pk if self.subevent else str(self.event),
                'date_from': ev.date_from,
                'date_to': ev.date_to,
                'timezone': self.event.settings.timezone,
                'url': event_absolute_uri(self.event, 'presale:event.index')
            },
            'checkins': cqs.count(),
            'total': pqs.count()
        }

        op_by_item = {
            p['item']: p['cnt']
            for p in pqs.order_by().values('item').annotate(cnt=Count('id'))
        }
        op_by_variation = {
            p['variation']: p['cnt']
            for p in pqs.order_by().values('variation').annotate(
                cnt=Count('id'))
        }
        c_by_item = {
            p['position__item']: p['cnt']
            for p in cqs.order_by().values('position__item').annotate(
                cnt=Count('id'))
        }
        c_by_variation = {
            p['position__variation']: p['cnt']
            for p in cqs.order_by().values('position__variation').annotate(
                cnt=Count('id'))
        }

        response['items'] = []
        for item in self.event.items.order_by('pk').prefetch_related(
                'variations'):
            i = {
                'id': item.pk,
                'name': str(item),
                'admission': item.admission,
                'checkins': c_by_item.get(item.pk, 0),
                'total': op_by_item.get(item.pk, 0),
                'variations': []
            }
            for var in item.variations.all():
                i['variations'].append({
                    'id':
                    var.pk,
                    'name':
                    str(var),
                    'checkins':
                    c_by_variation.get(var.pk, 0),
                    'total':
                    op_by_variation.get(var.pk, 0),
                })
            response['items'].append(i)

        return JsonResponse(response)
Beispiel #2
0
    def get(self, request, **kwargs):
        response = {
            'version':
            API_VERSION,
            'event': {
                'name': str(self.event),
                'slug': self.event.slug,
                'organizer': {
                    'name': str(self.event.organizer),
                    'slug': self.event.organizer.slug
                },
                'date_from': self.event.date_from,
                'date_to': self.event.date_to,
                'timezone': self.event.settings.timezone,
                'url': event_absolute_uri(self.event, 'presale:event.index')
            },
            'checkins':
            Checkin.objects.filter(position__order__event=self.event).count(),
            'total':
            OrderPosition.objects.filter(
                order__event=self.event,
                order__status=Order.STATUS_PAID).count()
        }

        op_by_item = {
            p['item']: p['cnt']
            for p in OrderPosition.objects.filter(
                order__event=self.event, order__status=Order.STATUS_PAID).
            order_by().values('item').annotate(cnt=Count('id'))
        }
        op_by_variation = {
            p['variation']: p['cnt']
            for p in OrderPosition.objects.filter(
                order__event=self.event, order__status=Order.STATUS_PAID).
            order_by().values('variation').annotate(cnt=Count('id'))
        }
        c_by_item = {
            p['position__item']: p['cnt']
            for p in Checkin.objects.filter(
                position__order__event=self.event,
                position__order__status=Order.STATUS_PAID).order_by().values(
                    'position__item').annotate(cnt=Count('id'))
        }
        c_by_variation = {
            p['position__variation']: p['cnt']
            for p in Checkin.objects.filter(
                position__order__event=self.event,
                position__order__status=Order.STATUS_PAID).order_by().values(
                    'position__variation').annotate(cnt=Count('id'))
        }

        response['items'] = []
        for item in self.event.items.prefetch_related('variations'):
            i = {
                'id': item.pk,
                'name': str(item),
                'admission': item.admission,
                'checkins': c_by_item.get(item.pk, 0),
                'total': op_by_item.get(item.pk, 0),
                'variations': []
            }
            for var in item.variations.all():
                i['variations'].append({
                    'id':
                    var.pk,
                    'name':
                    str(var),
                    'checkins':
                    c_by_variation.get(var.pk, 0),
                    'total':
                    op_by_variation.get(var.pk, 0),
                })
            response['items'].append(i)

        return JsonResponse(response)
Beispiel #3
0
    def get(self, request, **kwargs):

        cqs = Checkin.objects.filter(
            position__order__event=self.event, position__subevent=self.subevent,
            position__order__status__in=[Order.STATUS_PAID] + ([Order.STATUS_PENDING] if
                                                               self.config.list.include_pending else []),
            list=self.config.list
        )
        pqs = OrderPosition.objects.filter(
            order__event=self.event,
            order__status__in=[Order.STATUS_PAID] + ([Order.STATUS_PENDING] if self.config.list.include_pending else
                                                     []),
            subevent=self.subevent,
        )
        if not self.config.list.all_products:
            pqs = pqs.filter(item__in=self.config.list.limit_products.values_list('id', flat=True))

        ev = self.subevent or self.event
        response = {
            'version': API_VERSION,
            'event': {
                'name': str(ev.name),
                'list': self.config.list.name,
                'slug': self.event.slug,
                'organizer': {
                    'name': str(self.event.organizer),
                    'slug': self.event.organizer.slug
                },
                'subevent': self.subevent.pk if self.subevent else str(self.event),
                'date_from': ev.date_from,
                'date_to': ev.date_to,
                'timezone': self.event.settings.timezone,
                'url': event_absolute_uri(self.event, 'presale:event.index')
            },
            'checkins': cqs.count(),
            'total': pqs.count()
        }

        op_by_item = {
            p['item']: p['cnt']
            for p in pqs.order_by().values('item').annotate(cnt=Count('id'))
        }
        op_by_variation = {
            p['variation']: p['cnt']
            for p in pqs.order_by().values('variation').annotate(cnt=Count('id'))
        }
        c_by_item = {
            p['position__item']: p['cnt']
            for p in cqs.order_by().values('position__item').annotate(cnt=Count('id'))
        }
        c_by_variation = {
            p['position__variation']: p['cnt']
            for p in cqs.order_by().values('position__variation').annotate(cnt=Count('id'))
        }

        response['items'] = []
        for item in self.event.items.order_by('pk').prefetch_related('variations'):
            i = {
                'id': item.pk,
                'name': str(item),
                'admission': item.admission,
                'checkins': c_by_item.get(item.pk, 0),
                'total': op_by_item.get(item.pk, 0),
                'variations': []
            }
            for var in item.variations.all():
                i['variations'].append({
                    'id': var.pk,
                    'name': str(var),
                    'checkins': c_by_variation.get(var.pk, 0),
                    'total': op_by_variation.get(var.pk, 0),
                })
            response['items'].append(i)

        return JsonResponse(response)