1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
4 from django.contrib import admin
5 from modeltranslation.admin import TranslationAdmin
6 from fnpdjango.actions import export_as_csv_action
7 from .models import Offer, Perk, Funding, Spent
10 class OfferAdmin(TranslationAdmin):
12 list_display = ['title', 'author', 'target', 'sum', 'is_win', 'start', 'end']
13 search_fields = ['title', 'author']
14 readonly_fields = ('cover_img_tag',)
15 autocomplete_fields = ['book']
18 class PerkAdmin(TranslationAdmin):
20 search_fields = ['name', 'long_name']
21 list_display = ['name', 'long_name', 'price', 'end_date', 'offer']
22 list_filter = ['offer']
25 class PayedFilter(admin.SimpleListFilter):
26 title = 'płatność doszła do skutku'
27 parameter_name = 'payed'
29 def lookups(self, request, model_admin):
35 def queryset(self, request, queryset):
36 if self.value() == 'yes':
37 return queryset.exclude(completed_at=None)
38 elif self.value() == 'no':
39 return queryset.filter(completed_at=None)
42 class PerksFilter(admin.SimpleListFilter):
44 parameter_name = 'perks'
46 def lookups(self, request, model_admin):
52 def queryset(self, request, queryset):
53 if self.value() == 'yes':
54 return queryset.exclude(perks=None)
55 elif self.value() == 'no':
56 return queryset.filter(perks=None)
59 class FundingAdmin(admin.ModelAdmin):
61 list_display = ['created_at', 'completed_at', 'offer', 'amount', 'name', 'email', 'perk_names']
62 search_fields = ['name', 'email', 'offer__title', 'offer__author']
63 list_filter = [PayedFilter, 'offer', PerksFilter]
64 actions = [export_as_csv_action(
66 'id', 'offer', 'name', 'email', 'amount', 'completed_at',
67 'notifications', 'notify_key', 'wl_optout_url'
72 class SpentAdmin(admin.ModelAdmin):
74 list_display = ['book', 'amount', 'timestamp']
75 search_fields = ['book__title']
78 admin.site.register(Offer, OfferAdmin)
79 admin.site.register(Perk, PerkAdmin)
80 admin.site.register(Funding, FundingAdmin)
81 admin.site.register(Spent, SpentAdmin)