mirror of
https://github.com/pretix/pretix.git
synced 2026-09-13 16:14:40 +00:00
Fix #307 -- Log sent emails
This commit is contained in:
committed by
Raphael Michel
parent
adbe966d85
commit
cf334e2b48
@@ -8,4 +8,3 @@ dist/
|
|||||||
*.egg-info/
|
*.egg-info/
|
||||||
*.bak
|
*.bak
|
||||||
static/jsi18n/
|
static/jsi18n/
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db import models
|
from django.db import models
|
||||||
@@ -124,3 +125,7 @@ class LogEntry(models.Model):
|
|||||||
return a_text
|
return a_text
|
||||||
else:
|
else:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def parsed_data(self):
|
||||||
|
return json.loads(self.data)
|
||||||
|
|||||||
@@ -98,12 +98,28 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% for nav in nav_event %}
|
{% for nav in nav_event %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ nav.url }}" {% if nav.active %}class="active"{% endif %}>
|
<a href="{{ nav.url }}" {% if nav.active %}class="active"{% endif %}
|
||||||
|
{% if nav.children %}class="has-children"{% endif %}>
|
||||||
{% if nav.icon %}
|
{% if nav.icon %}
|
||||||
<i class="fa fa-{{ nav.icon }} fa-fw"></i>
|
<i class="fa fa-{{ nav.icon }} fa-fw"></i>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ nav.label }}
|
{{ nav.label }}
|
||||||
</a>
|
</a>
|
||||||
|
{% if nav.children %}
|
||||||
|
<a href="#" class="arrow">
|
||||||
|
<span class="fa arrow"></span>
|
||||||
|
</a>
|
||||||
|
<ul class="nav nav-second-level">
|
||||||
|
{% for item in nav.children %}
|
||||||
|
<li>
|
||||||
|
<a href="{{ item.url }}"
|
||||||
|
{% if item.active %}class="active"{% endif %}>
|
||||||
|
{{ item.label }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from django.core.urlresolvers import resolve, reverse
|
|||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from pretix.base.signals import logentry_display
|
||||||
from pretix.control.signals import nav_event
|
from pretix.control.signals import nav_event
|
||||||
|
|
||||||
|
|
||||||
@@ -19,5 +20,32 @@ def control_nav_import(sender, request=None, **kwargs):
|
|||||||
}),
|
}),
|
||||||
'active': (url.namespace == 'plugins:sendmail' and url.url_name == 'send'),
|
'active': (url.namespace == 'plugins:sendmail' and url.url_name == 'send'),
|
||||||
'icon': 'envelope',
|
'icon': 'envelope',
|
||||||
}
|
'children': [
|
||||||
|
{
|
||||||
|
'label': _('Send email'),
|
||||||
|
'url': reverse('plugins:sendmail:send', kwargs={
|
||||||
|
'event': request.event.slug,
|
||||||
|
'organizer': request.event.organizer.slug,
|
||||||
|
}),
|
||||||
|
'active': (url.namespace == 'plugins:sendmail' and url.url_name == 'send'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'label': _('Email history'),
|
||||||
|
'url': reverse('plugins:sendmail:history', kwargs={
|
||||||
|
'event': request.event.slug,
|
||||||
|
'organizer': request.event.organizer.slug,
|
||||||
|
}),
|
||||||
|
'active': (url.namespace == 'plugins:sendmail' and url.url_name == 'history'),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(signal=logentry_display)
|
||||||
|
def pretixcontrol_logentry_display(sender, logentry, **kwargs):
|
||||||
|
plains = {
|
||||||
|
'pretix.plugins.sendmail.sent': _('Email was sent'),
|
||||||
|
}
|
||||||
|
if logentry.action_type in plains:
|
||||||
|
return plains[logentry.action_type]
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
{% extends "pretixcontrol/event/base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% load bootstrap3 %}
|
||||||
|
{% block title %}{% trans "Send out emails" %}{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>{% trans "Email history" %}</h1>
|
||||||
|
<div>
|
||||||
|
<ul class="list-group">
|
||||||
|
{% for log in logs %}
|
||||||
|
<li class="list-group-item logentry">
|
||||||
|
<p class="meta">
|
||||||
|
<span class="fa fa-clock-o"></span> {{ log.datetime|date:"SHORT_DATETIME_FORMAT" }}
|
||||||
|
{% if log.user %}
|
||||||
|
<br/><span class="fa fa-user"></span> {{ log.user.get_full_name }}
|
||||||
|
{% endif %}
|
||||||
|
{% if log.display %}
|
||||||
|
<br/><span class="fa fa-comment-o"></span> {{ log.display }}
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>Email address:</strong> {{ log.parsed_data.recipients }}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>Subject:</strong>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
{% for key,value in log.parsed_data.subject.items %}
|
||||||
|
<p>
|
||||||
|
{{ key }}: {{ value }}
|
||||||
|
</p>
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>Email content:</strong>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
{% for key,value in log.parsed_data.message.items %}
|
||||||
|
<p>
|
||||||
|
{{ key }}:
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
{{ value|linebreaksbr }}
|
||||||
|
</p>
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% include "pretixcontrol/pagination.html" %}
|
||||||
|
{% endblock %}
|
||||||
@@ -3,6 +3,7 @@ from django.conf.urls import url
|
|||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^control/event/(?P<organizer>[^/]+)/(?P<event>[^/]+)/sendmail/', views.SenderView.as_view(),
|
url(r'^control/event/(?P<organizer>[^/]+)/(?P<event>[^/]+)/sendmail/$', views.SenderView.as_view(),
|
||||||
name='send'),
|
name='send'),
|
||||||
|
url(r'^control/event/(?P<organizer>[^/]+)/(?P<event>[^/]+)/sendmail/history/', views.EmailHistoryView.as_view(), name='history')
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ from django.shortcuts import redirect
|
|||||||
from django.utils.formats import date_format
|
from django.utils.formats import date_format
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.views.generic import FormView
|
from django.views.generic import FormView, ListView
|
||||||
|
|
||||||
from pretix.base.i18n import language
|
from pretix.base.i18n import language
|
||||||
from pretix.base.models import Order
|
from pretix.base.models import LogEntry, Order
|
||||||
from pretix.base.services.mail import SendMailException, mail
|
from pretix.base.services.mail import SendMailException, mail
|
||||||
from pretix.control.permissions import EventPermissionRequiredMixin
|
from pretix.control.permissions import EventPermissionRequiredMixin
|
||||||
from pretix.multidomain.urlreverse import build_absolute_uri
|
from pretix.multidomain.urlreverse import build_absolute_uri
|
||||||
@@ -38,9 +38,6 @@ class SenderView(EventPermissionRequiredMixin, FormView):
|
|||||||
statusq |= Q(status=Order.STATUS_PENDING, expires__lt=now())
|
statusq |= Q(status=Order.STATUS_PENDING, expires__lt=now())
|
||||||
orders = qs.filter(statusq)
|
orders = qs.filter(statusq)
|
||||||
|
|
||||||
self.request.event.log_action('pretix.plugins.sendmail.sent', user=self.request.user, data=dict(
|
|
||||||
form.cleaned_data))
|
|
||||||
|
|
||||||
tz = pytz.timezone(self.request.event.settings.timezone)
|
tz = pytz.timezone(self.request.event.settings.timezone)
|
||||||
|
|
||||||
failures = []
|
failures = []
|
||||||
@@ -77,9 +74,20 @@ class SenderView(EventPermissionRequiredMixin, FormView):
|
|||||||
'secret': o.secret
|
'secret': o.secret
|
||||||
})},
|
})},
|
||||||
self.request.event, locale=o.locale, order=o)
|
self.request.event, locale=o.locale, order=o)
|
||||||
|
o.log_action(
|
||||||
|
'pretix.plugins.sendmail.order.email.sent',
|
||||||
|
user=self.request.user,
|
||||||
|
data={
|
||||||
|
'subject': form.cleaned_data['subject'],
|
||||||
|
'content': form.cleaned_data['message'],
|
||||||
|
'recipients': o.email
|
||||||
|
}
|
||||||
|
)
|
||||||
except SendMailException:
|
except SendMailException:
|
||||||
failures.append(o.email)
|
failures.append(o.email)
|
||||||
|
self.request.event.log_action('pretix.plugins.sendmail.sent',
|
||||||
|
user=self.request.user,
|
||||||
|
data=dict(form.cleaned_data))
|
||||||
if failures:
|
if failures:
|
||||||
messages.error(self.request, _('Failed to send mails to the following users: {}'.format(' '.join(failures))))
|
messages.error(self.request, _('Failed to send mails to the following users: {}'.format(' '.join(failures))))
|
||||||
else:
|
else:
|
||||||
@@ -95,3 +103,18 @@ class SenderView(EventPermissionRequiredMixin, FormView):
|
|||||||
ctx = super().get_context_data(*args, **kwargs)
|
ctx = super().get_context_data(*args, **kwargs)
|
||||||
ctx['output'] = getattr(self, 'output', None)
|
ctx['output'] = getattr(self, 'output', None)
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
|
||||||
|
class EmailHistoryView(EventPermissionRequiredMixin, ListView):
|
||||||
|
template_name = 'pretixplugins/sendmail/history.html'
|
||||||
|
permission = 'can_change_orders'
|
||||||
|
model = LogEntry
|
||||||
|
context_object_name = 'logs'
|
||||||
|
paginate_by = 15
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
qs = LogEntry.objects.filter(
|
||||||
|
event=self.request.event,
|
||||||
|
action_type='pretix.plugins.sendmail.sent'
|
||||||
|
)
|
||||||
|
return qs
|
||||||
|
|||||||
Reference in New Issue
Block a user