1 from django.contrib import admin
2 from django.contrib import messages
3 from django.utils.translation import ugettext_lazy as _
4 from fnpdjango.actions import export_as_csv_action
8 class EmailTemplateAdmin(admin.ModelAdmin):
9 list_display = ['state', 'min_days_since', 'subject', 'min_hour', 'is_active']
13 ('min_days_since', 'max_days_since'),
16 (_('E-mail content'), {"fields": [
19 (_('Sending constraints'), {"fields": [
20 ('min_day_of_month', 'max_day_of_month'),
21 ('dow_1', 'dow_2', 'dow_3', 'dow_4', 'dow_5', 'dow_6', 'dow_7'),
22 ('min_hour', 'max_hour'),
26 def _test_email(self, request, obj):
27 if request.user.email:
28 obj.send_test_email(request.user.email)
29 messages.info(request, _('Test e-mail has been sent to %(email)s.') % {"email": request.user.email})
31 messages.warning(request, _('You have no email set. Test e-mail not sent.'))
33 def response_add(self, request, obj):
34 self._test_email(request, obj)
35 return super().response_add(request, obj)
37 def response_change(self, request, obj):
38 self._test_email(request, obj)
39 return super().response_change(request, obj)
42 admin.site.register(models.EmailTemplate, EmailTemplateAdmin)
45 class EmailSentAdmin(admin.ModelAdmin):
46 list_filter = ['template']
47 list_display = ['timestamp', 'template', 'contact', 'subject']
48 fields = ['timestamp', 'template', 'contact', 'subject', 'body']
49 readonly_fields = fields
50 change_links = ['template']
53 admin.site.register(models.EmailSent, EmailSentAdmin)
56 class ContactEmailSentInline(admin.TabularInline):
57 model = models.EmailSent
58 fields = ['timestamp', 'template', 'subject']
59 readonly_fields = ['timestamp', 'template', 'subject']
62 show_change_link = True
64 def has_add_permission(self, request, obj):
68 class ContactAdmin(admin.ModelAdmin):
69 inlines = [ContactEmailSentInline]
70 list_filter = ['level']
71 list_display = ['email', 'level', 'since', 'expires_at']
72 search_fields = ['email']
73 date_hierarchy = 'since'
75 # export_as_csv_action(fields=['id', 'email', 'get_level_display', 'since', 'expires_at']),
76 export_as_csv_action('Eksport dla PHPList', fields=['email', 'wl_optout_url'])
80 admin.site.register(models.Contact, ContactAdmin)