当前位置: 首页>>代码示例>>Python>>正文


Python SettingsSandbox.set方法代码示例

本文整理汇总了Python中pretix.base.settings.SettingsSandbox.set方法的典型用法代码示例。如果您正苦于以下问题:Python SettingsSandbox.set方法的具体用法?Python SettingsSandbox.set怎么用?Python SettingsSandbox.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pretix.base.settings.SettingsSandbox的用法示例。


在下文中一共展示了SettingsSandbox.set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_sandbox

# 需要导入模块: from pretix.base.settings import SettingsSandbox [as 别名]
# 或者: from pretix.base.settings.SettingsSandbox import set [as 别名]
    def test_sandbox(self):
        sandbox = SettingsSandbox('testing', 'foo', self.event)
        sandbox.set('foo', 'bar')
        self.assertEqual(sandbox.get('foo'), 'bar')
        self.assertEqual(self.event.settings.get('testing_foo_foo'), 'bar')
        self.assertIsNone(self.event.settings.get('foo'), 'bar')

        sandbox['bar'] = 'baz'
        sandbox.baz = 42

        self.event = Event.objects.get(id=self.event.id)
        sandbox = SettingsSandbox('testing', 'foo', self.event)
        self.assertEqual(sandbox['bar'], 'baz')
        self.assertEqual(sandbox.baz, '42')

        del sandbox.baz
        del sandbox['bar']

        self.assertIsNone(sandbox.bar)
        self.assertIsNone(sandbox['baz'])
开发者ID:JRodDynamite,项目名称:pretix,代码行数:22,代码来源:test_settings.py

示例2: test_sandbox

# 需要导入模块: from pretix.base.settings import SettingsSandbox [as 别名]
# 或者: from pretix.base.settings.SettingsSandbox import set [as 别名]
    def test_sandbox(self):
        sandbox = SettingsSandbox("testing", "foo", self.event)
        sandbox.set("foo", "bar")
        self.assertEqual(sandbox.get("foo"), "bar")
        self.assertEqual(self.event.settings.get("testing_foo_foo"), "bar")
        self.assertIsNone(self.event.settings.get("foo"), "bar")

        sandbox["bar"] = "baz"
        sandbox.baz = 42

        self.event = Event.objects.get(identity=self.event.identity)
        sandbox = SettingsSandbox("testing", "foo", self.event)
        self.assertEqual(sandbox["bar"], "baz")
        self.assertEqual(sandbox.baz, "42")

        del sandbox.baz
        del sandbox["bar"]

        self.assertIsNone(sandbox.bar)
        self.assertIsNone(sandbox["baz"])
开发者ID:akuks,项目名称:pretix,代码行数:22,代码来源:test_settings.py

示例3: __init__

# 需要导入模块: from pretix.base.settings import SettingsSandbox [as 别名]
# 或者: from pretix.base.settings.SettingsSandbox import set [as 别名]
class BasePaymentProvider:
    """
    This is the base class for all payment providers.
    """

    def __init__(self, event: Event):
        self.event = event
        self.settings = SettingsSandbox('payment', self.identifier, event)
        # Default values
        if self.settings.get('_fee_reverse_calc') is None:
            self.settings.set('_fee_reverse_calc', True)

    def __str__(self):
        return self.identifier

    @property
    def is_enabled(self) -> bool:
        """
        Returns whether or whether not this payment provider is enabled.
        By default, this is determined by the value of the ``_enabled`` setting.
        """
        return self.settings.get('_enabled', as_type=bool)

    def calculate_fee(self, price: Decimal) -> Decimal:
        """
        Calculate the fee for this payment provider which will be added to
        final price before fees (but after taxes). It should include any taxes.
        The default implementation makes use of the setting ``_fee_abs`` for an
        absolute fee and ``_fee_percent`` for a percentage.

        :param price: The total value without the payment method fee, after taxes.
        """
        fee_abs = self.settings.get('_fee_abs', as_type=Decimal, default=0)
        fee_percent = self.settings.get('_fee_percent', as_type=Decimal, default=0)
        fee_reverse_calc = self.settings.get('_fee_reverse_calc', as_type=bool, default=True)
        if fee_reverse_calc:
            return round_decimal((price + fee_abs) * (1 / (1 - fee_percent / 100)) - price)
        else:
            return round_decimal(price * fee_percent / 100) + fee_abs

    @property
    def verbose_name(self) -> str:
        """
        A human-readable name for this payment provider. This should
        be short but self-explaining. Good examples include 'Bank transfer'
        and 'Credit card via Stripe'.
        """
        raise NotImplementedError()  # NOQA

    @property
    def identifier(self) -> str:
        """
        A short and unique identifier for this payment provider.
        This should only contain lowercase letters and in most
        cases will be the same as your packagename.
        """
        raise NotImplementedError()  # NOQA

    @property
    def settings_form_fields(self) -> dict:
        """
        When the event's administrator visits the event configuration
        page, this method is called to return the configuration fields available.

        It should therefore return a dictionary where the keys should be (unprefixed)
        settings keys and the values should be corresponding Django form fields.

        The default implementation returns the appropriate fields for the ``_enabled``,
        ``_fee_abs`` and ``_fee_percent`` settings mentioned above.

        We suggest that you return an ``OrderedDict`` object instead of a dictionary
        and make use of the default implementation. Your implementation could look
        like this::

            @property
            def settings_form_fields(self):
                return OrderedDict(
                    list(super().settings_form_fields.items()) + [
                        ('bank_details',
                         forms.CharField(
                             widget=forms.Textarea,
                             label=_('Bank account details'),
                             required=False
                         ))
                    ]
                )

        .. WARNING:: It is highly discouraged to alter the ``_enabled`` field of the default
                     implementation.
        """
        return OrderedDict([
            ('_enabled',
             forms.BooleanField(
                 label=_('Enable payment method'),
                 required=False,
             )),
            ('_fee_abs',
             forms.DecimalField(
                 label=_('Additional fee'),
                 help_text=_('Absolute value'),
#.........这里部分代码省略.........
开发者ID:JRodDynamite,项目名称:pretix,代码行数:103,代码来源:payment.py


注:本文中的pretix.base.settings.SettingsSandbox.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。