0be845b193efc9677be8965297a91d4fa8764bb9
[wolnelektury.git] / src / pz / admin.py
1 from django.contrib import admin
2 from django.utils.translation import gettext_lazy as _
3 from django.utils.timezone import now
4 from fnpdjango.actions import export_as_csv_action
5 from . import bank
6 from . import models
7
8
9 admin.site.register(models.Fundraiser)
10 admin.site.register(models.Campaign)
11
12 @admin.register(models.DirectDebit)
13 class DirectDebitAdmin(admin.ModelAdmin):
14     list_display = [
15         'payment_id', 'acquisition_date',
16         'iban_valid',
17         'bank_submission_date',
18         'bank_acceptance_date',
19         'amount', 'first_name', 'last_name',
20     ]
21     date_hierarchy = 'acquisition_date'
22     search_fields = [
23         'payment_id', 'first_name', 'last_name', 'street', 'building', 'town', 'flat',
24         'phone', 'email', 'iban',
25         'notes',
26         'fundraiser_bill',
27     ]
28     list_filter = [
29         'iban_valid',
30         'agree_fundraising',
31         'agree_newsletter',
32         'fundraiser',
33         'campaign',
34         'is_cancelled',
35         'needs_redo',
36         'optout',
37         'amount',
38         'sex',
39         'is_consumer',
40     ]
41     fieldsets = [
42         (None, {
43             "fields": [
44                 ('first_name', 'sex', 'date_of_birth'),
45                 'last_name',
46                 ('street', 'building'),
47                 ('town', 'flat'),
48                 ('postal_code', 'phone'),
49                 'email',
50                 ('iban', 'iban_valid', 'iban_warning'),
51                 'payment_id',
52                 'agree_contact',
53                 'agree_fundraising',
54                 'agree_newsletter',
55                 ('acquisition_date', 'amount'),
56                 'is_consumer',
57                 'fundraiser',
58                 'campaign',
59             ]
60         }),
61         (_('Processing'), {"fields": [
62             ('is_cancelled', 'needs_redo', 'optout'),
63             'submission_date',
64             'fundraiser_commission',
65             'fundraiser_bill',
66             'bank_submission_date',
67             'bank_acceptance_date',
68             'notes',
69             ]
70         })
71     ]
72     readonly_fields = ['agree_contact', 'iban_valid', 'iban_warning']
73
74     def set_bank_submission(m,r,q):
75         q.update(bank_submission_date=now())
76     actions = [
77         bank.bank_export,
78         set_bank_submission,
79         export_as_csv_action(),
80     ]
81
82     def agree_contact(self, obj):
83         return _('obligatory')
84     agree_contact.short_description = _('agree contact')
85
86     def get_changeform_initial_data(self, request):
87         return {
88             'payment_id': models.DirectDebit.get_next_payment_id(),
89         }