Order email history: Record more information about attachments (Z#23185463) (#4914)

This commit is contained in:
Raphael Michel
2025-03-18 08:58:54 +01:00
committed by GitHub
parent fcd8c82092
commit f475781a89
6 changed files with 92 additions and 24 deletions

View File

@@ -1199,6 +1199,8 @@ class Order(LockModel, LoggedModel):
'invoices': [i.pk for i in invoices] if invoices else [], 'invoices': [i.pk for i in invoices] if invoices else [],
'attach_tickets': attach_tickets, 'attach_tickets': attach_tickets,
'attach_ical': attach_ical, 'attach_ical': attach_ical,
'attach_other_files': attach_other_files,
'attach_cached_files': [cf.filename for cf in attach_cached_files] if attach_cached_files else [],
} }
) )
@@ -2857,6 +2859,8 @@ class OrderPosition(AbstractPosition):
'invoices': [i.pk for i in invoices] if invoices else [], 'invoices': [i.pk for i in invoices] if invoices else [],
'attach_tickets': attach_tickets, 'attach_tickets': attach_tickets,
'attach_ical': attach_ical, 'attach_ical': attach_ical,
'attach_other_files': attach_other_files,
'attach_cached_files': [],
} }
) )

View File

@@ -286,6 +286,8 @@ class WaitingListEntry(LoggedModel):
'subject': subject, 'subject': subject,
'message': email_content, 'message': email_content,
'recipient': recipient, 'recipient': recipient,
'attach_other_files': attach_other_files,
'attach_cached_files': [cf.filename for cf in attach_cached_files] if attach_cached_files else [],
} }
) )

View File

@@ -51,6 +51,41 @@
{{ log.parsed_data.subject }}</strong> {{ log.parsed_data.subject }}</strong>
</p> </p>
<pre>{{ log.parsed_data.message }}</pre> <pre>{{ log.parsed_data.message }}</pre>
<ul class="list-unstyled">
{% if log.parsed_data.attach_tickets %}
<li><span class="fa fa-files-o fa-fw"></span> {% trans "Tickets" %}</li>
{% endif %}
{% if log.parsed_data.attach_ical %}
<li><span class="fa fa-calendar-o fa-fw"></span> {% trans "Calendar invite" %}</li>
{% endif %}
{% if log.parsed_data.invoices %}
{% for i in log.parsed_invoices %}
<li>
<span class="fa fa-file-o fa-fw"></span>
<a href="{% url "control:event.invoice.download" invoice=i.pk event=request.event.slug organizer=request.event.organizer.slug %}" target="_blank">
{% if i.is_cancellation %}{% trans "Cancellation" context "invoice" %}{% else %}{% trans "Invoice" %}{% endif %}
{{ i.number }}
</a>
</li>
{% endfor %}
{% endif %}
{% if log.parsed_data.attach_other_files %}
{% for f in log.parsed_other_files %}
<li>
<span class="fa fa-file-o fa-fw"></span>
{{ f }}
</li>
{% endfor %}
{% endif %}
{% if log.parsed_data.attach_cached_files %}
{% for f in log.parsed_data.attach_cached_files %}
<li>
<span class="fa fa-file-o fa-fw"></span>
{{ f }}
</li>
{% endfor %}
{% endif %}
</ul>
{% endif %} {% endif %}
</li> </li>
{% endfor %} {% endfor %}

View File

@@ -135,6 +135,7 @@ from pretix.control.views import PaginationMixin
from pretix.helpers import OF_SELF from pretix.helpers import OF_SELF
from pretix.helpers.compat import CompatDeleteView from pretix.helpers.compat import CompatDeleteView
from pretix.helpers.format import SafeFormatter, format_map from pretix.helpers.format import SafeFormatter, format_map
from pretix.helpers.hierarkey import clean_filename
from pretix.helpers.safedownload import check_token from pretix.helpers.safedownload import check_token
from pretix.presale.signals import question_form_fields from pretix.presale.signals import question_form_fields
@@ -2461,6 +2462,20 @@ class OrderEmailHistory(EventPermissionRequiredMixin, OrderViewMixin, ListView):
) )
return qs return qs
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
for l in ctx["logs"]:
if l.parsed_data.get("invoices"):
l.parsed_invoices = Invoice.objects.filter(
event=self.request.event,
pk__in=l.parsed_data["invoices"],
)
if l.parsed_data.get("attach_other_files"):
l.parsed_other_files = [
clean_filename(os.path.basename(f)) for f in l.parsed_data["attach_other_files"]
]
return ctx
class AnswerDownload(EventPermissionRequiredMixin, OrderViewMixin, ListView): class AnswerDownload(EventPermissionRequiredMixin, OrderViewMixin, ListView):
permission = 'can_view_orders' permission = 'can_view_orders'

View File

@@ -38,7 +38,9 @@ from i18nfield.strings import LazyI18nString
from pretix.base.email import get_email_context from pretix.base.email import get_email_context
from pretix.base.i18n import language from pretix.base.i18n import language
from pretix.base.models import Checkin, Event, InvoiceAddress, Order, User from pretix.base.models import (
CachedFile, Checkin, Event, InvoiceAddress, Order, User,
)
from pretix.base.services.mail import SendMailException, mail from pretix.base.services.mail import SendMailException, mail
from pretix.base.services.tasks import ProfiledEventTask from pretix.base.services.tasks import ProfiledEventTask
from pretix.celery_app import app from pretix.celery_app import app
@@ -56,6 +58,7 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
orders = Order.objects.filter(pk__in=objects, event=event) orders = Order.objects.filter(pk__in=objects, event=event)
subject = LazyI18nString(subject) subject = LazyI18nString(subject)
message = LazyI18nString(message) message = LazyI18nString(message)
attachments_for_log = [cf.filename for cf in CachedFile.objects.filter(pk__in=attachments)] if attachments else []
for o in orders: for o in orders:
send_to_order = recipients in ('both', 'orders') send_to_order = recipients in ('both', 'orders')
@@ -134,7 +137,11 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
'position': p.positionid, 'position': p.positionid,
'subject': format_map(subject.localize(o.locale), email_context), 'subject': format_map(subject.localize(o.locale), email_context),
'message': format_map(message.localize(o.locale), email_context), 'message': format_map(message.localize(o.locale), email_context),
'recipient': p.attendee_email 'recipient': p.attendee_email,
'attach_tickets': attach_tickets,
'attach_ical': attach_ical,
'attach_other_files': [],
'attach_cached_files': attachments_for_log,
} }
) )
except SendMailException: except SendMailException:
@@ -162,7 +169,11 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
data={ data={
'subject': format_map(subject.localize(o.locale), email_context), 'subject': format_map(subject.localize(o.locale), email_context),
'message': format_map(message.localize(o.locale), email_context), 'message': format_map(message.localize(o.locale), email_context),
'recipient': o.email 'recipient': o.email,
'attach_tickets': attach_tickets,
'attach_ical': attach_ical,
'attach_other_files': [],
'attach_cached_files': attachments_for_log,
} }
) )
except SendMailException: except SendMailException:

View File

@@ -45,27 +45,28 @@
<div lang="{{ locale }}" class="mail-preview"> <div lang="{{ locale }}" class="mail-preview">
<strong>{{ out.subject|safe }}</strong><br><br> <strong>{{ out.subject|safe }}</strong><br><br>
{{ out.html|safe }} {{ out.html|safe }}
{% if out.attachment %} <ul class="list-unstyled">
<p> {% if out.attachment %}
<a href="{% url 'cachedfile.download' id=out.attachment.id %}" class="btn btn-default" <li>
target="_blank"> <span class="fa fa-file-o fa-fw" aria-hidden="true"></span>
<span class="fa fa-file" aria-hidden="true"></span> <a href="{% url 'cachedfile.download' id=out.attachment.id %}" target="_blank">
{{ out.attachment.filename }} {{ out.attachment.filename }}
</a> </a>
</p> </li>
{% endif %} {% endif %}
{% if form.cleaned_data.attach_tickets %} {% if form.cleaned_data.attach_tickets %}
<p> <li>
<span class="fa fa-file" aria-hidden="true"></span> <span class="fa fa-file-o fa-fw" aria-hidden="true"></span>
{% trans "Tickets" %} {% trans "Tickets" %}
</p> </li>
{% endif %} {% endif %}
{% if form.cleaned_data.attach_ical %} {% if form.cleaned_data.attach_ical %}
<p> <li>
<span class="fa fa-file" aria-hidden="true"></span> <span class="fa fa-calendar-o fa-fw" aria-hidden="true"></span>
{% trans "Attach calendar files" %} {% trans "Attach calendar files" %}
</p> </li>
{% endif %} {% endif %}
</ul>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>