Exemplo n.º 1
0
def donationform_factory(fields=None):
    Donation = get_donation_model()
    widgets = {
        'project': ForeignKeyRawIdWidget(Donation._meta.get_field('project').rel, admin.site),
        'fundraiser': ForeignKeyRawIdWidget(Donation._meta.get_field('fundraiser').rel, admin.site),
        'order': ForeignKeyRawIdWidget(Donation._meta.get_field('order').rel, admin.site),
        'anonymous': forms.HiddenInput(),
    }
    ModelForm = forms.models.modelform_factory(
        Donation,
        form=BaseManualEntryModelForm,
        fields=fields or ('amount', 'project', 'fundraiser', 'order', 'anonymous'),
        widgets=widgets
    )
    ModelForm.title = Donation._meta.verbose_name
    ModelForm.url_name = 'admin:banktransaction-add-donation'
    return ModelForm
Exemplo n.º 2
0
from django.contrib import admin
from django.contrib.admin.filters import SimpleListFilter
from django.utils.translation import ugettext_lazy as _

from bluebottle.donations.admin import DonationInline
from bluebottle.payments.services import PaymentService
from bluebottle.payments.admin import OrderPaymentInline
from bluebottle.utils.admin import TotalAmountAdminChangeList
from bluebottle.utils.model_dispatcher import (get_order_model,
                                               get_donation_model)
from bluebottle.utils.utils import StatusDefinition

ORDER_MODEL = get_order_model()
DONATION_MODEL = get_donation_model()


class OrderStatusFilter(SimpleListFilter):
    title = _('Status')

    parameter_name = 'status__exact'
    default_status = 'pending_or_success'

    def lookups(self, request, model_admin):
        choices = (('all', _('All')),
                   ('pending_or_success', _('Pending/Success')))
        return choices + ORDER_MODEL.STATUS_CHOICES

    def choices(self, cl):
        for lookup, title in self.lookup_choices:
            yield {
                'selected': self.value() == lookup if self.value() else
Exemplo n.º 3
0
 def update_total(self, save=True):
     DONATION_MODEL = get_donation_model()
     donations = DONATION_MODEL.objects.filter(order=self)
     self.total = donations.aggregate(Sum('amount'))['amount__sum'] or 0
     if save:
         self.save()
Exemplo n.º 4
0
 def get_donations_qs(self):
     qs = get_donation_model().objects.filter(order__user=self)
     return qs.filter(order__status__in=[StatusDefinition.PENDING, StatusDefinition.SUCCESS])