本文整理匯總了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'])
示例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"])
示例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'),
#.........這裏部分代碼省略.........