1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.utils.translation import gettext_lazy as _
5 from django.contrib import admin
6 from modeltranslation.admin import TranslationAdmin
7 from fnpdjango.actions import export_as_csv_action
8 from .models import Offer, Perk, Funding, Spent
11 class OfferAdmin(TranslationAdmin):
13 list_display = ['title', 'author', 'target', 'sum', 'is_win', 'start', 'end']
14 search_fields = ['title', 'author']
15 readonly_fields = ('cover_img_tag',)
16 autocomplete_fields = ['book']
19 class PerkAdmin(TranslationAdmin):
21 search_fields = ['name', 'long_name']
22 list_display = ['name', 'long_name', 'price', 'end_date', 'offer']
23 list_filter = ['offer']
26 class PayedFilter(admin.SimpleListFilter):
27 title = _('payment complete')
28 parameter_name = 'payed'
30 def lookups(self, request, model_admin):
36 def queryset(self, request, queryset):
37 if self.value() == 'yes':
38 return queryset.exclude(completed_at=None)
39 elif self.value() == 'no':
40 return queryset.filter(completed_at=None)
43 class PerksFilter(admin.SimpleListFilter):
45 parameter_name = 'perks'
47 def lookups(self, request, model_admin):
53 def queryset(self, request, queryset):
54 if self.value() == 'yes':
55 return queryset.exclude(perks=None)
56 elif self.value() == 'no':
57 return queryset.filter(perks=None)
60 class FundingAdmin(admin.ModelAdmin):
62 list_display = ['created_at', 'completed_at', 'offer', 'amount', 'name', 'email', 'perk_names']
63 search_fields = ['name', 'email', 'offer__title', 'offer__author']
64 list_filter = [PayedFilter, 'offer', PerksFilter]
65 actions = [export_as_csv_action(
67 'id', 'offer', 'name', 'email', 'amount', 'completed_at',
68 'notifications', 'notify_key', 'wl_optout_url'
73 class SpentAdmin(admin.ModelAdmin):
75 list_display = ['book', 'amount', 'timestamp']
76 search_fields = ['book__title']
79 admin.site.register(Offer, OfferAdmin)
80 admin.site.register(Perk, PerkAdmin)
81 admin.site.register(Funding, FundingAdmin)
82 admin.site.register(Spent, SpentAdmin)