Beispiel #1
0
 def get_form_kwargs(self):
     kwargs = super().get_form_kwargs()
     kwargs['event'] = self.request.event
     if 'from_log' in self.request.GET:
         try:
             from_log_id = self.request.GET.get('from_log')
             logentry = LogEntry.objects.get(
                 id=from_log_id,
                 event=self.request.event,
                 action_type='pretix.plugins.sendmail.sent')
             kwargs['initial'] = {
                 'message': LazyI18nString(logentry.parsed_data['message']),
                 'subject': LazyI18nString(logentry.parsed_data['subject']),
                 'sendto': logentry.parsed_data['sendto'],
             }
             if logentry.parsed_data.get('subevent'):
                 try:
                     kwargs['initial'][
                         'subevent'] = self.request.event.subevents.get(
                             pk=logentry.parsed_data['subevent']['id'])
                 except SubEvent.DoesNotExist:
                     pass
         except LogEntry.DoesNotExist:
             raise Http404(_('You supplied an invalid log entry ID'))
     return kwargs
Beispiel #2
0
    def test_similar_translations(self):
        data = {
            'en': 'You',
            'de': 'Sie',
            'de-informal': 'Du'
        }
        s = LazyI18nString(data)
        translation.activate('de')
        self.assertEqual(str(s), 'Sie')
        translation.activate('de-informal')
        self.assertEqual(str(s), 'Du')

        data = {
            'en': 'You',
            'de-informal': 'Du'
        }
        s = LazyI18nString(data)
        translation.activate('de')
        self.assertEqual(str(s), 'Du')
        translation.activate('de-informal')
        self.assertEqual(str(s), 'Du')

        data = {
            'en': 'You',
            'de': 'Sie'
        }
        s = LazyI18nString(data)
        translation.activate('de')
        self.assertEqual(str(s), 'Sie')
        translation.activate('de-informal')
        self.assertEqual(str(s), 'Sie')
Beispiel #3
0
    def _unserialize(self, value: str, as_type: type) -> Any:
        if as_type is None and value is not None and value.startswith('file://'):
            as_type = File

        if as_type is not None and isinstance(value, as_type):
            return value
        elif value is None:
            return None
        elif as_type == int or as_type == float or as_type == decimal.Decimal:
            return as_type(value)
        elif as_type == dict or as_type == list:
            return json.loads(value)
        elif as_type == bool or value in ('True', 'False'):
            return value == 'True'
        elif as_type == File:
            try:
                fi = default_storage.open(value[7:], 'r')
                fi.url = default_storage.url(value[7:])
                return fi
            except OSError:
                return False
        elif as_type == datetime:
            return dateutil.parser.parse(value)
        elif as_type == date:
            return dateutil.parser.parse(value).date()
        elif as_type == time:
            return dateutil.parser.parse(value).time()
        elif as_type == LazyI18nString and not isinstance(value, LazyI18nString):
            try:
                return LazyI18nString(json.loads(value))
            except ValueError:
                return LazyI18nString(str(value))
        elif as_type is not None and issubclass(as_type, Model):
            return as_type.objects.get(pk=value)
        return value
Beispiel #4
0
 def get_form_kwargs(self):
     kwargs = super().get_form_kwargs()
     kwargs['event'] = self.request.event
     if 'from_log' in self.request.GET:
         try:
             from_log_id = self.request.GET.get('from_log')
             logentry = LogEntry.objects.get(
                 id=from_log_id,
                 event=self.request.event,
                 action_type='pretix.plugins.sendmail.sent'
             )
             kwargs['initial'] = {
                 'recipients': logentry.parsed_data.get('recipients', 'orders'),
                 'message': LazyI18nString(logentry.parsed_data['message']),
                 'subject': LazyI18nString(logentry.parsed_data['subject']),
                 'sendto': logentry.parsed_data['sendto'],
             }
             if 'items' in logentry.parsed_data:
                 kwargs['initial']['items'] = self.request.event.items.filter(
                     id__in=[a['id'] for a in logentry.parsed_data['items']]
                 )
             elif logentry.parsed_data.get('item'):
                 kwargs['initial']['items'] = self.request.event.items.filter(
                     id=logentry.parsed_data['item']['id']
                 )
             if 'checkin_lists' in logentry.parsed_data:
                 kwargs['initial']['checkin_lists'] = self.request.event.checkin_lists.filter(
                     id__in=[c['id'] for c in logentry.parsed_data['checkin_lists']]
                 )
             kwargs['initial']['filter_checkins'] = logentry.parsed_data.get('filter_checkins', False)
             kwargs['initial']['not_checked_in'] = logentry.parsed_data.get('not_checked_in', False)
             if logentry.parsed_data.get('subevents_from'):
                 kwargs['initial']['subevents_from'] = dateutil.parser.parse(logentry.parsed_data['subevents_from'])
             if logentry.parsed_data.get('subevents_to'):
                 kwargs['initial']['subevents_to'] = dateutil.parser.parse(logentry.parsed_data['subevents_to'])
             if logentry.parsed_data.get('created_from'):
                 kwargs['initial']['created_from'] = dateutil.parser.parse(logentry.parsed_data['created_from'])
             if logentry.parsed_data.get('created_to'):
                 kwargs['initial']['created_to'] = dateutil.parser.parse(logentry.parsed_data['created_to'])
             if logentry.parsed_data.get('attach_tickets'):
                 kwargs['initial']['attach_tickets'] = logentry.parsed_data['attach_tickets']
             if logentry.parsed_data.get('subevent'):
                 try:
                     kwargs['initial']['subevent'] = self.request.event.subevents.get(
                         pk=logentry.parsed_data['subevent']['id']
                     )
                 except SubEvent.DoesNotExist:
                     pass
         except LogEntry.DoesNotExist:
             raise Http404(_('You supplied an invalid log entry ID'))
     return kwargs
Beispiel #5
0
 def test_missing_translation(self):
     data = {
         'en': 'Hello',
     }
     s = LazyI18nString(data)
     translation.activate('en')
     self.assertEqual(str(s), 'Hello')
     translation.activate('de')
     self.assertEqual(str(s), 'Hello')
Beispiel #6
0
 def test_explicit_translation(self):
     data = {
         'de': 'Hallo',
         'en': 'Hello'
     }
     s = LazyI18nString(data)
     translation.activate('en')
     self.assertEqual(str(s), 'Hello')
     translation.activate('de')
     self.assertEqual(str(s), 'Hallo')
Beispiel #7
0
 def test_save_load_cycle_i18n_string(self):
     obj = ItemCategory.objects.create(event=self.event,
                                       name=LazyI18nString(
                                           {
                                               'de': 'Hallo',
                                               'en': 'Hello'
                                           }
                                       ))
     obj = ItemCategory.objects.get(id=obj.id)
     self.assertIsInstance(obj.name, LazyI18nString)
     translation.activate('en')
     self.assertEqual(str(obj.name), "Hello")
     translation.activate('de')
     self.assertEqual(str(obj.name), "Hallo")
Beispiel #8
0
    },
    'mail_prefix': {
        'default': None,
        'type': str
    },
    'mail_from': {
        'default': settings.MAIL_FROM,
        'type': str
    },
    'mail_text_resend_link': {
        'type': LazyI18nString,
        'default': LazyI18nString.from_gettext(ugettext_noop("""Hello,

you receive this message because you asked us to send you the link
to your order for {event}.

You can change your order details and view the status of your order at
{url}

Best regards,
Your {event} team"""))
    },
    'mail_text_resend_all_links': {
        'type': LazyI18nString,
        'default': LazyI18nString.from_gettext(ugettext_noop("""Hello,

somebody requested a list of your orders for {event}.
The list is as follows:

{orders}

Best regards,
Beispiel #9
0
    },
    'mail_prefix': {
        'default': None,
        'type': str
    },
    'mail_from': {
        'default': settings.MAIL_FROM,
        'type': str
    },
    'mail_text_resend_link': {
        'type': LazyI18nString,
        'default': LazyI18nString.from_gettext(ugettext_noop("""Hello,

you receive this message because you asked us to send you the link
to your order for {event}.

You can change your order details and view the status of your order at
{url}

Best regards,
Your {event} team"""))
    },
    'mail_text_order_placed': {
        'type': LazyI18nString,
        'default': LazyI18nString.from_gettext(ugettext_noop("""Hello,

we successfully received your order for {event} with a total value
of {total} {currency}. Please complete your payment before {date}.

{paymentinfo}

You can change your order details and view the status of your order at
Beispiel #10
0
def pretixcontrol_logentry_display(sender: Event, logentry: LogEntry,
                                   **kwargs):
    plains = {
        'pretix.event.order.modified':
        _('The order details have been modified.'),
        'pretix.event.order.unpaid':
        _('The order has been marked as unpaid.'),
        'pretix.event.order.resend':
        _('The link to the order detail page has been resent to the user.'),
        'pretix.event.order.secret.changed':
        _('The order\'s secret has been changed.'),
        'pretix.event.order.expirychanged':
        _('The order\'s expiry date has been changed.'),
        'pretix.event.order.expired':
        _('The order has been marked as expired.'),
        'pretix.event.order.paid':
        _('The order has been marked as paid.'),
        'pretix.event.order.refunded':
        _('The order has been refunded.'),
        'pretix.event.order.canceled':
        _('The order has been canceled.'),
        'pretix.event.order.placed':
        _('The order has been created.'),
        'pretix.event.order.contact.changed':
        _('The email address has been changed from "{old_email}" '
          'to "{new_email}".'),
        'pretix.event.order.invoice.generated':
        _('The invoice has been generated.'),
        'pretix.event.order.invoice.regenerated':
        _('The invoice has been regenerated.'),
        'pretix.event.order.invoice.reissued':
        _('The invoice has been reissued.'),
        'pretix.event.order.comment':
        _('The order\'s internal comment has been updated.'),
        'pretix.event.order.payment.changed':
        _('The payment method has been changed.'),
        'pretix.event.order.expire_warning_sent':
        _('An email has been sent with a warning that the order is about '
          'to expire.'),
        'pretix.user.settings.2fa.enabled':
        _('Two-factor authentication has been enabled.'),
        'pretix.user.settings.2fa.disabled':
        _('Two-factor authentication has been disabled.'),
        'pretix.user.settings.2fa.regenemergency':
        _('Your two-factor emergency codes have been regenerated.'),
        'pretix.user.settings.2fa.device.added':
        _('A new two-factor authentication device "{name}" has been added to '
          'your account.'),
        'pretix.user.settings.2fa.device.deleted':
        _('The two-factor authentication device "{name}" has been removed '
          'from your account.'),
        'pretix.control.auth.user.forgot_password.mail_sent':
        _('Password reset mail sent.'),
        'pretix.control.auth.user.forgot_password.recovered':
        _('The password has been reset.'),
        'pretix.voucher.added':
        _('The voucher has been created.'),
        'pretix.voucher.added.waitinglist':
        _('The voucher has been created and sent to a person on the waiting list.'
          ),
        'pretix.voucher.changed':
        _('The voucher has been modified.'),
        'pretix.voucher.deleted':
        _('The voucher has been deleted.'),
        'pretix.voucher.redeemed':
        _('The voucher has been redeemed in order {order_code}.'),
        'pretix.event.item.added':
        _('The product has been created.'),
        'pretix.event.item.changed':
        _('The product has been modified.'),
        'pretix.event.item.deleted':
        _('The product has been deleted.'),
        'pretix.event.item.variation.added':
        _('The variation "{value}" has been created.'),
        'pretix.event.item.variation.deleted':
        _('The variation "{value}" has been deleted.'),
        'pretix.event.item.variation.changed':
        _('The variation "{value}" has been modified.'),
        'pretix.event.quota.added':
        _('The quota has been added.'),
        'pretix.event.quota.deleted':
        _('The quota has been deleted.'),
        'pretix.event.quota.changed':
        _('The quota has been modified.'),
        'pretix.event.category.added':
        _('The category has been added.'),
        'pretix.event.category.deleted':
        _('The category has been deleted.'),
        'pretix.event.category.changed':
        _('The category has been modified.'),
        'pretix.event.question.added':
        _('The question has been added.'),
        'pretix.event.question.deleted':
        _('The question has been deleted.'),
        'pretix.event.question.changed':
        _('The question has been modified.'),
        'pretix.event.settings':
        _('The event settings have been changed.'),
        'pretix.event.tickets.settings':
        _('The ticket download settings have been changed.'),
        'pretix.event.plugins.enabled':
        _('A plugin has been enabled.'),
        'pretix.event.plugins.disabled':
        _('A plugin has been disabled.'),
        'pretix.event.live.activated':
        _('The shop has been taken live.'),
        'pretix.event.live.deactivated':
        _('The shop has been taken offline.'),
        'pretix.event.changed':
        _('The event settings have been changed.'),
        'pretix.event.question.option.added':
        _('An answer option has been added to the question.'),
        'pretix.event.question.option.deleted':
        _('An answer option has been removed from the question.'),
        'pretix.event.question.option.changed':
        _('An answer option has been changed.'),
        'pretix.event.permissions.added':
        _('A user has been added to the event team.'),
        'pretix.event.permissions.invited':
        _('A user has been invited to the event team.'),
        'pretix.event.permissions.changed':
        _('A user\'s permissions have been changed.'),
        'pretix.event.permissions.deleted':
        _('A user has been removed from the event team.'),
        'pretix.waitinglist.voucher':
        _('A voucher has been sent to a person on the waiting list.')
    }

    data = json.loads(logentry.data)

    if logentry.action_type.startswith('pretix.event.item.variation'):
        if 'value' not in data:
            # Backwards compatibility
            var = ItemVariation.objects.filter(id=data['id']).first()
            if var:
                data['value'] = str(var.value)
            else:
                data['value'] = '?'
        else:
            data['value'] = LazyI18nString(data['value'])

    if logentry.action_type in plains:
        return plains[logentry.action_type].format_map(data)

    if logentry.action_type.startswith('pretix.event.order.changed'):
        return _display_order_changed(sender, logentry)

    if logentry.action_type.startswith('pretix.event.payment.provider.'):
        return _('The settings of a payment provider have been changed.')

    if logentry.action_type.startswith('pretix.event.tickets.provider.'):
        return _('The settings of a ticket output provider have been changed.')

    if logentry.action_type == 'pretix.user.settings.changed':
        text = str(_('Your account settings have been changed.'))
        if 'email' in data:
            text = text + ' ' + str(
                _('Your email address has been changed to {email}.').format(
                    email=data['email']))
        if 'new_pw' in data:
            text = text + ' ' + str(_('Your password has been changed.'))
        return text
Beispiel #11
0
    'mail_prefix': {
        'default': None,
        'type': str
    },
    'mail_from': {
        'default': settings.MAIL_FROM,
        'type': str
    },
    'mail_text_order_placed': {
        'type': LazyI18nString,
        'default': LazyI18nString.from_gettext(ugettext_noop("""Hello,

we successfully received your order for {event} with a total value
of {total} {currency}. Please complete your payment before {date}.

{paymentinfo}

You can change your order details and view the status of your order at
{url}

Best regards,
Your {event} team"""))
    },
    'mail_text_order_paid': {
        'type': LazyI18nString,
        'default': LazyI18nString.from_gettext(ugettext_noop("""Hello,

we successfully received your payment for {event}. Thank you!

You can change your order details and view the status of your order at
{url}
Beispiel #12
0
        'type': str
    },
    'mail_from': {
        'default': settings.MAIL_FROM,
        'type': str
    },
    'mail_text_resend_link': {
        'type':
        LazyI18nString,
        'default':
        LazyI18nString.from_gettext(
            ugettext_noop("""Hello,

you receive this message because you asked us to send you the link
to your order for {event}.

You can change your order details and view the status of your order at
{url}

Best regards,
Your {event} team"""))
    },
    'mail_text_resend_all_links': {
        'type':
        LazyI18nString,
        'default':
        LazyI18nString.from_gettext(
            ugettext_noop("""Hello,

somebody requested a list of your orders for {event}.
The list is as follows:
Beispiel #13
0
def gdpr_localize(value):
    return str(LazyI18nString(value))
Beispiel #14
0
 def test_serialize_lazyi18nstring(self):
     self._test_serialization(
         LazyI18nString({
             'de': 'Hallo',
             'en': 'Hello'
         }), LazyI18nString)
Beispiel #15
0
 def test_none(self):
     s = LazyI18nString(None)
     self.assertEqual(str(s), "")
     s = LazyI18nString("")
     self.assertEqual(str(s), "")
Beispiel #16
0
 def test_legacy_string(self):
     s = LazyI18nString("Hello")
     translation.activate('en')
     self.assertEqual(str(s), 'Hello')
     translation.activate('de')
     self.assertEqual(str(s), 'Hello')
def confirm_messages(sender, *args, **kwargs):
    # @see https://docs.pretix.eu/en/latest/development/api/general.html#pretix.presale.signals.checkout_confirm_messages
    return {
        # @FIXME: We shouldn't have to use LazyI18nString here!
        'gdpr': str(LazyI18nString(sender.settings.billetaarhusgdpr_consent_text))
    }
Beispiel #18
0
        'type': str
    },
    'mail_from': {
        'default': settings.MAIL_FROM,
        'type': str
    },
    'mail_text_resend_link': {
        'type':
        LazyI18nString,
        'default':
        LazyI18nString.from_gettext(
            ugettext_noop("""Hello,

you receive this message because you asked us to send you the link
to your order for {event}.

You can change your order details and view the status of your order at
{url}

Best regards,
Your {event} team"""))
    },
    'mail_text_order_placed': {
        'type':
        LazyI18nString,
        'default':
        LazyI18nString.from_gettext(
            ugettext_noop("""Hello,

we successfully received your order for {event} with a total value
of {total} {currency}. Please complete your payment before {date}.