Picture list fix.
[wolnelektury.git] / src / club / admin.py
1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 import json
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
9 from . import models
10
11
12 admin.site.register(models.Club)
13
14
15 class PayUOrderInline(admin.TabularInline):
16     model = models.PayUOrder
17     fields = ['order_id', 'status', 'customer_ip']
18     readonly_fields = fields
19     extra = 0
20     show_change_link = True
21     can_delete = False
22
23     def has_add_permission(self, request, obj):
24         return False
25
26
27 class PayUCardTokenInline(admin.TabularInline):
28     model = models.PayUCardToken
29     fields = ['created_at', 'disposable_token', 'reusable_token']
30     readonly_fields = fields
31     extra = 0
32     show_change_link = True
33     can_delete = False
34     show_change_link = True
35
36     def has_add_permission(self, request, obj):
37         return False
38
39
40 class ScheduleAdmin(admin.ModelAdmin):
41     list_display = ['email', 'started_at', 'payed_at', 'expires_at', 'amount', 'monthly', 'yearly', 'is_cancelled']
42     search_fields = ['email']
43     list_filter = ['is_cancelled']
44     date_hierarchy = 'started_at'
45     raw_id_fields = ['membership']
46     inlines = [PayUOrderInline, PayUCardTokenInline]
47
48 admin.site.register(models.Schedule, ScheduleAdmin)
49
50
51 class ScheduleInline(admin.TabularInline):
52     model = models.Schedule
53     fields = ['email', 'amount', 'is_cancelled', 'started_at', 'payed_at', 'expires_at', 'email_sent']
54     readonly_fields = fields
55     extra = 0
56     show_change_link = True
57     can_delete = False
58
59     def has_add_permission(self, request, obj):
60         return False
61
62
63 class MembershipAdmin(admin.ModelAdmin):
64     list_display = ['user']
65     raw_id_fields = ['user']
66     search_fields = ['user__username', 'user__email', 'schedule__email']
67     inlines = [ScheduleInline]
68
69 admin.site.register(models.Membership, MembershipAdmin)
70
71
72 admin.site.register(models.ReminderEmail, TranslationAdmin)
73
74
75 class PayUNotificationAdmin(admin.ModelAdmin):
76     list_display = ['received_at', 'order']
77     fields = ['received_at', 'order', 'body_']
78     readonly_fields = ['received_at', 'body_']
79     raw_id_fields = ['order']
80
81     def body_(self, obj):
82         return mark_safe(
83                 "<pre>" +
84                 conditional_escape(json.dumps(json.loads(obj.body), indent=4))
85                 + "</pre>")
86
87
88 admin.site.register(models.PayUNotification, PayUNotificationAdmin)
89
90
91 class PayUNotificationInline(admin.TabularInline):
92     model = models.PayUNotification
93     fields = ['received_at', 'body_']
94     readonly_fields = fields
95     extra = 0
96     show_change_link = True
97     can_delete = False
98
99     def body_(self, obj):
100         return mark_safe(
101                 "<pre>" +
102                 conditional_escape(json.dumps(json.loads(obj.body), indent=4))
103                 + "</pre>")
104
105     def has_add_permission(self, request, obj):
106         return False
107
108
109 class PayUOrderAdmin(admin.ModelAdmin):
110     list_display = ['schedule']
111     raw_id_fields = ['schedule']
112     inlines = [PayUNotificationInline]
113
114
115 admin.site.register(models.PayUOrder, PayUOrderAdmin)
116
117
118 admin.site.register(models.Ambassador)