Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
 def __init__(self, condition, value, required=False):
     self.condition = condition
     self.value = value
     self.fn = get_condition(self.condition)
     self.required = required
Exemplo n.º 5
0
 def test_get_condition_none(self):
     self.assertEqual(list(get_condition('notgettable')), [])
Exemplo n.º 6
0
 def test_get_condition(self):
     fn = lambda conditional_value: True
     register('gettable', fn=fn)
     self.assertEqual(list(get_condition('gettable')), [fn])
Exemplo n.º 7
0
 def test_get_condition_none(self):
     self.assertEqual(get_condition("notgettable"), None)
Exemplo n.º 8
0
 def test_get_condition(self):
     fn = lambda conditional_value: True
     register("gettable", fn=fn)
     self.assertEqual(get_condition("gettable"), fn)
Exemplo n.º 9
0
 def __init__(self, condition, value):
     self.condition = condition
     self.value = value
     self.fn = get_condition(self.condition)