X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/53dd30b74a0b805937dd3a8add59aeb8c5ffeee0..1b80c204be885588f7cbe95610e3677f2f886801:/src/messaging/admin.py diff --git a/src/messaging/admin.py b/src/messaging/admin.py index 854079bee..9ac76b53d 100644 --- a/src/messaging/admin.py +++ b/src/messaging/admin.py @@ -1,12 +1,13 @@ from django.contrib import admin +from django.contrib import messages from django.utils.translation import ugettext_lazy as _ from . import models class EmailSentInline(admin.TabularInline): model = models.EmailSent - fields = ['timestamp', 'email', 'subject'] - readonly_fields = ['timestamp', 'email', 'subject'] + fields = ['timestamp', 'contact', 'subject'] + readonly_fields = ['timestamp', 'contact', 'subject'] extra = 0 can_delete = False show_change_link = True @@ -34,14 +35,29 @@ class EmailTemplateAdmin(admin.ModelAdmin): ]}), ] + def _test_email(self, request, obj): + if request.user.email: + obj.send_test_email(request.user.email) + messages.info(request, _('Test e-mail has been sent to %(email)s.') % {"email": request.user.email}) + else: + messages.warning(request, _('You have no email set. Test e-mail not sent.')) + + def response_add(self, request, obj): + self._test_email(request, obj) + return super().response_add(request, obj) + + def response_change(self, request, obj): + self._test_email(request, obj) + return super().response_change(request, obj) + admin.site.register(models.EmailTemplate, EmailTemplateAdmin) class EmailSentAdmin(admin.ModelAdmin): list_filter = ['template'] - list_display = ['timestamp', 'template', 'email', 'subject'] - fields = ['timestamp', 'template', 'email', 'subject', 'body', 'hash_value'] + list_display = ['timestamp', 'template', 'contact', 'subject'] + fields = ['timestamp', 'template', 'contact', 'subject', 'body'] readonly_fields = fields change_links = ['template']