1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.contrib import admin
6 from django.db.models.functions import Now
7 from django.db.models import Q
8 from django.utils.html import conditional_escape
9 from django.utils.safestring import mark_safe
10 from django.utils.translation import gettext_lazy as _
11 from fnpdjango.actions import export_as_csv_action
12 from modeltranslation.admin import TranslationAdmin
13 from wolnelektury.utils import YesNoFilter
17 admin.site.register(models.Club)
20 class PayUOrderInline(admin.TabularInline):
21 model = models.PayUOrder
22 fields = ['order_id', 'status', 'customer_ip']
23 readonly_fields = fields
25 show_change_link = True
28 def has_add_permission(self, request, obj):
32 class PayUCardTokenInline(admin.TabularInline):
33 model = models.PayUCardToken
34 fields = ['created_at', 'disposable_token', 'reusable_token']
35 readonly_fields = fields
37 show_change_link = True
39 show_change_link = True
41 def has_add_permission(self, request, obj):
45 class PayedFilter(YesNoFilter):
46 title = _('payment complete')
47 parameter_name = 'payed'
51 class ExpiredFilter(YesNoFilter):
52 title = _('schedule expired')
53 parameter_name = 'expired'
54 q = Q(expires_at__isnull=False, expires_at__lt=Now())
57 class ScheduleAdmin(admin.ModelAdmin):
59 'email', 'started_at', 'payed_at', 'expires_at', 'amount', 'monthly', 'yearly', 'is_cancelled',
62 search_fields = ['email']
63 list_filter = ['is_cancelled', 'monthly', 'yearly', 'method', PayedFilter, ExpiredFilter, 'source']
64 date_hierarchy = 'started_at'
65 raw_id_fields = ['membership']
66 inlines = [PayUOrderInline, PayUCardTokenInline]
67 actions = [export_as_csv_action()]
69 admin.site.register(models.Schedule, ScheduleAdmin)
72 class ScheduleInline(admin.TabularInline):
73 model = models.Schedule
74 fields = ['email', 'amount', 'is_cancelled', 'started_at', 'payed_at', 'expires_at', 'email_sent']
75 readonly_fields = fields
77 show_change_link = True
80 def has_add_permission(self, request, obj):
84 class MembershipAdmin(admin.ModelAdmin):
85 list_display = ['user', 'manual', 'updated_at', 'notes']
86 list_filter = ['manual']
87 date_hierarchy = 'updated_at'
88 raw_id_fields = ['user']
89 search_fields = ['user__username', 'user__email', 'schedule__email', 'notes']
90 inlines = [ScheduleInline]
92 admin.site.register(models.Membership, MembershipAdmin)
95 admin.site.register(models.ReminderEmail, TranslationAdmin)
98 class PayUNotificationAdmin(admin.ModelAdmin):
99 list_display = ['received_at', 'order']
100 fields = ['received_at', 'order', 'body_']
101 readonly_fields = ['received_at', 'body_']
102 raw_id_fields = ['order']
104 def body_(self, obj):
107 conditional_escape(json.dumps(json.loads(obj.body), indent=4))
111 admin.site.register(models.PayUNotification, PayUNotificationAdmin)
114 class PayUNotificationInline(admin.TabularInline):
115 model = models.PayUNotification
116 fields = ['received_at', 'body_']
117 readonly_fields = fields
119 show_change_link = True
122 def body_(self, obj):
125 conditional_escape(json.dumps(json.loads(obj.body), indent=4))
128 def has_add_permission(self, request, obj):
132 class PayUOrderAdmin(admin.ModelAdmin):
133 list_display = ['schedule']
134 raw_id_fields = ['schedule']
135 inlines = [PayUNotificationInline]
138 admin.site.register(models.PayUOrder, PayUOrderAdmin)
141 admin.site.register(models.Ambassador)
145 @admin.register(models.DirectDebit)
146 class DirectDebitAdmin(admin.ModelAdmin):
147 list_display = ['date', 'amount', 'first_name', 'last_name']
149 ('first_name', 'sex', 'date_of_birth'),
151 ('street', 'building'),
153 ('postal_code', 'phone'),