def configured_conditions(self): """ Get all flag conditions configured in settings """ # Get condition callables for our settings-configured conditions condition_fns = [(c, fn, v, None) for c, v in self.__conditions.items() for fn in get_condition(c)] return condition_fns
def dynamic_conditions(self): """ Get dynamic flag conditions from models.FlagState """ # Get condition callables for our dynamic-configured conditions FlagState = apps.get_model('flags', 'FlagState') condition_fns = [(s.condition, fn, s.value, s) for s in FlagState.objects.filter(name=self.name) for fn in get_condition(s.condition)] return condition_fns
def clean_value(self): condition_name = self.cleaned_data.get("condition") value = self.cleaned_data.get("value") condition = get_condition(condition_name) validator = getattr(condition, "validate") if validator is not None: try: validator(value) except Exception as e: raise forms.ValidationError(e) return value
def __init__(self, condition, value, required=False): self.condition = condition self.value = value self.fn = get_condition(self.condition) self.required = required
def test_get_condition_none(self): self.assertEqual(list(get_condition('notgettable')), [])
def test_get_condition(self): fn = lambda conditional_value: True register('gettable', fn=fn) self.assertEqual(list(get_condition('gettable')), [fn])
def test_get_condition_none(self): self.assertEqual(get_condition("notgettable"), None)
def test_get_condition(self): fn = lambda conditional_value: True register("gettable", fn=fn) self.assertEqual(get_condition("gettable"), fn)
def __init__(self, condition, value): self.condition = condition self.value = value self.fn = get_condition(self.condition)