Add "resend link" option to attendees

This commit is contained in:
Raphael Michel
2019-09-10 11:44:20 +02:00
parent 3a4fc69db1
commit 586e544fce
4 changed files with 61 additions and 8 deletions

View File

@@ -1914,25 +1914,26 @@ class OrderPosition(AbstractPosition):
""" """
from pretix.base.services.mail import SendMailException, mail, render_mail from pretix.base.services.mail import SendMailException, mail, render_mail
if not self.email: if not self.attendee_email:
return return
for k, v in self.event.meta_data.items(): for k, v in self.event.meta_data.items():
context['meta_' + k] = v context['meta_' + k] = v
with language(self.locale): with language(self.order.locale):
recipient = self.email recipient = self.attendee_email
try: try:
email_content = render_mail(template, context) email_content = render_mail(template, context)
mail( mail(
recipient, subject, template, context, recipient, subject, template, context,
self.event, self.locale, self, headers, sender, self.event, self.order.locale, order=self.order, headers=headers, sender=sender,
position=self,
invoices=invoices, attach_tickets=attach_tickets invoices=invoices, attach_tickets=attach_tickets
) )
except SendMailException: except SendMailException:
raise raise
else: else:
self.log_action( self.order.log_action(
log_entry_type, log_entry_type,
user=user, user=user,
auth=auth, auth=auth,
@@ -1945,6 +1946,40 @@ class OrderPosition(AbstractPosition):
} }
) )
def resend_link(self, user=None, auth=None):
from pretix.multidomain.urlreverse import build_absolute_uri
with language(self.order.locale):
try:
invoice_name = self.order.invoice_address.name
invoice_company = self.order.invoice_address.company
except InvoiceAddress.DoesNotExist:
invoice_name = ""
invoice_company = ""
if self.attendee_name:
invoice_name = self.attendee_name
email_template = self.event.settings.mail_text_resend_link
email_context = {
'event': self.event.name,
'url': build_absolute_uri(self.event, 'presale:event.order.position', kwargs={
'order': self.order.code,
'secret': self.web_secret,
'position': self.positionid
}),
'invoice_name': invoice_name,
'invoice_company': invoice_company,
'attendee_name': self.attendee_name,
}
name_scheme = PERSON_NAME_SCHEMES[self.event.settings.name_scheme]
for f, l, w in name_scheme['fields']:
email_context['attendee_name_%s' % f] = self.attendee_name_parts.get(f, '')
email_subject = _('Your event registration: %(code)s') % {'code': self.order.code}
self.send_mail(
email_subject, email_template, email_context,
'pretix.event.order.email.resend', user=user, auth=auth,
attach_tickets=True
)
class CartPosition(AbstractPosition): class CartPosition(AbstractPosition):
""" """

View File

@@ -315,8 +315,20 @@
{% endif %} {% endif %}
{% if line.item.admission and event.settings.attendee_emails_asked %} {% if line.item.admission and event.settings.attendee_emails_asked %}
<dt>{% trans "Attendee email" %}</dt> <dt>{% trans "Attendee email" %}</dt>
<dd>{% if line.attendee_email %}{{ line.attendee_email }}{% else %} <dd>
<em>{% trans "not answered" %}</em>{% endif %}</dd> {% if line.attendee_email and not line.addon_to %}
{{ line.attendee_email }}
<form class="form-inline helper-display-inline" method="post"
action="{% url "control:event.order.resendlink" event=request.event.slug organizer=request.event.organizer.slug code=order.code position=line.pk %}">
{% csrf_token %}
<button class="btn btn-default btn-xs">
{% trans "Resend link" %}
</button>
</form>
{% else %}
<em>{% trans "not answered" %}</em>
{% endif %}
</dd>
{% endif %} {% endif %}
{% for q in line.questions %} {% for q in line.questions %}
<dt> <dt>

View File

@@ -196,6 +196,8 @@ urlpatterns = [
name='event.order.transition'), name='event.order.transition'),
url(r'^orders/(?P<code>[0-9A-Z]+)/resend$', orders.OrderResendLink.as_view(), url(r'^orders/(?P<code>[0-9A-Z]+)/resend$', orders.OrderResendLink.as_view(),
name='event.order.resendlink'), name='event.order.resendlink'),
url(r'^orders/(?P<code>[0-9A-Z]+)/(?P<position>\d+)/resend$', orders.OrderResendLink.as_view(),
name='event.order.resendlink'),
url(r'^orders/(?P<code>[0-9A-Z]+)/invoice$', orders.OrderInvoiceCreate.as_view(), url(r'^orders/(?P<code>[0-9A-Z]+)/invoice$', orders.OrderInvoiceCreate.as_view(),
name='event.order.geninvoice'), name='event.order.geninvoice'),
url(r'^orders/(?P<code>[0-9A-Z]+)/invoices/(?P<id>\d+)/regenerate$', orders.OrderInvoiceRegenerate.as_view(), url(r'^orders/(?P<code>[0-9A-Z]+)/invoices/(?P<id>\d+)/regenerate$', orders.OrderInvoiceRegenerate.as_view(),

View File

@@ -1067,7 +1067,11 @@ class OrderResendLink(OrderView):
def post(self, *args, **kwargs): def post(self, *args, **kwargs):
try: try:
self.order.resend_link(user=self.request.user) if 'position' in kwargs:
p = get_object_or_404(self.order.positions, pk=kwargs['position'])
p.resend_link(user=self.request.user)
else:
self.order.resend_link(user=self.request.user)
except SendMailException: except SendMailException:
messages.error(self.request, _('There was an error sending the mail. Please try again later.')) messages.error(self.request, _('There was an error sending the mail. Please try again later.'))
return redirect(self.get_order_url()) return redirect(self.get_order_url())