def settings_form_fields(self): d = OrderedDict( [ ('public_name', I18nFormField( label=_('Payment method name'), widget=I18nTextInput, )), ('checkout_description', I18nFormField( label=_('Payment process description during checkout'), help_text=_('This text will be shown during checkout when the user selects this payment method. ' 'It should give a short explanation on this payment method.'), widget=I18nTextarea, )), ('email_instructions', I18nFormField( label=_('Payment process description in order confirmation emails'), help_text=_('This text will be included for the {payment_info} placeholder in order confirmation ' 'mails. It should instruct the user on how to proceed with the payment. You can use' 'the placeholders {order}, {total}, {currency} and {total_with_currency}'), widget=I18nTextarea, validators=[PlaceholderValidator(['{order}', '{total}', '{currency}', '{total_with_currency}'])], )), ('pending_description', I18nFormField( label=_('Payment process description for pending orders'), help_text=_('This text will be shown on the order confirmation page for pending orders. ' 'It should instruct the user on how to proceed with the payment. You can use' 'the placeholders {order}, {total}, {currency} and {total_with_currency}'), widget=I18nTextarea, validators=[PlaceholderValidator(['{order}', '{total}', '{currency}', '{total_with_currency}'])], )), ] + list(super().settings_form_fields.items()) ) d.move_to_end('_enabled', last=False) return d
def __init__(self, *args, **kwargs): event = kwargs.pop('event') super().__init__(*args, **kwargs) self.fields['subject'] = I18nFormField( label=_('Subject'), widget=I18nTextInput, required=True, locales=event.settings.get('locales'), help_text=_( "Available placeholders: {expire_date}, {event}, {code}, {date}, {url}, " "{invoice_name}, {invoice_company}"), validators=[ PlaceholderValidator([ '{expire_date}', '{event}', '{code}', '{date}', '{url}', '{invoice_name}', '{invoice_company}' ]) ]) self.fields['message'] = I18nFormField( label=_('Message'), widget=I18nTextarea, required=True, locales=event.settings.get('locales'), help_text=_( "Available placeholders: {expire_date}, {event}, {code}, {date}, {url}, " "{invoice_name}, {invoice_company}"), validators=[ PlaceholderValidator([ '{expire_date}', '{event}', '{code}', '{date}', '{url}', '{invoice_name}', '{invoice_company}' ]) ]) choices = list(Order.STATUS_CHOICE) if not event.settings.get('payment_term_expire_automatically', as_type=bool): choices.append(('overdue', _('pending with payment overdue'))) self.fields['sendto'] = forms.MultipleChoiceField( label=_("Send to customers with order status"), widget=forms.CheckboxSelectMultiple, choices=choices) self.fields['item'].queryset = event.items.all() if event.has_subevents: self.fields['subevent'].queryset = event.subevents.all() self.fields['subevent'].widget = Select2( attrs={ 'data-model-select2': 'event', 'data-select2-url': reverse('control:event.subevents.select2', kwargs={ 'event': event.slug, 'organizer': event.organizer.slug, }), 'data-placeholder': pgettext_lazy('subevent', 'Date') }) self.fields['subevent'].widget.choices = self.fields[ 'subevent'].choices else: del self.fields['subevent']
def __init__(self, *args, **kwargs): event = kwargs.pop('event') super().__init__(*args, **kwargs) self.fields['subject'] = I18nFormField( widget=I18nTextInput, required=True, locales=event.settings.get('locales')) self.fields['message'] = I18nFormField( widget=I18nTextarea, required=True, locales=event.settings.get('locales'), help_text=_( "Available placeholders: {due_date}, {event}, {order}, {order_date}, {order_url}, " "{invoice_name}, {invoice_company}"), validators=[ PlaceholderValidator([ '{due_date}', '{event}', '{order}', '{order_date}', '{order_url}', '{invoice_name}', '{invoice_company}' ]) ]) choices = list(Order.STATUS_CHOICE) if not event.settings.get('payment_term_expire_automatically', as_type=bool): choices.append(('overdue', _('pending with payment overdue'))) self.fields['sendto'] = forms.MultipleChoiceField( label=_("Send to"), widget=forms.CheckboxSelectMultiple, choices=choices)
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))
def _set_field_placeholders(self, fn, base_parameters): phs = [ '{%s}' % p for p in sorted(self._get_sample_context(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))
def __init__(self, *args, **kwargs): order = kwargs.pop('order') super().__init__(*args, **kwargs) self.fields['sendto'] = forms.EmailField( label=_("Recipient"), required=True, initial=order.email ) self.fields['sendto'].widget.attrs['readonly'] = 'readonly' self.fields['message'] = forms.CharField( label=_("Message"), required=True, widget=forms.Textarea, initial=order.event.settings.mail_text_order_custom_mail.localize(order.locale), help_text=_("Available placeholders: {expire_date}, {event}, {code}, {date}, {url}, " "{invoice_name}, {invoice_company}"), validators=[PlaceholderValidator(['{expire_date}', '{event}', '{code}', '{date}', '{url}', '{invoice_name}', '{invoice_company}'])] )
class MailSettingsForm(SettingsForm): mail_prefix = forms.CharField( label=_("Subject prefix"), help_text=_( "This will be prepended to the subject of all outgoing emails, formatted as [prefix]. " "Choose, for example, a short form of your event name."), required=False) mail_from = forms.EmailField( label=_("Sender address"), help_text=_("Sender address for outgoing emails")) mail_text_signature = I18nFormField( label=_("Signature"), required=False, widget=I18nTextarea, help_text= _("This will be attached to every email. Available placeholders: {event}" ), validators=[PlaceholderValidator(['{event}'])], widget_kwargs={ 'attrs': { 'rows': '4', 'placeholder': _('e.g. your contact details') } }) mail_text_order_placed = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, help_text=_( "Available placeholders: {event}, {total_with_currency}, {total}, {currency}, {date}, " "{payment_info}, {url}, {invoice_name}, {invoice_company}"), validators=[ PlaceholderValidator([ '{event}', '{total_with_currency}', '{total}', '{currency}', '{date}', '{payment_info}', '{url}', '{invoice_name}', '{invoice_company}' ]) ]) mail_text_order_paid = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, help_text= _("Available placeholders: {event}, {url}, {invoice_name}, {invoice_company}, {payment_info}" ), validators=[ PlaceholderValidator([ '{event}', '{url}', '{invoice_name}', '{invoice_company}', '{payment_info}' ]) ]) mail_text_order_free = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, help_text= _("Available placeholders: {event}, {url}, {invoice_name}, {invoice_company}" ), validators=[ PlaceholderValidator( ['{event}', '{url}', '{invoice_name}', '{invoice_company}']) ]) mail_text_order_changed = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, help_text= _("Available placeholders: {event}, {url}, {invoice_name}, {invoice_company}" ), validators=[ PlaceholderValidator( ['{event}', '{url}', '{invoice_name}', '{invoice_company}']) ]) mail_text_resend_link = I18nFormField( label=_("Text (sent by admin)"), required=False, widget=I18nTextarea, help_text= _("Available placeholders: {event}, {url}, {invoice_name}, {invoice_company}" ), validators=[ PlaceholderValidator( ['{event}', '{url}', '{invoice_name}', '{invoice_company}']) ]) mail_text_resend_all_links = I18nFormField( label=_("Text (requested by user)"), required=False, widget=I18nTextarea, help_text=_("Available placeholders: {event}, {orders}"), validators=[PlaceholderValidator(['{event}', '{orders}'])]) mail_days_order_expire_warning = forms.IntegerField( label=_("Number of days"), required=False, min_value=0, help_text=_( "This email will be sent out this many days before the order expires. If the " "value is 0, the mail will never be sent.")) mail_text_order_expire_warning = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, help_text= _("Available placeholders: {event}, {url}, {expire_date}, {invoice_name}, {invoice_company}" ), validators=[ PlaceholderValidator([ '{event}', '{url}', '{expire_date}', '{invoice_name}', '{invoice_company}' ]) ]) mail_text_waiting_list = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, help_text=_( "Available placeholders: {event}, {url}, {product}, {hours}, {code}" ), validators=[ PlaceholderValidator( ['{event}', '{url}', '{product}', '{hours}', '{code}']) ]) mail_text_order_canceled = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, help_text=_("Available placeholders: {event}, {code}, {url}"), validators=[PlaceholderValidator(['{event}', '{code}', '{url}'])]) mail_text_order_custom_mail = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, help_text=_( "Available placeholders: {expire_date}, {event}, {code}, {date}, {url}, " "{invoice_name}, {invoice_company}"), validators=[ PlaceholderValidator([ '{expire_date}', '{event}', '{code}', '{date}', '{url}', '{invoice_name}', '{invoice_company}' ]) ]) mail_text_download_reminder = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, help_text=_("Available placeholders: {event}, {url}"), validators=[PlaceholderValidator(['{event}', '{url}'])]) mail_days_download_reminder = forms.IntegerField( label=_("Number of days"), required=False, min_value=0, help_text=_( "This email will be sent out this many days before the order event starts. If the " "field is empty, the mail will never be sent.")) smtp_use_custom = forms.BooleanField( label=_("Use custom SMTP server"), help_text= _("All mail related to your event will be sent over the smtp server specified by you." ), required=False) smtp_host = forms.CharField( label=_("Hostname"), required=False, widget=forms.TextInput(attrs={'placeholder': 'mail.example.org'})) smtp_port = forms.IntegerField( label=_("Port"), required=False, widget=forms.TextInput( attrs={'placeholder': 'e.g. 587, 465, 25, ...'})) smtp_username = forms.CharField( label=_("Username"), widget=forms.TextInput(attrs={'placeholder': '*****@*****.**'}), required=False) smtp_password = forms.CharField( label=_("Password"), required=False, widget=forms.PasswordInput( attrs={ 'autocomplete': 'new-password' # see https://bugs.chromium.org/p/chromium/issues/detail?id=370363#c7 }), ) smtp_use_tls = forms.BooleanField( label=_("Use STARTTLS"), help_text=_("Commonly enabled on port 587."), required=False) smtp_use_ssl = forms.BooleanField( label=_("Use SSL"), help_text=_("Commonly enabled on port 465."), required=False) def clean(self): data = self.cleaned_data if not data.get('smtp_password') and data.get('smtp_username'): # Leave password unchanged if the username is set and the password field is empty. # This makes it impossible to set an empty password as long as a username is set, but # Python's smtplib does not support password-less schemes anyway. data['smtp_password'] = self.initial.get('smtp_password') if data.get('smtp_use_tls') and data.get('smtp_use_ssl'): raise ValidationError( _('You can activate either SSL or STARTTLS security, but not both at the same time.' ))
def __init__(self, *args, **kwargs): event = kwargs.pop('event') super().__init__(*args, **kwargs) recp_choices = [('orders', _('Everyone who created a ticket order'))] if event.settings.attendee_emails_asked: recp_choices += [ ('attendees', _('Every attendee (falling back to the order contact when no attendee email address is ' 'given)')), ('both', _('Both (all order contact addresses and all attendee email addresses)' )) ] self.fields['recipients'].choices = recp_choices self.fields['subject'] = I18nFormField( label=_('Subject'), widget=I18nTextInput, required=True, locales=event.settings.get('locales'), help_text=_( "Available placeholders: {expire_date}, {event}, {code}, {date}, {url}, " "{invoice_name}, {invoice_company}"), validators=[ PlaceholderValidator([ '{expire_date}', '{event}', '{code}', '{date}', '{url}', '{invoice_name}', '{invoice_company}' ]) ]) self.fields['message'] = I18nFormField( label=_('Message'), widget=I18nTextarea, required=True, locales=event.settings.get('locales'), help_text=_( "Available placeholders: {expire_date}, {event}, {code}, {date}, {url}, " "{invoice_name}, {invoice_company}"), validators=[ PlaceholderValidator([ '{expire_date}', '{event}', '{code}', '{date}', '{url}', '{invoice_name}', '{invoice_company}' ]) ]) choices = list(Order.STATUS_CHOICE) if not event.settings.get('payment_term_expire_automatically', as_type=bool): choices.append(('overdue', _('pending with payment overdue'))) self.fields['sendto'] = forms.MultipleChoiceField( label=_("Send to customers with order status"), widget=forms.CheckboxSelectMultiple( attrs={'class': 'scrolling-multiple-choice'}), choices=choices) if not self.initial.get('sendto'): self.initial['sendto'] = ['p', 'n'] self.fields['items'].queryset = event.items.all() if not self.initial.get('items'): self.initial['items'] = event.items.all() if event.has_subevents: self.fields['subevent'].queryset = event.subevents.all() self.fields['subevent'].widget = Select2( attrs={ 'data-model-select2': 'event', 'data-select2-url': reverse('control:event.subevents.select2', kwargs={ 'event': event.slug, 'organizer': event.organizer.slug, }), 'data-placeholder': pgettext_lazy('subevent', 'Date') }) self.fields['subevent'].widget.choices = self.fields[ 'subevent'].choices else: del self.fields['subevent']
class TwilioSettingsForm(SettingsForm): twilio_account_sid = forms.CharField( label=_("Account SID"), help_text=_( "You can find your SID here: https://www.twilio.com/console"), ) twilio_auth_token = forms.CharField( label=_("Auth token"), required=False, help_text=_( "You can find your auth token here: https://www.twilio.com/console" ), widget=forms.PasswordInput( attrs={ "autocomplete": "new-password" # see https://bugs.chromium.org/p/chromium/issues/detail?id=370363#c7 }), ) twilio_sender_number = forms.CharField( label=_("Sender number"), help_text=_( "Please enter the number to be used as sender. It must be one of your Twilio numbers. " "You can find your numbers here: https://www.twilio.com/console"), ) twilio_text_signature = I18nFormField( label=_("Signature"), required=False, widget=I18nTextarea, help_text= _("This will be attached to every SMS. Available placeholders: {event}" ), validators=[PlaceholderValidator(["{event}"])], widget_kwargs={ "attrs": { "rows": "4", "placeholder": _("e.g. your contact details") } }, ) twilio_text_order_placed = I18nFormField( label=_("Text sent to order contact address"), required=False, widget=I18nTextarea, ) twilio_text_order_paid = I18nFormField( label=_("Text sent to order contact address"), required=False, widget=I18nTextarea, ) twilio_text_order_free = I18nFormField( label=_("Text sent to order contact address"), required=False, widget=I18nTextarea, ) twilio_text_order_changed = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, ) twilio_text_order_canceled = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, ) base_context = { "twilio_text_order_placed": ["event", "order", "payment"], "twilio_text_order_free": ["event", "order"], "twilio_text_order_changed": ["event", "order"], "twilio_text_order_canceled": ["event", "order"], "twilio_text_order_paid": ["event", "order", "payment_info"], } 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)) def __init__(self, *args, **kwargs): self.event = kwargs.get("obj") super().__init__(*args, **kwargs) for k, v in self.base_context.items(): self._set_field_placeholders(k, v) def clean(self): data = self.cleaned_data if not data.get("twilio_auth_token") and data.get( "twilio_account_sid"): # Leave password unchanged if the username is set and the password field is empty. data["twilio_auth_token"] = self.initial.get("twilio_auth_token")
class MailSettingsForm(SettingsForm): auto_fields = [ 'mail_prefix', 'mail_from', 'mail_from_name', 'mail_attach_ical', ] mail_bcc = forms.CharField( label=_("Bcc address"), help_text=_("All emails will be sent to this address as a Bcc copy"), validators=[multimail_validate], required=False, max_length=255 ) mail_text_signature = I18nFormField( label=_("Signature"), required=False, widget=I18nTextarea, help_text=_("This will be attached to every email. Available placeholders: {event}"), validators=[PlaceholderValidator(['{event}'])], widget_kwargs={'attrs': { 'rows': '4', 'placeholder': _( 'e.g. your contact details' ) }} ) mail_html_renderer = forms.ChoiceField( label=_("HTML mail renderer"), required=True, choices=[] ) mail_text_order_placed = I18nFormField( label=_("Text sent to order contact address"), required=False, widget=I18nTextarea, ) mail_send_order_placed_attendee = forms.BooleanField( label=_("Send an email to attendees"), help_text=_('If the order contains attendees with email addresses different from the person who orders the ' 'tickets, the following email will be sent out to the attendees.'), required=False, ) mail_text_order_placed_attendee = I18nFormField( label=_("Text sent to attendees"), required=False, widget=I18nTextarea, ) mail_text_order_paid = I18nFormField( label=_("Text sent to order contact address"), required=False, widget=I18nTextarea, ) mail_send_order_paid_attendee = forms.BooleanField( label=_("Send an email to attendees"), help_text=_('If the order contains attendees with email addresses different from the person who orders the ' 'tickets, the following email will be sent out to the attendees.'), required=False, ) mail_text_order_paid_attendee = I18nFormField( label=_("Text sent to attendees"), required=False, widget=I18nTextarea, ) mail_text_order_free = I18nFormField( label=_("Text sent to order contact address"), required=False, widget=I18nTextarea, ) mail_send_order_free_attendee = forms.BooleanField( label=_("Send an email to attendees"), help_text=_('If the order contains attendees with email addresses different from the person who orders the ' 'tickets, the following email will be sent out to the attendees.'), required=False, ) mail_text_order_free_attendee = I18nFormField( label=_("Text sent to attendees"), required=False, widget=I18nTextarea, ) mail_text_order_changed = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, ) mail_text_resend_link = I18nFormField( label=_("Text (sent by admin)"), required=False, widget=I18nTextarea, ) mail_text_resend_all_links = I18nFormField( label=_("Text (requested by user)"), required=False, widget=I18nTextarea, ) mail_days_order_expire_warning = forms.IntegerField( label=_("Number of days"), required=True, min_value=0, help_text=_("This email will be sent out this many days before the order expires. If the " "value is 0, the mail will never be sent.") ) mail_text_order_expire_warning = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, ) mail_text_waiting_list = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, ) mail_text_order_canceled = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, ) mail_text_order_custom_mail = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, ) mail_text_download_reminder = I18nFormField( label=_("Text sent to order contact address"), required=False, widget=I18nTextarea, ) mail_send_download_reminder_attendee = forms.BooleanField( label=_("Send an email to attendees"), help_text=_('If the order contains attendees with email addresses different from the person who orders the ' 'tickets, the following email will be sent out to the attendees.'), required=False, ) mail_text_download_reminder_attendee = I18nFormField( label=_("Text sent to attendees"), required=False, widget=I18nTextarea, ) mail_days_download_reminder = forms.IntegerField( label=_("Number of days"), required=False, min_value=0, help_text=_("This email will be sent out this many days before the order event starts. If the " "field is empty, the mail will never be sent.") ) mail_text_order_placed_require_approval = I18nFormField( label=_("Received order"), required=False, widget=I18nTextarea, ) mail_text_order_approved = I18nFormField( label=_("Approved order"), required=False, widget=I18nTextarea, help_text=_("This will only be sent out for non-free orders. Free orders will receive the free order " "template from above instead."), ) mail_text_order_denied = I18nFormField( label=_("Denied order"), required=False, widget=I18nTextarea, ) smtp_use_custom = forms.BooleanField( label=_("Use custom SMTP server"), help_text=_("All mail related to your event will be sent over the smtp server specified by you."), required=False ) smtp_host = forms.CharField( label=_("Hostname"), required=False, widget=forms.TextInput(attrs={'placeholder': 'mail.example.org'}) ) smtp_port = forms.IntegerField( label=_("Port"), required=False, widget=forms.TextInput(attrs={'placeholder': 'e.g. 587, 465, 25, ...'}) ) smtp_username = forms.CharField( label=_("Username"), widget=forms.TextInput(attrs={'placeholder': '*****@*****.**'}), required=False ) smtp_password = forms.CharField( label=_("Password"), required=False, widget=forms.PasswordInput(attrs={ 'autocomplete': 'new-password' # see https://bugs.chromium.org/p/chromium/issues/detail?id=370363#c7 }), ) smtp_use_tls = forms.BooleanField( label=_("Use STARTTLS"), help_text=_("Commonly enabled on port 587."), required=False ) smtp_use_ssl = forms.BooleanField( label=_("Use SSL"), help_text=_("Commonly enabled on port 465."), required=False ) base_context = { 'mail_text_order_placed': ['event', 'order', 'payment'], 'mail_text_order_placed_attendee': ['event', 'order', 'position'], 'mail_text_order_placed_require_approval': ['event', 'order'], 'mail_text_order_approved': ['event', 'order'], 'mail_text_order_denied': ['event', 'order', 'comment'], 'mail_text_order_paid': ['event', 'order', 'payment_info'], 'mail_text_order_paid_attendee': ['event', 'order', 'position'], 'mail_text_order_free': ['event', 'order'], 'mail_text_order_free_attendee': ['event', 'order', 'position'], 'mail_text_order_changed': ['event', 'order'], 'mail_text_order_canceled': ['event', 'order'], 'mail_text_order_expire_warning': ['event', 'order'], 'mail_text_order_custom_mail': ['event', 'order'], 'mail_text_download_reminder': ['event', 'order'], 'mail_text_download_reminder_attendee': ['event', 'order', 'position'], 'mail_text_resend_link': ['event', 'order'], 'mail_text_waiting_list': ['event', 'waiting_list_entry'], 'mail_text_resend_all_links': ['event', 'orders'] } 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) ) def __init__(self, *args, **kwargs): self.event = event = kwargs.get('obj') super().__init__(*args, **kwargs) self.fields['mail_html_renderer'].choices = [ (r.identifier, r.verbose_name) for r in event.get_html_mail_renderers().values() ] for k, v in self.base_context.items(): self._set_field_placeholders(k, v) for k, v in list(self.fields.items()): if k.endswith('_attendee') and not event.settings.attendee_emails_asked: # If we don't ask for attendee emails, we can't send them anything and we don't need to clutter # the user interface with it del self.fields[k] def clean(self): data = self.cleaned_data if not data.get('smtp_password') and data.get('smtp_username'): # Leave password unchanged if the username is set and the password field is empty. # This makes it impossible to set an empty password as long as a username is set, but # Python's smtplib does not support password-less schemes anyway. data['smtp_password'] = self.initial.get('smtp_password') if data.get('smtp_use_tls') and data.get('smtp_use_ssl'): raise ValidationError(_('You can activate either SSL or STARTTLS security, but not both at the same time.'))
class MailSettingsForm(SettingsForm): auto_fields = [ 'mail_from_name', ] mail_bcc = forms.CharField( label=_("Bcc address"), help_text=_("All emails will be sent to this address as a Bcc copy"), validators=[multimail_validate], required=False, max_length=255) mail_text_signature = I18nFormField( label=_("Signature"), required=False, widget=I18nTextarea, help_text=_("This will be attached to every email."), validators=[PlaceholderValidator([])], widget_kwargs={ 'attrs': { 'rows': '4', 'placeholder': _('e.g. your contact details') } }) mail_text_customer_registration = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, ) mail_text_customer_email_change = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, ) mail_text_customer_reset = I18nFormField( label=_("Text"), required=False, widget=I18nTextarea, ) base_context = { 'mail_text_customer_registration': ['customer', 'url'], 'mail_text_customer_email_change': ['customer', 'url'], 'mail_text_customer_reset': ['customer', 'url'], } def _get_sample_context(self, base_parameters): placeholders = {'organizer': self.organizer.name} if 'url' in base_parameters: placeholders['url'] = build_absolute_uri( self.organizer, 'presale:organizer.customer.activate' ) + '?token=' + get_random_string(30) if 'customer' in base_parameters: placeholders['name'] = pgettext_lazy('person_name_sample', 'John Doe') name_scheme = PERSON_NAME_SCHEMES[ self.organizer.settings.name_scheme] for f, l, w in name_scheme['fields']: if f == 'full_name': continue placeholders['name_%s' % f] = name_scheme['sample'][f] return placeholders def _set_field_placeholders(self, fn, base_parameters): phs = [ '{%s}' % p for p in sorted(self._get_sample_context(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)) def __init__(self, *args, **kwargs): self.organizer = kwargs.get('obj') super().__init__(*args, **kwargs) for k, v in self.base_context.items(): self._set_field_placeholders(k, v)