mirror of
https://github.com/pretix/pretix.git
synced 2026-05-07 15:34:02 +00:00
Fixed #46 -- Added a plugin to send out emails
This commit is contained in:
22
src/pretix/plugins/sendmail/__init__.py
Normal file
22
src/pretix/plugins/sendmail/__init__.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from django.apps import AppConfig
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from pretix.base.plugins import PluginType
|
||||
|
||||
|
||||
class SendMailApp(AppConfig):
|
||||
name = 'pretix.plugins.sendmail'
|
||||
verbose_name = _("Send out emails")
|
||||
|
||||
class PretixPluginMeta:
|
||||
type = PluginType.ADMINFEATURE
|
||||
name = _("Send out emails")
|
||||
author = _("the pretix team")
|
||||
version = '1.0.0'
|
||||
description = _("This plugin allows you to send out emails " +
|
||||
"to all your customers.")
|
||||
|
||||
def ready(self):
|
||||
from . import signals # NOQA
|
||||
|
||||
|
||||
default_app_config = 'pretix.plugins.sendmail.SendMailApp'
|
||||
25
src/pretix/plugins/sendmail/forms.py
Normal file
25
src/pretix/plugins/sendmail/forms.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from pretix.base.i18n import I18nFormField, I18nTextarea, I18nTextInput
|
||||
from pretix.base.models import Order
|
||||
|
||||
|
||||
class MailForm(forms.Form):
|
||||
sendto = forms.MultipleChoiceField(
|
||||
label=_("Send to"), widget=forms.CheckboxSelectMultiple,
|
||||
choices=Order.STATUS_CHOICE
|
||||
)
|
||||
subject = forms.CharField(label=_("Subject"))
|
||||
message = forms.CharField(label=_("Message"))
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
event = kwargs.pop('event')
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['subject'] = I18nFormField(
|
||||
widget=I18nTextInput, required=True,
|
||||
langcodes=event.settings.get('locales')
|
||||
)
|
||||
self.fields['message'] = I18nFormField(
|
||||
widget=I18nTextarea, required=True,
|
||||
langcodes=event.settings.get('locales')
|
||||
)
|
||||
23
src/pretix/plugins/sendmail/signals.py
Normal file
23
src/pretix/plugins/sendmail/signals.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.core.urlresolvers import reverse, resolve
|
||||
from django.dispatch import receiver
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from pretix.control.signals import nav_event
|
||||
|
||||
|
||||
@receiver(nav_event)
|
||||
def control_nav_import(sender, request=None, **kwargs):
|
||||
url = resolve(request.path_info)
|
||||
if not request.eventperm.can_change_orders:
|
||||
return []
|
||||
return [
|
||||
{
|
||||
'label': _('Send out emails'),
|
||||
'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'),
|
||||
'icon': 'envelope',
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,21 @@
|
||||
{% extends "pretixcontrol/event/base.html" %}
|
||||
{% load i18n %}
|
||||
{% load bootstrap3 %}
|
||||
{% block title %}{% trans "Send out emails" %}{% endblock %}
|
||||
{% block content %}
|
||||
<h1>{% trans "Send out emails" %}</h1>
|
||||
{% block inner %}
|
||||
<form class="form-horizontal" method="post" action="">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_field form.sendto layout='horizontal' %}
|
||||
{% bootstrap_field form.subject layout='horizontal' %}
|
||||
{% bootstrap_field form.message layout='horizontal' %}
|
||||
<div class="form-group submit-group">
|
||||
<button type="submit" class="btn btn-primary btn-save">
|
||||
{% trans "Send" %}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
9
src/pretix/plugins/sendmail/urls.py
Normal file
9
src/pretix/plugins/sendmail/urls.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^control/event/(?P<organizer>[^/]+)/(?P<event>[^/]+)/sendmail/', views.SenderView.as_view(),
|
||||
name='send'),
|
||||
]
|
||||
43
src/pretix/plugins/sendmail/views.py
Normal file
43
src/pretix/plugins/sendmail/views.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import logging
|
||||
from django.contrib import messages
|
||||
from django.shortcuts import redirect
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.generic import FormView
|
||||
|
||||
from pretix.base.models import Order
|
||||
from pretix.base.services.mail import mail
|
||||
from pretix.control.permissions import EventPermissionRequiredMixin
|
||||
|
||||
from . import forms
|
||||
|
||||
|
||||
logger = logging.getLogger('pretix.plugins.sendmail')
|
||||
|
||||
|
||||
class SenderView(EventPermissionRequiredMixin, FormView):
|
||||
template_name = 'pretixplugins/sendmail/send_form.html'
|
||||
permission = 'can_change_orders'
|
||||
form_class = forms.MailForm
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs['event'] = self.request.event
|
||||
return kwargs
|
||||
|
||||
def form_valid(self, form):
|
||||
orders = Order.objects.current.filter(
|
||||
event=self.request.event, status__in=form.cleaned_data['sendto']
|
||||
).select_related("user")
|
||||
users = set([o.user for o in orders])
|
||||
|
||||
for u in users:
|
||||
mail(u, form.cleaned_data['subject'], form.cleaned_data['message'],
|
||||
None, self.request.event)
|
||||
|
||||
messages.success(self.request, _('Your message will be sent to the selected users.'))
|
||||
|
||||
return redirect(
|
||||
'plugins:sendmail:send',
|
||||
event=self.request.event.slug,
|
||||
organizer=self.request.event.organizer.slug
|
||||
)
|
||||
Reference in New Issue
Block a user