1 from django.contrib import admin
2 from django.contrib import messages
3 from fnpdjango.actions import export_as_csv_action
7 class EmailTemplateAdmin(admin.ModelAdmin):
8 list_display = ['state', 'min_days_since', 'subject', 'min_hour', 'is_active']
12 ('min_days_since', 'max_days_since'),
15 ('Zawartość e-maila', {"fields": [
18 ('Ograniczenia wysyłki', {"fields": [
19 ('min_day_of_month', 'max_day_of_month'),
20 ('dow_1', 'dow_2', 'dow_3', 'dow_4', 'dow_5', 'dow_6', 'dow_7'),
21 ('min_hour', 'max_hour'),
25 def _test_email(self, request, obj):
26 if request.user.email:
27 obj.send_test_email(request.user.email)
30 'Na adres %(email)s została wysłana testowa wiadomość.' % {
31 "email": request.user.email
37 'Nie masz ustawionego adresu e-mail. Wiadomość testowa nie została wysłana.'
40 def response_add(self, request, obj):
41 self._test_email(request, obj)
42 return super().response_add(request, obj)
44 def response_change(self, request, obj):
45 self._test_email(request, obj)
46 return super().response_change(request, obj)
49 admin.site.register(models.EmailTemplate, EmailTemplateAdmin)
52 class EmailSentAdmin(admin.ModelAdmin):
53 list_filter = ['template']
54 list_display = ['timestamp', 'template', 'contact', 'subject']
55 fields = ['timestamp', 'template', 'contact', 'subject', 'body']
56 readonly_fields = fields
57 change_links = ['template']
60 admin.site.register(models.EmailSent, EmailSentAdmin)
63 class ContactEmailSentInline(admin.TabularInline):
64 model = models.EmailSent
65 fields = ['timestamp', 'template', 'subject']
66 readonly_fields = ['timestamp', 'template', 'subject']
69 show_change_link = True
71 def has_add_permission(self, request, obj):
75 class ContactAdmin(admin.ModelAdmin):
76 inlines = [ContactEmailSentInline]
77 list_filter = ['level']
78 list_display = ['email', 'level', 'since', 'expires_at']
79 search_fields = ['email']
80 date_hierarchy = 'since'
82 # export_as_csv_action(fields=['id', 'email', 'get_level_display', 'since', 'expires_at']),
83 export_as_csv_action('Eksport dla PHPList', fields=['email', 'wl_optout_url'])
87 admin.site.register(models.Contact, ContactAdmin)