X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/b412f294aa668eab3295a058f6c66845ef23ada7..c798d2c2b8516c242c0884ccc768a9b43ce16195:/apps/funding/admin.py?ds=inline diff --git a/apps/funding/admin.py b/apps/funding/admin.py index 59c3ac6e3..d70aef66a 100644 --- a/apps/funding/admin.py +++ b/apps/funding/admin.py @@ -1,3 +1,8 @@ +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from django.utils.translation import ugettext_lazy as _ from django.contrib import admin from .models import Offer, Perk, Funding, Spent @@ -11,13 +16,47 @@ class OfferAdmin(admin.ModelAdmin): class PerkAdmin(admin.ModelAdmin): model = Perk + search_fields = ['name', 'long_name'] list_display = ['name', 'long_name', 'price', 'end_date', 'offer'] + list_filter = ['offer'] + + + +class PayedFilter(admin.SimpleListFilter): + title = _('payment complete') + parameter_name = 'payed' + def lookups(self, request, model_admin): + return ( + ('yes', _('Yes')), + ('no', _('No')), + ) + def queryset(self, request, queryset): + if self.value() == 'yes': + return queryset.exclude(payed_at=None) + elif self.value() == 'no': + return queryset.filter(payed_at=None) + +class PerksFilter(admin.SimpleListFilter): + title = _('perks') + parameter_name = 'perks' + def lookups(self, request, model_admin): + return ( + ('yes', _('Yes')), + ('no', _('No')), + ) + def queryset(self, request, queryset): + if self.value() == 'yes': + return queryset.exclude(perks=None) + elif self.value() == 'no': + return queryset.filter(perks=None) class FundingAdmin(admin.ModelAdmin): model = Funding - list_display = ['payed_at', 'offer', 'amount', 'name', 'email'] + list_display = ['payed_at', 'offer', 'amount', 'name', 'email', 'perk_names'] search_fields = ['name', 'email', 'offer__title', 'offer__author'] + list_filter = [PayedFilter, 'offer', PerksFilter] + class SpentAdmin(admin.ModelAdmin):