class NoteForm(components.Form): id = None compo_state = components.Form.compo_state + ["id"] node_list = [ components.NumberInput(label='Parent note id', name='parent'), components.TextInput(label='Title', name='title', mandatory=True, placeholder='Insert a title here!'), components.Textarea(label='Text', name='text', mandatory=True), components.Button(value='Submit', color='primary', event_name='submit'), components.Button(value='Cancel', event_name='cancel') ] def handle_submit(self): if not self.validate(): self.page.show_fading_message( 'An error occurred in validating the form!', 'error') return note_value = self.get_values() if note_value['parent']: # force integer ids note_value['parent'] = int(note_value['parent']) if self.id is None: self.page.model.add_note(note_value) else: self.page.model.set_note(self.id, note_value) self.page.notes_link_list.redraw() self.page.notes_list.redraw() self.clean_form() def handle_cancel(self): self.clean_form() def clean_form(self): self.id = None self.set_value('title', '') self.set_value('text', '') self.set_value('parent', 0) self.redraw() def load_note(self, note_id): note = self.page.model.get_note(note_id) self.id = note['id'] self.set_value('parent', note['parent']) self.set_value('title', note['title']) self.set_value('text', note['text']) self.redraw()
def test_is_submit(page): page.root_node = components.Box(node_list=[ components.Button( cid='button', event_name='test_event', is_submit=False), components.Button( cid='button_is_submit', event_name='test_event', is_submit=True) ]) page.handle_transaction() assert 'type="button"' in page.button.render() assert 'type="submit"' in page.button_is_submit.render()
def test_tooltip(page): page.root_node = components.Box(node_list=[ components.Button(cid='button', event_name='test_event'), components.Button(cid='button_with_tooltip', event_name='test_event', tooltip='test tooltip') ]) page.handle_transaction() assert 'title=""' in page.button.render() assert 'title="test tooltip"' in page.button_with_tooltip.render()
def test_label(page): page.root_node = components.Box(node_list=[ components.Button(cid='button', event_name='test_event'), components.Button(cid='button_with_label', event_name='test_event', label='test_label') ]) page.handle_transaction() assert '<label ' not in page.button.render() assert '<label ' in page.button_with_label.render() assert '>test_label<' in page.button_with_label.render()
def test_disabled(page): page.root_node = components.Box(node_list=[ components.Button( cid='button', event_name='test_event', disabled=False), components.Button( cid='button_disabled', event_name='test_event', disabled=True) ]) page.handle_transaction() disabled = re.compile('class="[^"]*disabled[^"]*"') assert disabled.search(page.button_disabled.render()) assert not disabled.search(page.button.render())
def test_icon(page, bool_toggle): label = None if bool_toggle: label = 'some label' page.root_node = components.Box(node_list=[ components.Button(cid='button_with_icon', event_name='test_event', icon='times', label=label), components.Button(cid='button_with_icon_size', event_name='test_event', icon='times', icon_size=3, label=label), components.Button(cid='button_with_icon_color', event_name='test_event', icon='times', icon_color='primary', label=label), components.Button(cid='button_with_icon_size_color', event_name='test_event', icon='times', icon_size=3, icon_color='primary', label=label), ]) page.handle_transaction() assert 'fa fa-times' in page.button_with_icon.render() assert 'fa-3x' not in page.button_with_icon.render() assert 'text-primary' not in page.button_with_icon.render() assert 'fa fa-times' in page.button_with_icon_size.render() assert 'fa-3x' in page.button_with_icon_size.render() assert 'text-primary' not in page.button_with_icon_size.render() assert 'fa fa-times' in page.button_with_icon_color.render() assert 'fa-3x' not in page.button_with_icon_color.render() assert 'text-primary' in page.button_with_icon_color.render() assert 'fa fa-times' in page.button_with_icon_size_color.render() assert 'fa-3x' in page.button_with_icon_size_color.render() assert 'text-primary' in page.button_with_icon_size_color.render()
def init_struct(self): self.node_list.extend([ components.Box(title='Edit note', node_list=[NoteForm(cid='note_form')]), components.Box( cid="notes_list", title='My notes', default_child_cls=components.Box(node_list=[ components.Text(value=self.reflect.container_compo.text), components.ColLayout(node_list=[ components.Button(value='Edit this note', color='primary', cols=6, event_name='edit_note'), components.Button(value='Delete this note', color='danger', cols=6, event_name='delete_note') ]) ]), data_interface={ 'id': None, 'text': None, 'title': None }, get_data='notes'), components.LinkListLayout(cid="notes_link_list", slot='west', auto_update_children=True, show_pagination=False, show_search=False, get_data='notes', event_name='open_details', data_interface={ 'id': None, 'url': 'note/{id}', 'text': 'title' }) ])
class Logout(components.Box): """ Component that displays the Logout Button with some text. """ title = 'Logout Box' node_list = [ components.Text( value='This box is only visible for all authenticated users'), components.Button(value='Logout', color='warning', event_name='logout') ] def handle_logout(self): self.page.forget() self.page.show_fading_message('Logout done.', 'success') self.page.jump(self.page.request.matched_route.name, 1000)
def test_value(page, bool_toggle): icon = None if bool_toggle: icon = 'times' page.root_node = components.Box(node_list=[ components.Button(cid='button', event_name='test_event', value='test value', icon=icon) ]) page.handle_transaction() assert 'test value' in page.button.render() page.button.reset_render_cache() page.button.value = None assert 'test value' not in page.button.render()
def test_button_size_and_color(page, bool_toggle): color = None if bool_toggle: color = 'default' page.root_node = components.Box(node_list=[ components.Button(cid='button', event_name='test_event', color=color), components.Button(cid='button_sm', event_name='test_event', button_size='btn-sm', color=color), components.Button(cid='button_md', event_name='test_event', button_size='btn-md', color=color), components.Button(cid='button_lg', event_name='test_event', button_size='btn-lg', color=color) ]) page.handle_transaction() btn = page.button btn_sm = page.button_sm btn_md = page.button_md btn_lg = page.button_lg color_set = re.compile('class="[^"]*btn-default[^"]*"') if bool_toggle: assert color_set.search(btn.render()) assert color_set.search(btn_sm.render()) assert color_set.search(btn_md.render()) assert color_set.search(btn_lg.render()) else: assert not color_set.search(btn.render()) assert not color_set.search(btn_sm.render()) assert not color_set.search(btn_md.render()) assert not color_set.search(btn_lg.render()) no_size = re.compile('class="[^"]*form-control[^"]*"') sm = re.compile('class="[^"]*btn-sm[^"]*"') md = re.compile('class="[^"]*btn-md[^"]*"') lg = re.compile('class="[^"]*btn-lg[^"]*"') assert no_size.search(btn.render()) assert not sm.search(btn.render()) assert not md.search(btn.render()) assert not lg.search(btn.render()) assert not no_size.search(btn_sm.render()) assert sm.search(btn_sm.render()) assert not md.search(btn_sm.render()) assert not lg.search(btn_sm.render()) assert not no_size.search(btn_md.render()) assert not sm.search(btn_md.render()) assert md.search(btn_md.render()) assert not lg.search(btn_md.render()) assert not no_size.search(btn_lg.render()) assert not sm.search(btn_lg.render()) assert not md.search(btn_lg.render()) assert lg.search(btn_lg.render())