Repository: pretix/pretix

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.



Discussion:
Hi, @raphaelm!
I also would like to try this task. :)
Sure, give it a try!

Resolving patch:
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 @@ class SenderView(EventPermissionRequiredMixin, FormView):
     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):


Test patch: