コード例 #1
0
ファイル: test_fields.py プロジェクト: quantrocket/lux
 def test_JsonField(self):
     field = forms.JsonField()
     value = {'test': '????'}
     t = type(value)
     json_val = json.dumps(value)
     result = field.clean(json_val)
     self.assertEqual(type(result), t)
コード例 #2
0
class ApplicationForm(forms.Form):
    id = forms.CharField(readonly=True, required=False)
    name = forms.SlugField(minlength=2, maxlength=32, validator=UniqueField)
    domain = forms.CharField(minlength=2,
                             maxlength=120,
                             required=False,
                             validator=UniqueField)
    config = forms.JsonField(required=False, ace=json.dumps({'mode': 'json'}))
コード例 #3
0
ファイル: forms.py プロジェクト: pvanderlinden/lux
class PermissionForm(forms.Form):
    model = 'permission'
    id = forms.HiddenField(required=False)
    name = forms.CharField()
    description = forms.TextField()
    policy = forms.JsonField(text_edit=json.dumps({'mode': 'json'}))

    def clean(self):
        policy = self.cleaned_data['policy']
        self.cleaned_data['policy'] = validate_policy(policy)
コード例 #4
0
ファイル: forms.py プロジェクト: Bhajju2510/SupervisedML
class PermissionForm(forms.Form):
    model = 'permissions'
    name = forms.CharField()
    description = forms.TextField(required=False, rows=2)
    policy = forms.JsonField(lux_ace=json.dumps({'mode': 'json'}))

    def clean(self):
        if 'policy' in self.cleaned_data:
            policy = self.cleaned_data['policy']
            self.cleaned_data['policy'] = validate_policy(policy)
コード例 #5
0
class PageForm(forms.Form):
    path = forms.CharField(required=False)
    title = forms.CharField()
    description = forms.TextField(required=False)
    template = odm.RelationshipField(template_model, label='template')
    published = forms.BooleanField(required=False)
    layout = forms.JsonField(text_edit=json.dumps({'mode': 'json'}))

    def clean_layout(self, value):
        if not isinstance(value, dict):
            raise forms.ValidationError('Layout must be a dictionary')
        layout = {}
        if 'components' in value:
            components = value['components']
            if not isinstance(components, list):
                raise forms.ValidationError('componets must be a list')
            layout['components'] = components
        if 'rows' in value:
            rows = value['rows']
            if not isinstance(rows, list):
                raise forms.ValidationError('rows must be a list')
            layout['rows'] = rows
        return layout
コード例 #6
0
ファイル: fields.py プロジェクト: pvanderlinden/lux
    def test_JsonField_raises(self):
        field = forms.JsonField()
        value = 'string'

        with self.assertRaises(forms.ValidationError):
            field._clean(value, None)
コード例 #7
0
ファイル: test_fields.py プロジェクト: quantrocket/lux
 def test_JsonField_fail(self):
     field = forms.JsonField()
     self.assertRaises(forms.ValidationError, field.clean, self)
コード例 #8
0
ファイル: test_fields.py プロジェクト: quantrocket/lux
 def test_JsonField_object(self):
     field = forms.JsonField()
     value = {'bla': 'foo', 'zzz': [1, 2, 3]}
     self.assertEqual(field.clean(value), value)
コード例 #9
0
ファイル: test_fields.py プロジェクト: quantrocket/lux
 def test_JsonField_string(self):
     field = forms.JsonField()
     self.assertRaises(forms.ValidationError, field.clean, 'string')