X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/357027375ff8867f42ca34bcbfb5a78b5b185fc3..98062d2158ebe1f734d811691ab15e6887684281:/src/funding/admin.py?ds=sidebyside diff --git a/src/funding/admin.py b/src/funding/admin.py index d70aef66a..6f29fbc83 100644 --- a/src/funding/admin.py +++ b/src/funding/admin.py @@ -1,49 +1,55 @@ -# -*- 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.utils.translation import gettext_lazy as _ from django.contrib import admin +from modeltranslation.admin import TranslationAdmin +from fnpdjango.actions import export_as_csv_action from .models import Offer, Perk, Funding, Spent -class OfferAdmin(admin.ModelAdmin): +class OfferAdmin(TranslationAdmin): model = Offer list_display = ['title', 'author', 'target', 'sum', 'is_win', 'start', 'end'] search_fields = ['title', 'author'] readonly_fields = ('cover_img_tag',) + autocomplete_fields = ['book'] -class PerkAdmin(admin.ModelAdmin): +class PerkAdmin(TranslationAdmin): 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) + return queryset.exclude(completed_at=None) elif self.value() == 'no': - return queryset.filter(payed_at=None) + return queryset.filter(completed_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) @@ -53,10 +59,16 @@ class PerksFilter(admin.SimpleListFilter): class FundingAdmin(admin.ModelAdmin): model = Funding - list_display = ['payed_at', 'offer', 'amount', 'name', 'email', 'perk_names'] + list_display = ['created_at', 'completed_at', 'offer', 'amount', 'name', 'email', 'perk_names'] search_fields = ['name', 'email', 'offer__title', 'offer__author'] list_filter = [PayedFilter, 'offer', PerksFilter] - + search_fields = ['user'] + actions = [export_as_csv_action( + fields=[ + 'id', 'offer', 'name', 'email', 'amount', 'completed_at', + 'notifications', 'notify_key', 'wl_optout_url' + ] + )] class SpentAdmin(admin.ModelAdmin):