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.utils.html import conditional_escape
7 from django.utils.safestring import mark_safe
8 from modeltranslation.admin import TranslationAdmin
12 class PlanAdmin(admin.ModelAdmin):
13 list_display = ['min_amount', 'interval']
15 admin.site.register(models.Plan, PlanAdmin)
18 class PayUOrderInline(admin.TabularInline):
19 model = models.PayUOrder
20 fields = ['order_id', 'status', 'customer_ip']
21 readonly_fields = fields
23 show_change_link = True
26 def has_add_permission(self, request, obj):
30 class PayUCardTokenInline(admin.TabularInline):
31 model = models.PayUCardToken
32 fields = ['created_at', 'disposable_token', 'reusable_token']
33 readonly_fields = fields
35 show_change_link = True
37 show_change_link = True
39 def has_add_permission(self, request, obj):
43 class ScheduleAdmin(admin.ModelAdmin):
44 list_display = ['email', 'started_at', 'payed_at', 'expires_at', 'plan', 'amount', 'is_cancelled']
45 list_search = ['email']
46 list_filter = ['is_cancelled']
47 date_hierarchy = 'started_at'
48 raw_id_fields = ['membership']
49 inlines = [PayUOrderInline, PayUCardTokenInline]
51 admin.site.register(models.Schedule, ScheduleAdmin)
54 class ScheduleInline(admin.TabularInline):
55 model = models.Schedule
56 fields = ['email', 'plan', 'amount', 'method', 'is_cancelled', 'started_at', 'payed_at', 'expires_at', 'email_sent']
57 readonly_fields = fields
59 show_change_link = True
62 def has_add_permission(self, request, obj):
66 class MembershipAdmin(admin.ModelAdmin):
67 list_display = ['user']
68 raw_id_fields = ['user']
69 search_fields = ['user__username', 'user__email', 'schedule__email']
70 inlines = [ScheduleInline]
72 admin.site.register(models.Membership, MembershipAdmin)
75 admin.site.register(models.ReminderEmail, TranslationAdmin)
78 class PayUNotificationAdmin(admin.ModelAdmin):
79 list_display = ['received_at', 'order']
80 fields = ['received_at', 'order', 'body_']
81 readonly_fields = ['received_at', 'body_']
82 raw_id_fields = ['order']
87 conditional_escape(json.dumps(json.loads(obj.body), indent=4))
91 admin.site.register(models.PayUNotification, PayUNotificationAdmin)
94 class PayUNotificationInline(admin.TabularInline):
95 model = models.PayUNotification
96 fields = ['received_at', 'body_']
97 readonly_fields = fields
99 show_change_link = True
102 def body_(self, obj):
105 conditional_escape(json.dumps(json.loads(obj.body), indent=4))
108 def has_add_permission(self, request, obj):
112 class PayUOrderAdmin(admin.ModelAdmin):
113 list_display = ['schedule']
114 raw_id_fields = ['schedule']
115 inlines = [PayUNotificationInline]
118 admin.site.register(models.PayUOrder, PayUOrderAdmin)