1 from django.contrib import admin
2 from django.contrib import messages
3 from django.utils.translation import ugettext_lazy as _
7 class EmailSentInline(admin.TabularInline):
8 model = models.EmailSent
9 fields = ['timestamp', 'contact', 'subject']
10 readonly_fields = ['timestamp', 'contact', 'subject']
13 show_change_link = True
15 def has_add_permission(self, request, obj):
19 class EmailTemplateAdmin(admin.ModelAdmin):
20 list_display = ['state', 'min_days_since', 'subject', 'min_hour']
21 inlines = [EmailSentInline]
25 ('min_days_since', 'max_days_since'),
28 (_('E-mail content'), {"fields": [
31 (_('Sending constraints'), {"fields": [
32 ('min_day_of_month', 'max_day_of_month'),
33 ('dow_1', 'dow_2', 'dow_3', 'dow_4', 'dow_5', 'dow_6', 'dow_7'),
34 ('min_hour', 'max_hour'),
38 def _test_email(self, request, obj):
39 if request.user.email:
40 obj.send_test_email(request.user.email)
41 messages.info(request, _('Test e-mail has been sent to %(email)s.') % {"email": request.user.email})
43 messages.warning(request, _('You have no email set. Test e-mail not sent.'))
45 def response_add(self, request, obj):
46 self._test_email(request, obj)
47 return super().response_add(request, obj)
49 def response_change(self, request, obj):
50 self._test_email(request, obj)
51 return super().response_change(request, obj)
54 admin.site.register(models.EmailTemplate, EmailTemplateAdmin)
57 class EmailSentAdmin(admin.ModelAdmin):
58 list_filter = ['template']
59 list_display = ['timestamp', 'template', 'contact', 'subject']
60 fields = ['timestamp', 'template', 'contact', 'subject', 'body']
61 readonly_fields = fields
62 change_links = ['template']
65 admin.site.register(models.EmailSent, EmailSentAdmin)
68 class ContactAdmin(admin.ModelAdmin):
69 list_filter = ['level']
70 list_display = ['email', 'level', 'since', 'expires_at']
71 search_fields = ['email']
72 date_hierarchy = 'since'
75 admin.site.register(models.Contact, ContactAdmin)