X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/8d1372958ce4a205f11fcdd44cf6e9cac8429a69..5e0f7ad5d4274130ad9db5e80c7c433b73f14dfe:/apps/funding/admin.py diff --git a/apps/funding/admin.py b/apps/funding/admin.py old mode 100755 new mode 100644 index 132c86304..d70aef66a --- a/apps/funding/admin.py +++ b/apps/funding/admin.py @@ -1,6 +1,71 @@ +# -*- 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 +from .models import Offer, Perk, Funding, Spent -admin.site.register(Offer) -admin.site.register(Perk) -admin.site.register(Funding) + +class OfferAdmin(admin.ModelAdmin): + model = Offer + list_display = ['title', 'author', 'target', 'sum', 'is_win', 'start', 'end'] + search_fields = ['title', 'author'] + readonly_fields = ('cover_img_tag',) + + +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', 'perk_names'] + search_fields = ['name', 'email', 'offer__title', 'offer__author'] + list_filter = [PayedFilter, 'offer', PerksFilter] + + + +class SpentAdmin(admin.ModelAdmin): + model = Spent + list_display = ['book', 'amount', 'timestamp'] + search_fields = ['book__title'] + + +admin.site.register(Offer, OfferAdmin) +admin.site.register(Perk, PerkAdmin) +admin.site.register(Funding, FundingAdmin) +admin.site.register(Spent, SpentAdmin)