Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        self.obj = GlobalSettingsObject()
        super().__init__(*args, obj=self.obj, **kwargs)

        self.fields = OrderedDict(list(self.fields.items()) + [
            ('footer_text', I18nFormField(
                widget=I18nTextInput,
                required=False,
                label=_("Additional footer text"),
                help_text=_("Will be included as additional text in the footer, site-wide.")
            )),
            ('footer_link', I18nFormField(
                widget=I18nTextInput,
                required=False,
                label=_("Additional footer link"),
                help_text=_("Will be included as the link in the additional footer text.")
            )),
            ('banner_message', I18nFormField(
                widget=I18nTextarea,
                required=False,
                label=_("Global message banner"),
            )),
            ('banner_message_detail', I18nFormField(
                widget=I18nTextarea,
                required=False,
                label=_("Global message banner detail text"),
            )),
            ('opencagedata_apikey', SecretKeySettingsField(
                required=False,
                label=_("OpenCage API key for geocoding"),
            )),
            ('mapquest_apikey', SecretKeySettingsField(
                required=False,
                label=_("MapQuest API key for geocoding"),
            )),
            ('leaflet_tiles', forms.CharField(
                required=False,
                label=_("Leaflet tiles URL pattern"),
                help_text=_("e.g. {sample}").format(sample="https://a.tile.openstreetmap.org/{z}/{x}/{y}.png")
            )),
            ('leaflet_tiles_attribution', forms.CharField(
                required=False,
                label=_("Leaflet tiles attribution"),
                help_text=_("e.g. {sample}").format(sample='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors')
            )),
        ])
        responses = register_global_settings.send(self)
        for r, response in sorted(responses, key=lambda r: str(r[0])):
            for key, value in response.items():
                # We need to be this explicit, since OrderedDict.update does not retain ordering
                self.fields[key] = value

        self.fields['banner_message'].widget.attrs['rows'] = '2'
        self.fields['banner_message_detail'].widget.attrs['rows'] = '3'
Ejemplo n.º 2
0
def register_global_settings(sender, **kwargs):
    return OrderedDict([
        ('payment_stripe_connect_client_id', forms.CharField(
            label=_('Stripe Connect: Client ID'),
            required=False,
            validators=(
                StripeKeyValidator('ca_'),
            ),
        )),
        ('payment_stripe_connect_secret_key', SecretKeySettingsField(
            label=_('Stripe Connect: Secret key'),
            required=False,
            validators=(
                StripeKeyValidator(['sk_live_', 'rk_live_']),
            ),
        )),
        ('payment_stripe_connect_publishable_key', forms.CharField(
            label=_('Stripe Connect: Publishable key'),
            required=False,
            validators=(
                StripeKeyValidator('pk_live_'),
            ),
        )),
        ('payment_stripe_connect_test_secret_key', SecretKeySettingsField(
            label=_('Stripe Connect: Secret key (test)'),
            required=False,
            validators=(
                StripeKeyValidator(['sk_test_', 'rk_test_']),
            ),
        )),
        ('payment_stripe_connect_test_publishable_key', forms.CharField(
            label=_('Stripe Connect: Publishable key (test)'),
            required=False,
            validators=(
                StripeKeyValidator('pk_test_'),
            ),
        )),
        ('payment_stripe_connect_app_fee_percent', forms.DecimalField(
            label=_('Stripe Connect: App fee (percent)'),
            required=False,
        )),
        ('payment_stripe_connect_app_fee_max', forms.DecimalField(
            label=_('Stripe Connect: App fee (max)'),
            required=False,
        )),
        ('payment_stripe_connect_app_fee_min', forms.DecimalField(
            label=_('Stripe Connect: App fee (min)'),
            required=False,
        )),
    ])
Ejemplo n.º 3
0
class VenuelessSettingsForm(SettingsForm):
    venueless_url = forms.URLField(
        label=_("Venueless URL"),
        required=False,
    )
    venueless_secret = SecretKeySettingsField(
        label=_("Venueless secret"),
        required=False,
    )
    venueless_issuer = forms.CharField(
        label=_("Venueless issuer"),
        required=False,
    )
    venueless_audience = forms.CharField(
        label=_("Venueless audience"),
        required=False,
    )
    venueless_start = RelativeDateTimeField(
        label=_('Start of live event'),
        required=False,
    )
    venueless_allow_pending = forms.BooleanField(
        label=_(
            'Allow users to access the live event before their order is paid'),
        required=False,
    )
    venueless_all_items = forms.BooleanField(
        label=_('Allow buyers of all admission products'), required=False)
    venueless_items = forms.ModelMultipleChoiceField(
        widget=forms.CheckboxSelectMultiple(
            attrs={
                'class': 'scrolling-multiple-choice',
                'data-inverse-dependency': '<[name$=venueless_all_items]'
            }),
        label=_('Limit to products'),
        required=False,
        queryset=Item.objects.none(),
        initial=None)

    def __init__(self, *args, **kwargs):
        event = kwargs['obj']
        super().__init__(*args, **kwargs)
        self.fields['venueless_items'].queryset = event.items.all()

    def clean(self):
        data = super().clean()

        for k, v in self.fields.items():
            if isinstance(v, forms.ModelMultipleChoiceField):
                answstr = [o.pk for o in data[k]]
                data[k] = answstr

        return data
Ejemplo n.º 4
0
def register_global_settings(sender, **kwargs):
    return OrderedDict([
        ('payment_mollie_connect_client_id',
         forms.CharField(
             label=_('Mollie Connect: Client ID'),
             required=False,
             validators=(MollieKeyValidator('app_'), ),
         )),
        ('payment_mollie_connect_client_secret',
         SecretKeySettingsField(
             label=_('Mollie Connect: Client secret'),
             required=False,
         )),
    ])
Ejemplo n.º 5
0
def register_global_settings(sender, **kwargs):
    return OrderedDict([
        ('payment_paypal_connect_client_id', forms.CharField(
            label=_('PayPal Connect: Client ID'),
            required=False,
        )),
        ('payment_paypal_connect_secret_key', SecretKeySettingsField(
            label=_('PayPal Connect: Secret key'),
            required=False,
        )),
        ('payment_paypal_connect_endpoint', forms.ChoiceField(
            label=_('PayPal Connect Endpoint'),
            initial='live',
            choices=(
                ('live', 'Live'),
                ('sandbox', 'Sandbox'),
            ),
        )),
    ])
Ejemplo n.º 6
0
class CinesendSettingsForm(SettingsForm):
    cinesend_environment = forms.ChoiceField(
        label=_("Environment"),
        choices=(
            ("api.cinesend.com", _("Production")),
            ("staging-api.cinesend.com", _("Staging")),
        ),
    )
    cinesend_api_key = SecretKeySettingsField(
        label="API Key",
        required=False,
    )
    cinesend_exclude_addons = forms.BooleanField(
        label=_('Exclude add-on products'),
        required=False,
    )
    cinesend_voucher_landingpage = forms.BooleanField(
        label=_('Use landing page URL for vouchers'),
        required=False,
    )
Ejemplo n.º 7
0
    def settings_form_fields(self):
        d = OrderedDict([
            ('merchant_id',
             forms.CharField(label=_('Merchant ID'),
                             min_length=2,
                             max_length=16,
                             help_text=_('The Merchant ID issued by DIBS'))),
            ('test_mode',
             forms.BooleanField(
                 label=_('Test mode'),
                 required=False,
                 initial=False,
                 help_text=_(
                     'If checked, payments will be processed in test mode '
                     '(cf. <a target="_blank" rel="noopener" href="{docs_url}">{docs_url}</a>)'
                 ).format(
                     docs_url=
                     'https://tech.dibspayment.com/D2/Hosted/Input_parameters/Standard'
                 ))),
            ('md5_key1',
             forms.CharField(
                 label=_('MD5 key 1'),
                 min_length=32,
                 max_length=32,
                 help_text=
                 _('MD5 key 1 (32 characters)'
                   ' (cf. <a target="_blank" rel="noopener" href="{docs_url}">{docs_url}</a>)'
                   ' (required if "{parent_control}" is set)').format(
                       docs_url='https://tech.dibspayment.com/D2/API/MD5',
                       parent_control=_('MD5-control of payments')))),
            ('md5_key2',
             forms.CharField(
                 label=_('MD5 key 2'),
                 min_length=32,
                 max_length=32,
                 help_text=
                 _('MD5 key 2 (32 characters)'
                   ' (cf. <a target="_blank" rel="noopener" href="{docs_url}">{docs_url}</a>)'
                   ' (required if "{parent_control}" is set)').format(
                       docs_url='https://tech.dibspayment.com/D2/API/MD5',
                       parent_control=_('MD5-control of payments')))),
            ('decorator',
             forms.ChoiceField(
                 label=_('Payment page design'),
                 choices=(('default', _('Default')), ('basal', _('Basal')),
                          ('rich', _('Rich')), ('responsive',
                                                _('Responsive'))),
                 initial='responsive',
                 help_text=_(
                     '(cf. <a target="_blank" rel="noopener" href="{docs_url}">{docs_url}</a>)'
                 ).format(
                     docs_url=
                     'https://tech.dibspayment.com/D2/Hosted/Input_parameters/Standard'
                 ))),
            ('api_user',
             forms.CharField(
                 label=_('API Username'),
                 required=False,
                 help_text=_(
                     'Required for refunds. Can be set up at Setup > User Setup > API users.'
                 ).format(
                     docs_url=
                     'https://tech.dibspayment.com/D2/Hosted/Input_parameters/Standard'
                 ))),
            ('api_password',
             SecretKeySettingsField(
                 label=_('API Password'),
                 required=False,
                 help_text=_(
                     'Required for refunds. Can be set up at Setup > User Setup > API users.'
                 ).format(
                     docs_url=
                     'https://tech.dibspayment.com/D2/Hosted/Input_parameters/Standard'
                 ))),
        ] + list(super().settings_form_fields.items()))
        d.move_to_end('_enabled', last=False)

        return d
Ejemplo n.º 8
0
class SMTPMailForm(SettingsForm):
    mail_from = forms.EmailField(
        label=_("Sender address"),
        help_text=_("Sender address for outgoing emails"),
        required=True,
    )
    smtp_host = forms.CharField(
        label=_("Hostname"),
        required=True,
        widget=forms.TextInput(attrs={'placeholder': 'mail.example.org'})
    )
    smtp_port = forms.IntegerField(
        label=_("Port"),
        required=True,
        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 = SecretKeySettingsField(
        label=_("Password"),
        required=False,
    )
    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 = super().clean()
        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.'))
        for k, v in self.fields.items():
            val = data.get(k)
            if v._required and not val:
                self.add_error(k, _('This field is required.'))
        return data

    def clean_smtp_host(self):
        v = self.cleaned_data['smtp_host']
        if not settings.MAIL_CUSTOM_SMTP_ALLOW_PRIVATE_NETWORKS:
            try:
                if ipaddress.ip_address(v).is_private:
                    raise ValidationError(_('You are not allowed to use this mail server, please choose one with a '
                                            'public IP address instead.'))
            except ValueError:
                try:
                    if ipaddress.ip_address(socket.gethostbyname(v)).is_private:
                        raise ValidationError(_('You are not allowed to use this mail server, please choose one with a '
                                                'public IP address instead.'))
                except OSError:
                    raise ValidationError(_('We were unable to resolve this hostname.'))
        return v

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        if self.obj.settings.mail_from in (settings.MAIL_FROM, settings.MAIL_FROM_ORGANIZERS):
            self.initial.pop('mail_from')

        for k, v in self.fields.items():
            v._required = v.required
            v.required = False
            v.widget.is_required = False