We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Sendmail plugin: Create new mail based on an old one
**Hey!** If you ever wanted to contribute to an Open Source project, but didn't know how, you just found a perfect place to start. We try to write this issue as instructive as possible, but as we're humans we almost certainly forgot to write something important in here. If you want to try to tackle this issue and get stuck at _any_ point, please do not hesitate and ask us, either here on GitHub or via email at support@pretix.eu. We'll be very happy to help! 

We think this issue is very suitable to people who are just starting with Python or Django development or who never contributed to Open Source before. We'd like to ask people with wide experience in these areas to leave this issue to beginners. Thanks! (If you want something more advanced, just drop us a line, we'll find something :wink:)

## How to get started

First of all, you need pretix running locally on your machine. We have a guide on the developer installation [over here](https://docs.pretix.eu/en/latest/development/setup.html). Play around with it and get a feeling for what pretix is and how it works :) Try to find the places in the interface mentioned in this issue where something needs to change. Maybe try to find the same places in the code? Just searching for characteristic words can be a powerful tool to find your way around.


## What this is about

If you create an event and then (under Settings > Plugins) activate the Sendmail plugin, there will be a new navigation option allowing you to send emails to everyone who ordered a ticket. Thanks to @FlaviaBastos, there is also a navigation item showing you the history of all mails sent through this feature. It would be nice if this history would include a button that allows you to create a new mail *based* on the old one, i.e. pre-fill the sendmail form with the contents from that time.

## How to do this

Find a way to pass the data around to the form. I believe the best way is to create a link in ``pretix/plugins/sendmail/templates/pretixplugins/sendmail/history.html`` that includes the ID of the log entry in a query parameter to the sending view (defined in ``pretix/plugins/sendmail/views.py``). I suggest that you shortly read up on how our [log objects](https://docs.pretix.eu/en/latest/development/implementation/logging.html) work. You can then modify the ``get_form_kwargs`` method of ``SenderView`` to pass the correct [initial values](https://docs.djangoproject.com/en/1.10/ref/forms/api/#dynamic-initial-values) to the form.

## I want to give it a try!

You're still reading, nice! If you want to try working on this, please comment below, so everyone else knows this is being looked at and can search for a different place to contribute. 

First, [fork](https://github.com/pretix/pretix/fork) the repository to your own GitHub account. Then clone it locally (or [set it as your remote](https://help.github.com/articles/configuring-a-remote-for-a-fork/) if you already cloned it earlier) and prepare your pull requests. There are a number of tutorials on the Pull Request workflow online, for example this [short version](https://guides.github.com/introduction/flow/) by GitHub itself and this [more in-depth tutorial](https://www.digitalocean.com/community/tutorials/how-to-create-a-pull-request-on-github). We're excited to see your pull request! 

And don't forget: If you get stuck, don't hestitate to ask. We bound ourselves to a [Code of Conduct](https://docs.pretix.eu/en/latest/development/contribution/codeofconduct.html) and we're committed to providing a welcoming experience and giving constructive, friendly and useful feedback on your contributions.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/pretix/plugins/sendmail/views.py`
Content:
```
1 import logging
2 from datetime import timedelta
3 
4 import pytz
5 from django.contrib import messages
6 from django.db.models import Q
7 from django.shortcuts import redirect
8 from django.utils.formats import date_format
9 from django.utils.timezone import now
10 from django.utils.translation import ugettext_lazy as _
11 from django.views.generic import FormView, ListView
12 
13 from pretix.base.i18n import language
14 from pretix.base.models import LogEntry, Order
15 from pretix.base.services.mail import SendMailException, mail
16 from pretix.control.permissions import EventPermissionRequiredMixin
17 from pretix.multidomain.urlreverse import build_absolute_uri
18 
19 from . import forms
20 
21 logger = logging.getLogger('pretix.plugins.sendmail')
22 
23 
24 class SenderView(EventPermissionRequiredMixin, FormView):
25     template_name = 'pretixplugins/sendmail/send_form.html'
26     permission = 'can_change_orders'
27     form_class = forms.MailForm
28 
29     def get_form_kwargs(self):
30         kwargs = super().get_form_kwargs()
31         kwargs['event'] = self.request.event
32         return kwargs
33 
34     def form_invalid(self, form):
35         messages.error(self.request, _('We could not send the email. See below for details.'))
36         return super().form_invalid(form)
37 
38     def form_valid(self, form):
39         qs = Order.objects.filter(event=self.request.event)
40         statusq = Q(status__in=form.cleaned_data['sendto'])
41         if 'overdue' in form.cleaned_data['sendto']:
42             statusq |= Q(status=Order.STATUS_PENDING, expires__lt=now())
43         orders = qs.filter(statusq)
44 
45         tz = pytz.timezone(self.request.event.settings.timezone)
46 
47         failures = []
48         self.output = {}
49         if not orders:
50             messages.error(self.request, _('There are no orders matching this selection.'))
51             return self.get(self.request, *self.args, **self.kwargs)
52         for o in orders:
53             if self.request.POST.get("action") == "preview":
54                 for l in self.request.event.settings.locales:
55                     with language(l):
56                         self.output[l] = []
57                         self.output[l].append(_('Subject: {subject}').format(subject=form.cleaned_data['subject'].localize(l)))
58                         message = form.cleaned_data['message'].localize(l)
59                         preview_text = message.format(
60                             order='ORDER1234',
61                             event=self.request.event.name,
62                             order_date=date_format(now(), 'SHORT_DATE_FORMAT'),
63                             due_date=date_format(now() + timedelta(days=7), 'SHORT_DATE_FORMAT'),
64                             order_url=build_absolute_uri(self.request.event, 'presale:event.order', kwargs={
65                                 'order': 'ORDER1234',
66                                 'secret': 'longrandomsecretabcdef123456'
67                             }))
68                         self.output[l].append(preview_text)
69                 return self.get(self.request, *self.args, **self.kwargs)
70             else:
71                 try:
72                     with language(o.locale):
73                         mail(o.email, form.cleaned_data['subject'], form.cleaned_data['message'],
74                              {
75                                  'event': o.event,
76                                  'order': o.code,
77                                  'order_date': date_format(o.datetime.astimezone(tz), 'SHORT_DATETIME_FORMAT'),
78                                  'due_date': date_format(o.expires, 'SHORT_DATE_FORMAT'),
79                                  'order_url': build_absolute_uri(o.event, 'presale:event.order', kwargs={
80                                      'order': o.code,
81                                      'secret': o.secret
82                                  })},
83                              self.request.event, locale=o.locale, order=o)
84                         o.log_action(
85                             'pretix.plugins.sendmail.order.email.sent',
86                             user=self.request.user,
87                             data={
88                                 'subject': form.cleaned_data['subject'],
89                                 'message': form.cleaned_data['message'],
90                                 'recipient': o.email
91                             }
92                         )
93                 except SendMailException:
94                     failures.append(o.email)
95         self.request.event.log_action('pretix.plugins.sendmail.sent',
96                                       user=self.request.user,
97                                       data=dict(form.cleaned_data))
98         if failures:
99             messages.error(self.request, _('Failed to send mails to the following users: {}'.format(' '.join(failures))))
100         else:
101             messages.success(self.request, _('Your message has been queued and will be sent to the selected users.'))
102 
103         return redirect(
104             'plugins:sendmail:send',
105             event=self.request.event.slug,
106             organizer=self.request.event.organizer.slug
107         )
108 
109     def get_context_data(self, *args, **kwargs):
110         ctx = super().get_context_data(*args, **kwargs)
111         ctx['output'] = getattr(self, 'output', None)
112         return ctx
113 
114 
115 class EmailHistoryView(EventPermissionRequiredMixin, ListView):
116     template_name = 'pretixplugins/sendmail/history.html'
117     permission = 'can_change_orders'
118     model = LogEntry
119     context_object_name = 'logs'
120     paginate_by = 5
121 
122     def get_queryset(self):
123         qs = LogEntry.objects.filter(
124             event=self.request.event,
125             action_type='pretix.plugins.sendmail.sent'
126         )
127         return qs
128 
129     def get_context_data(self, **kwargs):
130         ctx = super().get_context_data()
131 
132         status = dict(Order.STATUS_CHOICE)
133         status['overdue'] = _('pending with payment overdue')
134         for log in ctx['logs']:
135             log.pdata = log.parsed_data
136             log.pdata['locales'] = {}
137             for locale, msg in log.pdata['message'].items():
138                 log.pdata['locales'][locale] = {
139                     'message': msg,
140                     'subject': log.pdata['subject'][locale]
141                 }
142             log.pdata['sendto'] = [
143                 status[s] for s in log.pdata['sendto']
144             ]
145 
146         return ctx
147
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/pretix/plugins/sendmail/views.py b/src/pretix/plugins/sendmail/views.py
--- a/src/pretix/plugins/sendmail/views.py
+++ b/src/pretix/plugins/sendmail/views.py
@@ -4,13 +4,14 @@
 import pytz
 from django.contrib import messages
 from django.db.models import Q
+from django.http import Http404
 from django.shortcuts import redirect
 from django.utils.formats import date_format
 from django.utils.timezone import now
 from django.utils.translation import ugettext_lazy as _
 from django.views.generic import FormView, ListView
 
-from pretix.base.i18n import language
+from pretix.base.i18n import LazyI18nString, language
 from pretix.base.models import LogEntry, Order
 from pretix.base.services.mail import SendMailException, mail
 from pretix.control.permissions import EventPermissionRequiredMixin
@@ -29,6 +30,18 @@
     def get_form_kwargs(self):
         kwargs = super().get_form_kwargs()
         kwargs['event'] = self.request.event
+        if 'from_log' in self.request.GET:
+            try:
+                from_log_id = self.request.GET.get('from_log')
+                logentry = LogEntry.objects.get(
+                    id=from_log_id,
+                    event=self.request.event,
+                    action_type='pretix.plugins.sendmail.sent'
+                )
+                message = LazyI18nString(logentry.parsed_data['message'])
+                kwargs['initial'] = {'message': message}
+            except LogEntry.DoesNotExist:
+                raise Http404(_('You supplied an invalid log entry ID'))
         return kwargs
 
     def form_invalid(self, form):

{"golden_diff": "diff --git a/src/pretix/plugins/sendmail/views.py b/src/pretix/plugins/sendmail/views.py\n--- a/src/pretix/plugins/sendmail/views.py\n+++ b/src/pretix/plugins/sendmail/views.py\n@@ -4,13 +4,14 @@\n import pytz\n from django.contrib import messages\n from django.db.models import Q\n+from django.http import Http404\n from django.shortcuts import redirect\n from django.utils.formats import date_format\n from django.utils.timezone import now\n from django.utils.translation import ugettext_lazy as _\n from django.views.generic import FormView, ListView\n \n-from pretix.base.i18n import language\n+from pretix.base.i18n import LazyI18nString, language\n from pretix.base.models import LogEntry, Order\n from pretix.base.services.mail import SendMailException, mail\n from pretix.control.permissions import EventPermissionRequiredMixin\n@@ -29,6 +30,18 @@\n     def get_form_kwargs(self):\n         kwargs = super().get_form_kwargs()\n         kwargs['event'] = self.request.event\n+        if 'from_log' in self.request.GET:\n+            try:\n+                from_log_id = self.request.GET.get('from_log')\n+                logentry = LogEntry.objects.get(\n+                    id=from_log_id,\n+                    event=self.request.event,\n+                    action_type='pretix.plugins.sendmail.sent'\n+                )\n+                message = LazyI18nString(logentry.parsed_data['message'])\n+                kwargs['initial'] = {'message': message}\n+            except LogEntry.DoesNotExist:\n+                raise Http404(_('You supplied an invalid log entry ID'))\n         return kwargs\n \n     def form_invalid(self, form):\n", "issue": "Sendmail plugin: Create new mail based on an old one\n**Hey!** If you ever wanted to contribute to an Open Source project, but didn't know how, you just found a perfect place to start. We try to write this issue as instructive as possible, but as we're humans we almost certainly forgot to write something important in here. If you want to try to tackle this issue and get stuck at _any_ point, please do not hesitate and ask us, either here on GitHub or via email at support@pretix.eu. We'll be very happy to help! \r\n\r\nWe think this issue is very suitable to people who are just starting with Python or Django development or who never contributed to Open Source before. We'd like to ask people with wide experience in these areas to leave this issue to beginners. Thanks! (If you want something more advanced, just drop us a line, we'll find something :wink:)\r\n\r\n## How to get started\r\n\r\nFirst of all, you need pretix running locally on your machine. We have a guide on the developer installation [over here](https://docs.pretix.eu/en/latest/development/setup.html). Play around with it and get a feeling for what pretix is and how it works :) Try to find the places in the interface mentioned in this issue where something needs to change. Maybe try to find the same places in the code? Just searching for characteristic words can be a powerful tool to find your way around.\r\n\r\n\r\n## What this is about\r\n\r\nIf you create an event and then (under Settings > Plugins) activate the Sendmail plugin, there will be a new navigation option allowing you to send emails to everyone who ordered a ticket. Thanks to @FlaviaBastos, there is also a navigation item showing you the history of all mails sent through this feature. It would be nice if this history would include a button that allows you to create a new mail *based* on the old one, i.e. pre-fill the sendmail form with the contents from that time.\r\n\r\n## How to do this\r\n\r\nFind a way to pass the data around to the form. I believe the best way is to create a link in ``pretix/plugins/sendmail/templates/pretixplugins/sendmail/history.html`` that includes the ID of the log entry in a query parameter to the sending view (defined in ``pretix/plugins/sendmail/views.py``). I suggest that you shortly read up on how our [log objects](https://docs.pretix.eu/en/latest/development/implementation/logging.html) work. You can then modify the ``get_form_kwargs`` method of ``SenderView`` to pass the correct [initial values](https://docs.djangoproject.com/en/1.10/ref/forms/api/#dynamic-initial-values) to the form.\r\n\r\n## I want to give it a try!\r\n\r\nYou're still reading, nice! If you want to try working on this, please comment below, so everyone else knows this is being looked at and can search for a different place to contribute. \r\n\r\nFirst, [fork](https://github.com/pretix/pretix/fork) the repository to your own GitHub account. Then clone it locally (or [set it as your remote](https://help.github.com/articles/configuring-a-remote-for-a-fork/) if you already cloned it earlier) and prepare your pull requests. There are a number of tutorials on the Pull Request workflow online, for example this [short version](https://guides.github.com/introduction/flow/) by GitHub itself and this [more in-depth tutorial](https://www.digitalocean.com/community/tutorials/how-to-create-a-pull-request-on-github). We're excited to see your pull request! \r\n\r\nAnd don't forget: If you get stuck, don't hestitate to ask. We bound ourselves to a [Code of Conduct](https://docs.pretix.eu/en/latest/development/contribution/codeofconduct.html) and we're committed to providing a welcoming experience and giving constructive, friendly and useful feedback on your contributions.\r\n\n", "before_files": [{"content": "import logging\nfrom datetime import timedelta\n\nimport pytz\nfrom django.contrib import messages\nfrom django.db.models import Q\nfrom django.shortcuts import redirect\nfrom django.utils.formats import date_format\nfrom django.utils.timezone import now\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.generic import FormView, ListView\n\nfrom pretix.base.i18n import language\nfrom pretix.base.models import LogEntry, Order\nfrom pretix.base.services.mail import SendMailException, mail\nfrom pretix.control.permissions import EventPermissionRequiredMixin\nfrom pretix.multidomain.urlreverse import build_absolute_uri\n\nfrom . import forms\n\nlogger = logging.getLogger('pretix.plugins.sendmail')\n\n\nclass SenderView(EventPermissionRequiredMixin, FormView):\n    template_name = 'pretixplugins/sendmail/send_form.html'\n    permission = 'can_change_orders'\n    form_class = forms.MailForm\n\n    def get_form_kwargs(self):\n        kwargs = super().get_form_kwargs()\n        kwargs['event'] = self.request.event\n        return kwargs\n\n    def form_invalid(self, form):\n        messages.error(self.request, _('We could not send the email. See below for details.'))\n        return super().form_invalid(form)\n\n    def form_valid(self, form):\n        qs = Order.objects.filter(event=self.request.event)\n        statusq = Q(status__in=form.cleaned_data['sendto'])\n        if 'overdue' in form.cleaned_data['sendto']:\n            statusq |= Q(status=Order.STATUS_PENDING, expires__lt=now())\n        orders = qs.filter(statusq)\n\n        tz = pytz.timezone(self.request.event.settings.timezone)\n\n        failures = []\n        self.output = {}\n        if not orders:\n            messages.error(self.request, _('There are no orders matching this selection.'))\n            return self.get(self.request, *self.args, **self.kwargs)\n        for o in orders:\n            if self.request.POST.get(\"action\") == \"preview\":\n                for l in self.request.event.settings.locales:\n                    with language(l):\n                        self.output[l] = []\n                        self.output[l].append(_('Subject: {subject}').format(subject=form.cleaned_data['subject'].localize(l)))\n                        message = form.cleaned_data['message'].localize(l)\n                        preview_text = message.format(\n                            order='ORDER1234',\n                            event=self.request.event.name,\n                            order_date=date_format(now(), 'SHORT_DATE_FORMAT'),\n                            due_date=date_format(now() + timedelta(days=7), 'SHORT_DATE_FORMAT'),\n                            order_url=build_absolute_uri(self.request.event, 'presale:event.order', kwargs={\n                                'order': 'ORDER1234',\n                                'secret': 'longrandomsecretabcdef123456'\n                            }))\n                        self.output[l].append(preview_text)\n                return self.get(self.request, *self.args, **self.kwargs)\n            else:\n                try:\n                    with language(o.locale):\n                        mail(o.email, form.cleaned_data['subject'], form.cleaned_data['message'],\n                             {\n                                 'event': o.event,\n                                 'order': o.code,\n                                 'order_date': date_format(o.datetime.astimezone(tz), 'SHORT_DATETIME_FORMAT'),\n                                 'due_date': date_format(o.expires, 'SHORT_DATE_FORMAT'),\n                                 'order_url': build_absolute_uri(o.event, 'presale:event.order', kwargs={\n                                     'order': o.code,\n                                     'secret': o.secret\n                                 })},\n                             self.request.event, locale=o.locale, order=o)\n                        o.log_action(\n                            'pretix.plugins.sendmail.order.email.sent',\n                            user=self.request.user,\n                            data={\n                                'subject': form.cleaned_data['subject'],\n                                'message': form.cleaned_data['message'],\n                                'recipient': o.email\n                            }\n                        )\n                except SendMailException:\n                    failures.append(o.email)\n        self.request.event.log_action('pretix.plugins.sendmail.sent',\n                                      user=self.request.user,\n                                      data=dict(form.cleaned_data))\n        if failures:\n            messages.error(self.request, _('Failed to send mails to the following users: {}'.format(' '.join(failures))))\n        else:\n            messages.success(self.request, _('Your message has been queued and will be sent to the selected users.'))\n\n        return redirect(\n            'plugins:sendmail:send',\n            event=self.request.event.slug,\n            organizer=self.request.event.organizer.slug\n        )\n\n    def get_context_data(self, *args, **kwargs):\n        ctx = super().get_context_data(*args, **kwargs)\n        ctx['output'] = getattr(self, 'output', None)\n        return ctx\n\n\nclass EmailHistoryView(EventPermissionRequiredMixin, ListView):\n    template_name = 'pretixplugins/sendmail/history.html'\n    permission = 'can_change_orders'\n    model = LogEntry\n    context_object_name = 'logs'\n    paginate_by = 5\n\n    def get_queryset(self):\n        qs = LogEntry.objects.filter(\n            event=self.request.event,\n            action_type='pretix.plugins.sendmail.sent'\n        )\n        return qs\n\n    def get_context_data(self, **kwargs):\n        ctx = super().get_context_data()\n\n        status = dict(Order.STATUS_CHOICE)\n        status['overdue'] = _('pending with payment overdue')\n        for log in ctx['logs']:\n            log.pdata = log.parsed_data\n            log.pdata['locales'] = {}\n            for locale, msg in log.pdata['message'].items():\n                log.pdata['locales'][locale] = {\n                    'message': msg,\n                    'subject': log.pdata['subject'][locale]\n                }\n            log.pdata['sendto'] = [\n                status[s] for s in log.pdata['sendto']\n            ]\n\n        return ctx\n", "path": "src/pretix/plugins/sendmail/views.py"}], "after_files": [{"content": "import logging\nfrom datetime import timedelta\n\nimport pytz\nfrom django.contrib import messages\nfrom django.db.models import Q\nfrom django.http import Http404\nfrom django.shortcuts import redirect\nfrom django.utils.formats import date_format\nfrom django.utils.timezone import now\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.generic import FormView, ListView\n\nfrom pretix.base.i18n import LazyI18nString, language\nfrom pretix.base.models import LogEntry, Order\nfrom pretix.base.services.mail import SendMailException, mail\nfrom pretix.control.permissions import EventPermissionRequiredMixin\nfrom pretix.multidomain.urlreverse import build_absolute_uri\n\nfrom . import forms\n\nlogger = logging.getLogger('pretix.plugins.sendmail')\n\n\nclass SenderView(EventPermissionRequiredMixin, FormView):\n    template_name = 'pretixplugins/sendmail/send_form.html'\n    permission = 'can_change_orders'\n    form_class = forms.MailForm\n\n    def get_form_kwargs(self):\n        kwargs = super().get_form_kwargs()\n        kwargs['event'] = self.request.event\n        if 'from_log' in self.request.GET:\n            try:\n                from_log_id = self.request.GET.get('from_log')\n                logentry = LogEntry.objects.get(\n                    id=from_log_id,\n                    event=self.request.event,\n                    action_type='pretix.plugins.sendmail.sent'\n                )\n                message = LazyI18nString(logentry.parsed_data['message'])\n                kwargs['initial'] = {'message': message}\n            except LogEntry.DoesNotExist:\n                raise Http404(_('You supplied an invalid log entry ID'))\n        return kwargs\n\n    def form_invalid(self, form):\n        messages.error(self.request, _('We could not send the email. See below for details.'))\n        return super().form_invalid(form)\n\n    def form_valid(self, form):\n        qs = Order.objects.filter(event=self.request.event)\n        statusq = Q(status__in=form.cleaned_data['sendto'])\n        if 'overdue' in form.cleaned_data['sendto']:\n            statusq |= Q(status=Order.STATUS_PENDING, expires__lt=now())\n        orders = qs.filter(statusq)\n\n        tz = pytz.timezone(self.request.event.settings.timezone)\n\n        failures = []\n        self.output = {}\n        if not orders:\n            messages.error(self.request, _('There are no orders matching this selection.'))\n            return self.get(self.request, *self.args, **self.kwargs)\n        for o in orders:\n            if self.request.POST.get(\"action\") == \"preview\":\n                for l in self.request.event.settings.locales:\n                    with language(l):\n                        self.output[l] = []\n                        self.output[l].append(_('Subject: {subject}').format(subject=form.cleaned_data['subject'].localize(l)))\n                        message = form.cleaned_data['message'].localize(l)\n                        preview_text = message.format(\n                            order='ORDER1234',\n                            event=self.request.event.name,\n                            order_date=date_format(now(), 'SHORT_DATE_FORMAT'),\n                            due_date=date_format(now() + timedelta(days=7), 'SHORT_DATE_FORMAT'),\n                            order_url=build_absolute_uri(self.request.event, 'presale:event.order', kwargs={\n                                'order': 'ORDER1234',\n                                'secret': 'longrandomsecretabcdef123456'\n                            }))\n                        self.output[l].append(preview_text)\n                return self.get(self.request, *self.args, **self.kwargs)\n            else:\n                try:\n                    with language(o.locale):\n                        mail(o.email, form.cleaned_data['subject'], form.cleaned_data['message'],\n                             {\n                                 'event': o.event,\n                                 'order': o.code,\n                                 'order_date': date_format(o.datetime.astimezone(tz), 'SHORT_DATETIME_FORMAT'),\n                                 'due_date': date_format(o.expires, 'SHORT_DATE_FORMAT'),\n                                 'order_url': build_absolute_uri(o.event, 'presale:event.order', kwargs={\n                                     'order': o.code,\n                                     'secret': o.secret\n                                 })},\n                             self.request.event, locale=o.locale, order=o)\n                        o.log_action(\n                            'pretix.plugins.sendmail.order.email.sent',\n                            user=self.request.user,\n                            data={\n                                'subject': form.cleaned_data['subject'],\n                                'message': form.cleaned_data['message'],\n                                'recipient': o.email\n                            }\n                        )\n                except SendMailException:\n                    failures.append(o.email)\n        self.request.event.log_action('pretix.plugins.sendmail.sent',\n                                      user=self.request.user,\n                                      data=dict(form.cleaned_data))\n        if failures:\n            messages.error(self.request, _('Failed to send mails to the following users: {}'.format(' '.join(failures))))\n        else:\n            messages.success(self.request, _('Your message has been queued and will be sent to the selected users.'))\n\n        return redirect(\n            'plugins:sendmail:send',\n            event=self.request.event.slug,\n            organizer=self.request.event.organizer.slug\n        )\n\n    def get_context_data(self, *args, **kwargs):\n        ctx = super().get_context_data(*args, **kwargs)\n        ctx['output'] = getattr(self, 'output', None)\n        return ctx\n\n\nclass EmailHistoryView(EventPermissionRequiredMixin, ListView):\n    template_name = 'pretixplugins/sendmail/history.html'\n    permission = 'can_change_orders'\n    model = LogEntry\n    context_object_name = 'logs'\n    paginate_by = 5\n\n    def get_queryset(self):\n        qs = LogEntry.objects.filter(\n            event=self.request.event,\n            action_type='pretix.plugins.sendmail.sent'\n        )\n        return qs\n\n    def get_context_data(self, **kwargs):\n        ctx = super().get_context_data()\n\n        status = dict(Order.STATUS_CHOICE)\n        status['overdue'] = _('pending with payment overdue')\n        for log in ctx['logs']:\n            log.pdata = log.parsed_data\n            log.pdata['locales'] = {}\n            for locale, msg in log.pdata['message'].items():\n                log.pdata['locales'][locale] = {\n                    'message': msg,\n                    'subject': log.pdata['subject'][locale]\n                }\n            log.pdata['sendto'] = [\n                status[s] for s in log.pdata['sendto']\n            ]\n\n        return ctx\n", "path": "src/pretix/plugins/sendmail/views.py"}]}