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 modeltranslation.admin import TranslationAdmin
12 from wolnelektury.utils import YesNoFilter
16 admin.site.register(models.Club)
19 class PayUOrderInline(admin.TabularInline):
20 model = models.PayUOrder
21 fields = ['order_id', 'status', 'customer_ip']
22 readonly_fields = fields
24 show_change_link = True
27 def has_add_permission(self, request, obj):
31 class PayUCardTokenInline(admin.TabularInline):
32 model = models.PayUCardToken
33 fields = ['created_at', 'disposable_token', 'reusable_token']
34 readonly_fields = fields
36 show_change_link = True
38 show_change_link = True
40 def has_add_permission(self, request, obj):
44 class PayedFilter(YesNoFilter):
45 title = _('payment complete')
46 parameter_name = 'payed'
50 class ExpiredFilter(YesNoFilter):
51 title = _('schedule expired')
52 parameter_name = 'expired'
53 q = Q(expires_at__isnull=False, expires_at__lt=Now())
56 class ScheduleAdmin(admin.ModelAdmin):
57 list_display = ['email', 'started_at', 'payed_at', 'expires_at', 'amount', 'monthly', 'yearly', 'is_cancelled']
58 search_fields = ['email']
59 list_filter = ['is_cancelled', 'monthly', 'yearly', PayedFilter, ExpiredFilter]
60 date_hierarchy = 'started_at'
61 raw_id_fields = ['membership']
62 inlines = [PayUOrderInline, PayUCardTokenInline]
64 admin.site.register(models.Schedule, ScheduleAdmin)
67 class ScheduleInline(admin.TabularInline):
68 model = models.Schedule
69 fields = ['email', 'amount', 'is_cancelled', 'started_at', 'payed_at', 'expires_at', 'email_sent']
70 readonly_fields = fields
72 show_change_link = True
75 def has_add_permission(self, request, obj):
79 class MembershipAdmin(admin.ModelAdmin):
80 list_display = ['user']
81 raw_id_fields = ['user']
82 search_fields = ['user__username', 'user__email', 'schedule__email']
83 inlines = [ScheduleInline]
85 admin.site.register(models.Membership, MembershipAdmin)
88 admin.site.register(models.ReminderEmail, TranslationAdmin)
91 class PayUNotificationAdmin(admin.ModelAdmin):
92 list_display = ['received_at', 'order']
93 fields = ['received_at', 'order', 'body_']
94 readonly_fields = ['received_at', 'body_']
95 raw_id_fields = ['order']
100 conditional_escape(json.dumps(json.loads(obj.body), indent=4))
104 admin.site.register(models.PayUNotification, PayUNotificationAdmin)
107 class PayUNotificationInline(admin.TabularInline):
108 model = models.PayUNotification
109 fields = ['received_at', 'body_']
110 readonly_fields = fields
112 show_change_link = True
115 def body_(self, obj):
118 conditional_escape(json.dumps(json.loads(obj.body), indent=4))
121 def has_add_permission(self, request, obj):
125 class PayUOrderAdmin(admin.ModelAdmin):
126 list_display = ['schedule']
127 raw_id_fields = ['schedule']
128 inlines = [PayUNotificationInline]
131 admin.site.register(models.PayUOrder, PayUOrderAdmin)
134 admin.site.register(models.Ambassador)