Exemple #1
0
    def get_context_data(self, **kwargs):
        ctx = super().get_context_data(**kwargs)
        o = {}

        for lang in self.request.event.settings.locales:
            with language(lang, self.request.event.settings.region):
                placeholders = TolerantDict()
                for k, v in get_available_placeholders(self.request.event, ['event', 'order', 'position_or_address']).items():
                    placeholders[k] = '<span class="placeholder" title="{}">{}</span>'.format(
                        _('This value will be replaced based on dynamic parameters.'),
                        v.render_sample(self.request.event)
                    )

                subject = bleach.clean(self.object.subject.localize(lang), tags=[])
                preview_subject = subject.format_map(placeholders)
                template = self.object.template.localize(lang)
                preview_text = markdown_compile_email(template.format_map(placeholders))

                o[lang] = {
                    'subject': _('Subject: {subject}'.format(subject=preview_subject)),
                    'html': preview_text,
                }

        ctx['output'] = o

        return ctx
Exemple #2
0
 def _set_field_placeholders(self, fn, base_parameters):
     phs = [
         "{%s}" % p for p in sorted(
             get_available_placeholders(self.event, base_parameters).keys())
     ]
     ht = _("Available placeholders: {list}").format(list=", ".join(phs))
     if self.fields[fn].help_text:
         self.fields[fn].help_text += " " + str(ht)
     else:
         self.fields[fn].help_text = ht
     self.fields[fn].validators.append(PlaceholderValidator(phs))
Exemple #3
0
 def _set_field_placeholders(self, fn, base_parameters):
     phs = [
         '{%s}' % p for p in sorted(
             get_available_placeholders(self.instance.event,
                                        base_parameters).keys())
     ]
     ht = _('Available placeholders: {list}').format(list=', '.join(phs))
     if self.fields[fn].help_text:
         self.fields[fn].help_text += ' ' + str(ht)
     else:
         self.fields[fn].help_text = ht
     self.fields[fn].validators.append(PlaceholderValidator(phs))
Exemple #4
0
    def form_valid(self, form):
        self.output = {}

        if self.request.POST.get("action") == "preview":
            for l in self.request.event.settings.locales:
                with language(l, self.request.event.settings.region):
                    context_dict = TolerantDict()
                    for k, v in get_available_placeholders(
                            self.request.event,
                        ['event', 'order', 'position_or_address']).items():
                        context_dict[
                            k] = '<span class="placeholder" title="{}">{}</span>'.format(
                                _('This value will be replaced based on dynamic parameters.'
                                  ), v.render_sample(self.request.event))

                    subject = bleach.clean(
                        form.cleaned_data['subject'].localize(l), tags=[])
                    preview_subject = subject.format_map(context_dict)
                    template = form.cleaned_data['template'].localize(l)
                    preview_text = markdown_compile_email(
                        template.format_map(context_dict))

                    self.output[l] = {
                        'subject':
                        _('Subject: {subject}').format(
                            subject=preview_subject),
                        'html':
                        preview_text,
                    }

            return self.get(self.request, *self.args, **self.kwargs)

        messages.success(self.request, _('Your rule has been created.'))

        form.instance.event = self.request.event

        self.object = form.save()

        return redirect(
            'plugins:sendmail:rule.update',
            event=self.request.event.slug,
            organizer=self.request.event.organizer.slug,
            rule=self.object.pk,
        )
Exemple #5
0
    def form_valid(self, form):
        qs = Order.objects.filter(event=self.request.event)
        statusq = Q(status__in=form.cleaned_data['sendto'])
        if 'overdue' in form.cleaned_data['sendto']:
            statusq |= Q(status=Order.STATUS_PENDING, expires__lt=now())
        orders = qs.filter(statusq)

        opq = OrderPosition.objects.filter(
            order=OuterRef('pk'),
            canceled=False,
            item_id__in=[i.pk for i in form.cleaned_data.get('items')],
        )

        if form.cleaned_data.get('filter_checkins'):
            ql = []
            if form.cleaned_data.get('not_checked_in'):
                ql.append(Q(checkins__list_id=None))
            if form.cleaned_data.get('checkin_lists'):
                ql.append(
                    Q(checkins__list_id__in=[
                        i.pk
                        for i in form.cleaned_data.get('checkin_lists', [])
                    ], ))
            if len(ql) == 2:
                opq = opq.filter(ql[0] | ql[1])
            elif ql:
                opq = opq.filter(ql[0])
            else:
                opq = opq.none()

        if form.cleaned_data.get('subevent'):
            opq = opq.filter(subevent=form.cleaned_data.get('subevent'))

        orders = orders.annotate(match_pos=Exists(opq)).filter(
            match_pos=True).distinct()

        self.output = {}
        if not orders:
            messages.error(self.request,
                           _('There are no orders matching this selection.'))
            return self.get(self.request, *self.args, **self.kwargs)

        if self.request.POST.get("action") == "preview":
            for l in self.request.event.settings.locales:

                with language(l):
                    context_dict = TolerantDict()
                    for k, v in get_available_placeholders(
                            self.request.event,
                        ['event', 'order', 'position_or_address']).items():
                        context_dict[
                            k] = '<span class="placeholder" title="{}">{}</span>'.format(
                                _('This value will be replaced based on dynamic parameters.'
                                  ), v.render_sample(self.request.event))

                    subject = bleach.clean(
                        form.cleaned_data['subject'].localize(l), tags=[])
                    preview_subject = subject.format_map(context_dict)
                    message = form.cleaned_data['message'].localize(l)
                    preview_text = markdown_compile_email(
                        message.format_map(context_dict))

                    self.output[l] = {
                        'subject':
                        _('Subject: {subject}').format(
                            subject=preview_subject),
                        'html':
                        preview_text,
                    }

            return self.get(self.request, *self.args, **self.kwargs)

        send_mails.apply_async(
            kwargs={
                'recipients':
                form.cleaned_data['recipients'],
                'event':
                self.request.event.pk,
                'user':
                self.request.user.pk,
                'subject':
                form.cleaned_data['subject'].data,
                'message':
                form.cleaned_data['message'].data,
                'orders': [o.pk for o in orders],
                'items': [i.pk for i in form.cleaned_data.get('items')],
                'not_checked_in':
                form.cleaned_data.get('not_checked_in'),
                'checkin_lists':
                [i.pk for i in form.cleaned_data.get('checkin_lists')],
                'filter_checkins':
                form.cleaned_data.get('filter_checkins'),
            })
        self.request.event.log_action('pretix.plugins.sendmail.sent',
                                      user=self.request.user,
                                      data=dict(form.cleaned_data))
        messages.success(
            self.request,
            _('Your message has been queued and will be sent to the contact addresses of %d '
              'orders in the next minutes.') % len(orders))

        return redirect('plugins:sendmail:send',
                        event=self.request.event.slug,
                        organizer=self.request.event.organizer.slug)