コード例 #1
0
    def get_context_data(self, **kwargs):
        context = super(RactiveShopView, self).get_context_data(**kwargs)
        event = get_object_or_404(Event.objects.select_related('organization'),
                                  slug=kwargs['event_slug'],
                                  organization__slug=kwargs['organization_slug'])

        editable_by_user = event.editable_by(self.request.user)

        if not event.is_published and not editable_by_user:
            raise Http404

        clear_expired_carts(event)
        try:
            order = Order.objects.get(event=event, person=self.request.user)
        except:
            order = None

        # TODO: This will never allow anonymous users to get past the
        # shopping page, because their orders are stored in the session.
        # Probably we need to refactor OrderViewSet.create() to make an
        # Order.objects.from_request() method that gets used across the board.
        # And/or find a better way to store workflow information.

        context['event'] = event
        context['editable_by_user'] = editable_by_user
        context['workflow'] = RegistrationWorkflow(event=event, order=order)
        context['code_in_url'] = (True if self.kwargs.get('code') and
                                  not self.request.user.is_authenticated() else False)
        return context
コード例 #2
0
    def post(self, request, *args, **kwargs):
        clear_expired_carts(self.event)

        if self.order is None:
            return JsonResponse({
                'success':
                False,
                'error':
                "Registration for this event is restricted."
            })

        try:
            item_option = ItemOption.objects.get(item__event=self.event,
                                                 pk=kwargs['pk'])
        except ItemOption.DoesNotExist:
            raise Http404

        # If a total number is set and has been reached, the item is sold out.
        if item_option.total_number is not None and item_option.remaining <= 0:
            return JsonResponse({
                'success': False,
                'error': 'That item is sold out.'
            })

        self.order.add_to_cart(item_option)
        return JsonResponse({'success': True})
コード例 #3
0
    def get_context_data(self, **kwargs):
        context = super(RactiveShopView, self).get_context_data(**kwargs)
        event = get_object_or_404(
            Event.objects.select_related('organization'),
            slug=kwargs['event_slug'],
            organization__slug=kwargs['organization_slug'])

        editable_by_user = self.request.user.has_perm('edit', event)

        if not event.is_published and not editable_by_user:
            raise Http404

        clear_expired_carts(event)
        try:
            order = Order.objects.get(event=event, person=self.request.user)
        except:
            order = None

        # TODO: This will never allow anonymous users to get past the
        # shopping page, because their orders are stored in the session.
        # Probably we need to refactor OrderViewSet.create() to make an
        # Order.objects.from_request() method that gets used across the board.
        # And/or find a better way to store workflow information.

        context['event'] = event
        context['editable_by_user'] = editable_by_user
        context['workflow'] = RegistrationWorkflow(event=event, order=order)
        return context
コード例 #4
0
ファイル: organizer.py プロジェクト: j-po/django-brambling
 def get(self, request, *args, **kwargs):
     self.event = get_object_or_404(Event.objects.select_related('organization'),
                                    slug=self.kwargs['event_slug'],
                                    organization__slug=self.kwargs['organization_slug'])
     if not self.event.editable_by(request.user):
         raise Http404
     clear_expired_carts(self.event)
     return super(EventSummaryView, self).get(request, *args, **kwargs)
コード例 #5
0
    def post(self, request, *args, **kwargs):
        clear_expired_carts(self.event)

        try:
            item_option = ItemOption.objects.get(item__event=self.event,
                                                 pk=kwargs['pk'])
        except ItemOption.DoesNotExist:
            raise Http404

        # If a total number is set and has been reached, the item is sold out.
        if item_option.total_number is not None and item_option.remaining <= 0:
            return JsonResponse({'success': False, 'error': 'That item is sold out.'})

        self.order.add_to_cart(item_option)
        return JsonResponse({'success': True})
コード例 #6
0
    def get_context_data(self, **kwargs):
        context = super(ChooseItemsView, self).get_context_data(**kwargs)
        clear_expired_carts(self.event)
        now = timezone.now()
        item_options = ItemOption.objects.filter(
            available_start__lte=now,
            available_end__gte=now,
            item__event=self.event,
        ).order_by('item', 'order').extra(select={
            'taken': """
SELECT COUNT(*) FROM brambling_boughtitem WHERE
brambling_boughtitem.item_option_id = brambling_itemoption.id AND
brambling_boughtitem.status != 'refunded'
"""
        })

        context['item_options'] = item_options
        return context