本文整理汇总了Python中djblets.conditions.ConditionSet.deserialize方法的典型用法代码示例。如果您正苦于以下问题:Python ConditionSet.deserialize方法的具体用法?Python ConditionSet.deserialize怎么用?Python ConditionSet.deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类djblets.conditions.ConditionSet
的用法示例。
在下文中一共展示了ConditionSet.deserialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_conditions
# 需要导入模块: from djblets.conditions import ConditionSet [as 别名]
# 或者: from djblets.conditions.ConditionSet import deserialize [as 别名]
def load_conditions(self, form_cls, conditions_key='conditions'):
"""Load a set of conditions from the configuration.
This loads and deserializes a set of conditions from the configuration
stored in the provided key. Those conditions can then be matched by the
caller.
If the conditions are not found, this will return ``None``.
If the conditions cannot be deserialized, this will log some diagnostic
output and error messages and return ``None``.
Args:
form_cls (type):
The configuration form class that owns the condition field.
This will generally be ``my_integration.form_cls``,
but can be another form in more complex integrations.
conditions_key (unicode, optional):
The key for the conditions data in the configuration.
Defaults to "conditions".
Returns:
djblets.conditions.conditions.ConditionSet:
The condition set based on the data, if found and if it could be
loaded. Otherwise, ``None`` will be returned.
"""
conditions_data = self.get(conditions_key)
if not conditions_data:
return None
try:
return ConditionSet.deserialize(
form_cls.base_fields[conditions_key].choices,
conditions_data,
choice_kwargs={
'local_site': self.local_site,
})
except:
logging.exception('Unable to load bad condition set data for '
'integration configuration ID=%s for key="%s"',
self.pk, conditions_key)
logging.debug('Bad conditions data = %r', conditions_data)
return None