Esempio n. 1
0
 def clean_bought_item(self):
     bought_item = self.cleaned_data['bought_item']
     if not bought_item.can_transfer():
         raise forms.ValidationError("This item is not eligible for transfer.")
     if TransferInvite.get_invites(bought_item).exists():
         raise ValidationError("A transfer has already been initiated for this item.")
     return bought_item
Esempio n. 2
0
 def clean_bought_item(self):
     bought_item = self.cleaned_data['bought_item']
     if not bought_item.can_transfer():
         raise forms.ValidationError(
             "This item is not eligible for transfer.")
     if TransferInvite.get_invites(bought_item).exists():
         raise ValidationError(
             "A transfer has already been initiated for this item.")
     return bought_item
Esempio n. 3
0
    def get_context_data(self, **kwargs):
        context = super(SummaryView, self).get_context_data(**kwargs)

        context.update({
            'attendees': self.order.attendees.all(),
            'new_card_form': getattr(self, 'new_card_form', None),
            'choose_card_form': getattr(self, 'choose_card_form', None),
            'check_form': getattr(self, 'check_form', None),
            'net_balance': self.net_balance,
            'STRIPE_PUBLISHABLE_KEY': getattr(settings,
                                              'STRIPE_PUBLISHABLE_KEY',
                                              ''),
            'STRIPE_TEST_PUBLISHABLE_KEY': getattr(settings,
                                                   'STRIPE_TEST_PUBLISHABLE_KEY',
                                                   ''),
        })
        context.update(self.summary_data)

        # TODO: Improve this overall assembly. It's possible the data model
        # will need to change to allow this. Invite doesn't have a reference
        # back to its content though, just an IntegerField content_id.
        bought_items = self.order.bought_items.filter(status=BoughtItem.BOUGHT)
        invites = TransferInvite.get_invites(bought_items)
        context['pending_transfers'] = [
            dict(
                invite=invite,
                bought_item=bought_items.get(pk=invite.content_id),
            )
            for invite in invites
        ]

        # This is pretty awful and hopefully only used as a stopgap measure
        # before Invites get refactored. Then again, this comment is one of
        # those kinds that stick around for years.
        context['transferred_items'] = BoughtItem.objects.filter(
            transactions__related_transaction__transaction_type=Transaction.TRANSFER,
            transactions__related_transaction__order=self.order,
        ).prefetch_related(Prefetch(
            'transactions',
            queryset=Transaction.objects.filter(transaction_type=Transaction.TRANSFER),
            to_attr='transfer_transactions',
        ))
        return context
Esempio n. 4
0
 def clean_boughtitem(self):
     bought_item = self.cleaned_data['bought_item']
     if TransferInvite.get_invites(bought_item).exists():
         raise ValidationError(
             "A transfer has already been initiated for this item.")
     return bought_item