Esempio n. 1
0
    def addformconfig(self, name, config):
        forms = self.settings.setdefault("forms", [])
        folder = os.path.join(self.folder, name)

        if hasattr(forms, 'items'):
            forms[name] = config
        else:
            forms.append(name)
            Form.saveconfig(config, folder)

        self.settings['forms'] = forms
        self._forms = []
        form = [form for form in self.forms if form.name == name][0]
        return form
Esempio n. 2
0
def test_should_return_list_of_defined_widgets():
    widgetone = {'field': 'test'}
    widgettwo = {'field': 'test2'}
    widgets = [widgetone, widgettwo]
    config = dict(widgets=widgets)
    form = Form('test', config, None)
    assert form.widgets == widgets
Esempio n. 3
0
    def forms(self):
        def mapformconfig(forms):
            if hasattr(forms, 'items'):
                for formname, config in forms.items():
                    yield formname, config
            else:
                for formname in forms:
                    folder = os.path.join(self.folder, formname)
                    config = readfolderconfig(folder, configname='form')
                    yield formname, config

        if not self._forms:
            forms = self.settings.setdefault("forms", [])
            for formname, config in mapformconfig(forms):
                folder = os.path.join(self.folder, formname)
                form = Form.from_config(formname, config, folder, project=self)
                self._forms.append(form)

        return self._forms
Esempio n. 4
0
def test_should_return_no_widgets_when_not_found():
    form = Form('test', {}, None)
    assert form.widgets == []
Esempio n. 5
0
def test_should_return_layer_name_from_config():
    form = Form('test', {'layer': 'TestLayer'}, None)
    assert form.layername == 'TestLayer'
Esempio n. 6
0
def test_should_return_name_if_no_label():
    form = Form('test', {}, None)
    assert form.label == 'test'
Esempio n. 7
0
def test_should_return_label_from_config():
    form = Form('test', {"label": "TestLabel"}, None)
    assert form.label == "TestLabel"