diff --git a/jdav_web/mailer/admin.py b/jdav_web/mailer/admin.py index abead81..9c7da22 100644 --- a/jdav_web/mailer/admin.py +++ b/jdav_web/mailer/admin.py @@ -1,5 +1,7 @@ from django.contrib import admin +from django.contrib.admin import helpers from django.utils.translation import ugettext_lazy as _ +from django.shortcuts import render from .models import Message @@ -26,18 +28,30 @@ class ButtonableModelAdmin(admin.ModelAdmin): class MessageAdmin(ButtonableModelAdmin): """Message creation view""" - list_display = ('subject', 'from_addr', 'to_group') + list_display = ('subject', 'from_addr', 'to_group', 'sent') + # TODO: get this working # can't find a good solution for this at the moment - # send_message = Button() - # send_message.short_description = _("Send") - # send_message.view = "mailer:index" - # buttons = [send_message] + send_message = Button() + send_message.short_description = _("Send") + send_message.view = "mailer:send_mail" + buttons = [send_message] actions = ['send_message'] def send_message(self, request, queryset): - for msg in queryset: - msg.submit() - self.message_user(request, _("Message sent")) + print("calling send_message") + if request.POST.get('confirmed'): + for msg in queryset: + msg.submit() + self.message_user(request, _("Message sent")) + else: + context = { + 'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME, + 'mails': queryset, + 'ids': queryset.values_list("id"), + 'some_sent': any(m.sent for m in queryset)} + return render(request, 'mailer/confirm_send.html', context) + send_message.short_description = _("Send message") + admin.site.register(Message, MessageAdmin) diff --git a/jdav_web/mailer/locale/de/LC_MESSAGES/django.po b/jdav_web/mailer/locale/de/LC_MESSAGES/django.po index 8d7a2ad..bc20696 100644 --- a/jdav_web/mailer/locale/de/LC_MESSAGES/django.po +++ b/jdav_web/mailer/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-10-22 18:28+0200\n" +"POT-Creation-Date: 2016-11-19 13:59+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,10 +18,18 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: admin.py:41 +#: admin.py:36 templates/mailer/confirm_send.html:30 +msgid "Send" +msgstr "Senden" + +#: admin.py:46 msgid "Message sent" msgstr "Nachricht gesendet" +#: admin.py:54 +msgid "Send message" +msgstr "Nachricht verschicken" + #: apps.py:7 msgid "mailer" msgstr "Verteiler" @@ -42,18 +50,69 @@ msgstr "Inhalt" msgid "to group" msgstr "An Gruppe" -#: models.py:23 +#: models.py:13 +msgid "sent" +msgstr "Gesendet" + +#: models.py:29 msgid "message" msgstr "Nachricht" -#: models.py:24 +#: models.py:30 msgid "messages" msgstr "Nachrichten" -#: templates/admin/change_form.html:10 +#: models.py:32 +msgid "Can submit mails" +msgstr "Kann Mails verschicken" + +#: templates/admin/change_form.html:12 msgid "History" msgstr "Geschichte" +#: templates/mailer/confirm_send.html:7 +msgid "Do you really want to send these mails?" +msgstr "Möchtest du diese Emails wirklich verschicken?" + +#: templates/mailer/confirm_send.html:13 +msgid "already sent" +msgstr "schon verschickt" + +#: templates/mailer/confirm_send.html:19 +msgid "" +"Some messages have already been sent! Do you really want to resend them?" +msgstr "" +"Einige Emails wurden schon versendet! Möchtest du diese wirklich nochmal " +"senden?" + +#: templates/mailer/confirm_send.html:35 +msgid "Cancel" +msgstr "Abbruch" + #: templates/mailer/index.html:2 msgid "This is the mailer app!" msgstr "Das ist die Mailer App!" + +#: templates/mailer/send.html:2 +msgid "Here you can send new emails!" +msgstr "Hier kannst du neue Emails verschicken!" + +#: templates/mailer/send.html:11 +msgid "Subject:" +msgstr "Betreff" + +#: templates/mailer/send.html:14 +msgid "Content:" +msgstr "Inhalt:" + +#: templates/mailer/send.html:17 +msgid "Receiving group:" +msgstr "Erhaltende Gruppe" + +#: templates/mailer/send.html:24 +msgid "Send mail" +msgstr "Email senden" + +#: views.py:33 +msgid "Please fill in every field!" +msgstr "Bitte jedes Feld ausfüllen!" diff --git a/jdav_web/mailer/models.py b/jdav_web/mailer/models.py index 475b8d0..0498719 100644 --- a/jdav_web/mailer/models.py +++ b/jdav_web/mailer/models.py @@ -10,6 +10,7 @@ class Message(models.Model): subject = models.CharField(_('subject'), max_length=50) content = models.TextField(_('content')) to_group = models.ForeignKey('members.Group', verbose_name=_('to group')) + sent = models.BooleanField(_('sent'), default=False) def __str__(self): return self.subject @@ -21,6 +22,8 @@ class Message(models.Model): for member in self.to_group.member_set.all() ] send_mass_mail(data) + self.sent = True + self.save() class Meta: verbose_name = _('message') diff --git a/jdav_web/mailer/static/admin/style.css b/jdav_web/mailer/static/admin/style.css new file mode 100644 index 0000000..5d34418 --- /dev/null +++ b/jdav_web/mailer/static/admin/style.css @@ -0,0 +1,4 @@ +form { + float:left; + margin-right:30px; +} diff --git a/jdav_web/mailer/templates/admin/change_form.html b/jdav_web/mailer/templates/admin/change_form.html index 226923d..3e71d7b 100644 --- a/jdav_web/mailer/templates/admin/change_form.html +++ b/jdav_web/mailer/templates/admin/change_form.html @@ -1,11 +1,13 @@ {% extends "admin/change_form.html" %} {% load i18n %} +{% load custom_send %} {% block object-tools %} {% if change %}{% if not is_popup %}