def test_datetime_format_split(self): ret = HtmlForm._split_datetime_format("%Y-%m-%d %H:%M:%S") assert ret == ("yy-mm-dd", "HH:mm:ss") ret = HtmlForm._split_datetime_format("%Y-%m-%d %H:%M") assert ret == ("yy-mm-dd", "HH:mm") ret = HtmlForm._split_datetime_format("%Y-%m-%d") assert ret == ("yy-mm-dd", "") ret = HtmlForm._split_datetime_format("%H:%M:%S") assert ret == ("", "HH:mm:ss")
def test_datetime_format_split(self): ret = HtmlForm._split_datetime_format('%Y-%m-%d %H:%M:%S') assert ret == ('yy-mm-dd', 'HH:mm:ss') ret = HtmlForm._split_datetime_format('%Y-%m-%d %H:%M') assert ret == ('yy-mm-dd', 'HH:mm') ret = HtmlForm._split_datetime_format('%Y-%m-%d') assert ret == ('yy-mm-dd', '') ret = HtmlForm._split_datetime_format('%H:%M:%S') assert ret == ('', 'HH:mm:ss')
def __init__(self, app=None, ignore_uncap=False, ignore_wrappers=True, cloth=None, polymorphic=True, doctype=None, hier_delim='.', cloth_parser=None, header=True, table_name_attr='class', table_name=None, input_class=None, input_div_class=None, input_wrapper_class=None, label_class=None, action=None, table_class=None, field_name_attr='class', border=0, row_class=None, cell_class=None, header_cell_class=None, can_add=True, can_remove=True, label=True, before_table=None): super(HtmlFormTable, self).__init__(app=app, ignore_uncap=ignore_uncap, ignore_wrappers=ignore_wrappers, polymorphic=polymorphic, hier_delim=hier_delim, doctype=doctype, cloth=cloth, cloth_parser=cloth_parser, header=header, table_name_attr=table_name_attr, table_name=table_name, table_class=table_class, field_name_attr=field_name_attr, border=border, row_class=row_class, cell_class=cell_class, header_cell_class=header_cell_class, before_table=before_table) self.prot_form = HtmlForm(label=label, label_class=label_class, action=action, input_class=input_class, input_div_class=input_div_class, input_wrapper_class=input_wrapper_class) self.can_add = can_add self.can_remove = can_remove self.use_global_null_handler = False self.label = label self._init_input_vars(input_class, input_div_class, input_wrapper_class, label_class)
def _test_type(cls, inst): from spyne.util import appreg appreg._applications.clear() class SomeService(ServiceBase): @rpc(_returns=cls, _body_style='bare') def some_call(ctx): return inst prot = HtmlForm(cloth=T_TEST) app = Application([SomeService], 'some_ns', out_protocol=prot) null = NullServer(app, ostr=True) ret = ''.join(null.service.some_call()) try: elt = html.fromstring(ret) except: print(ret) raise show(elt, stdout=False) elt = elt.xpath('//*[@spyne]')[0][ 0] # get the form tag inside the body tag elt = strip_ns(elt) # get rid of namespaces to simplify xpaths in tests print(etree.tostring(elt, pretty_print=True)) return elt
def __init__(self, app=None, ignore_uncap=False, ignore_wrappers=True, cloth=None, attr_name='spyne_id', root_attr_name='spyne', polymorphic=True, doctype=None, hier_delim='.', cloth_parser=None, produce_header=True, table_name_attr='class', field_name_attr='class', border=0, row_class=None, cell_class=None, header_cell_class=None, can_add=True, can_remove=True): super(HtmlFormTable, self).__init__(app=app, ignore_uncap=ignore_uncap, ignore_wrappers=ignore_wrappers, polymorphic=polymorphic, hier_delim=hier_delim, doctype=doctype, cloth=cloth, attr_name=attr_name, root_attr_name=root_attr_name, cloth_parser=cloth_parser, produce_header=produce_header, table_name_attr=table_name_attr, field_name_attr=field_name_attr, border=border, row_class=row_class, cell_class=cell_class, header_cell_class=header_cell_class) self.prot_form = HtmlForm() self.can_add = can_add self.can_remove = can_remove self.use_global_null_handler = False
class HtmlFormTable(HtmlColumnTable): def __init__(self, app=None, ignore_uncap=False, ignore_wrappers=False, cloth=None, attr_name='spyne_id', root_attr_name='spyne', cloth_parser=None, can_add=True, can_remove=True): super(HtmlFormTable, self).__init__(app=app, ignore_uncap=ignore_uncap, ignore_wrappers=ignore_wrappers, cloth=cloth, attr_name=attr_name, root_attr_name=root_attr_name, cloth_parser=cloth_parser) self.serialization_handlers = cdict({ ModelBase: self.model_base_to_parent, }) self.prot_form = HtmlForm() self.can_add = can_add self.can_remove = can_remove def _init_cloth(self, *args, **kwargs): super(HtmlFormTable, self)._init_cloth(*args, **kwargs) form = E.form(method='POST', enctype="multipart/form-data") if self._root_cloth is None: self._cloth = self._root_cloth = form else: self._root_cloth.append(form) self._root_cloth = form def model_base_to_parent(self, ctx, cls, inst, parent, name, array_index=None, from_arr=False, **kwargs): if from_arr: with parent.element('tr'): with parent.element('td'): self.prot_form.to_parent(ctx, cls, inst, parent, name, **kwargs) else: self.prot_form.to_parent(ctx, cls, inst, parent, name, **kwargs) def extend_header_row(self, ctx, cls, parent, name, **kwargs): if self.can_add or self.can_remove: parent.write(E.td())
def __init__(self, app=None, ignore_uncap=False, ignore_wrappers=False, cloth=None, attr_name='spyne_id', root_attr_name='spyne', cloth_parser=None, can_add=True, can_remove=True): super(HtmlFormTable, self).__init__(app=app, ignore_uncap=ignore_uncap, ignore_wrappers=ignore_wrappers, cloth=cloth, attr_name=attr_name, root_attr_name=root_attr_name, cloth_parser=cloth_parser) self.serialization_handlers = cdict({ ModelBase: self.model_base_to_parent, }) self.prot_form = HtmlForm() self.can_add = can_add self.can_remove = can_remove
def _test_type_no_root_cloth(cls, inst): from spyne.util import appreg appreg._applications.clear() class SomeService(ServiceBase): @rpc(_returns=cls, _body_style='bare') def some_call(ctx): return inst prot = HtmlForm() app = Application([SomeService], 'some_ns', out_protocol=prot) null = NullServer(app, ostr=True) elt = etree.fromstring(''.join(null.service.some_call())) show(elt) return elt
from a2billing_spyne.service import ReaderServiceBase, ScreenBase, DalBase SIP_BUDDY_CUST = dict( name=dict(order=1, exc=False), callerid=dict(order=2, exc=False), context=dict(order=3, write=False, exc=False), dtmfmode=dict(order=4, exc=False), host=dict(order=5, write=False, exc=False), secret=dict(order=6, exc=False), type=dict(order=7, exc=False), ) SipBuddyScreen = SipBuddy.customize( prot=HtmlForm(), form_action="put_sip_buddy", child_attrs_all=dict(exc=True,), child_attrs=dict( id=dict(order=0, write=False, exc=False), **SIP_BUDDY_CUST ), ) class NewSipBuddyScreen(ScreenBase): main = SipBuddyScreen class SipBuddyDetailScreen(ScreenBase): main = SipBuddyScreen
class HtmlFormTable(HtmlColumnTable, HtmlFormRoot): def __init__(self, app=None, ignore_uncap=False, ignore_wrappers=True, cloth=None, polymorphic=True, doctype=None, hier_delim='.', cloth_parser=None, header=True, table_name_attr='class', table_name=None, input_class=None, input_div_class=None, input_wrapper_class=None, label_class=None, action=None, table_class=None, field_name_attr='class', border=0, row_class=None, cell_class=None, header_cell_class=None, can_add=True, can_remove=True, label=True, before_table=None): super(HtmlFormTable, self).__init__(app=app, ignore_uncap=ignore_uncap, ignore_wrappers=ignore_wrappers, polymorphic=polymorphic, hier_delim=hier_delim, doctype=doctype, cloth=cloth, cloth_parser=cloth_parser, header=header, table_name_attr=table_name_attr, table_name=table_name, table_class=table_class, field_name_attr=field_name_attr, border=border, row_class=row_class, cell_class=cell_class, header_cell_class=header_cell_class, before_table=before_table) self.prot_form = HtmlForm(label=label, label_class=label_class, action=action, input_class=input_class, input_div_class=input_div_class, input_wrapper_class=input_wrapper_class) self.can_add = can_add self.can_remove = can_remove self.use_global_null_handler = False self.label = label self._init_input_vars(input_class, input_div_class, input_wrapper_class, label_class) @coroutine def model_base_to_parent(self, ctx, cls, inst, parent, name, from_arr=False, remove=None, **kwargs): if from_arr: td_attrs = {} if self.field_name_attr: td_attrs[self.field_name_attr] = name with parent.element('tr'): with parent.element('td', attrib=td_attrs): ret = self.prot_form.to_parent(ctx, cls, inst, parent, name, from_arr=from_arr, no_label=True, **kwargs) if isgenerator(ret): try: while True: y = (yield) ret.send(y) except Break as b: try: ret.throw(b) except StopIteration: pass if remove is None: remove = True self.extend_data_row(ctx, cls, inst, parent, name, remove=remove, **kwargs) else: ret = self.prot_form.to_parent(ctx, cls, inst, parent, name, from_arr=from_arr, no_label=True, **kwargs) if isgenerator(ret): try: while True: y = (yield) ret.send(y) except Break as b: try: ret.throw(b) except StopIteration: pass # sole reason to override is to generate labels @coroutine def wrap_table(self, ctx, cls, inst, parent, name, gen_rows, **kwargs): if name == "": name = cls.get_type_name() if self.label: parent.write(E.label(self.trc(cls, ctx.locale, name))) ret = self._gen_table(ctx, cls, inst, parent, name, gen_rows, **kwargs) if isgenerator(ret): try: while True: sv2 = (yield) ret.send(sv2) except Break as b: try: ret.throw(b) except StopIteration: pass def extend_header_row(self, ctx, cls, parent, name, **kwargs): if self.can_add or self.can_remove: parent.write(E.th(**{'class': 'array-button'})) def extend_data_row(self, ctx, cls, inst, parent, name, array_index=None, add=False, remove=True, **kwargs): if array_index is None: return if not (self.can_remove or self.can_add): return td = E.td(style='white-space: nowrap;') td.attrib['class'] = 'array-button' self._gen_buttons(td, name, add, remove) parent.write(td) def _gen_buttons(self, elt, name, add, remove): name = "%s-%d" % (self.selsafe(name), SOME_COUNTER[0]) if add: elt.append( E.button('+', **{ "class": "%s_btn_add" % name, "type": "button", }), ) if remove: elt.append( E.button('-', **{ "class": "%s_btn_remove" % name, "type": "button", }), ) def extend_table(self, ctx, cls, parent, name, **kwargs): if not self.can_add: return # FIXME: just fix me. if issubclass(cls, Array): cls = next(iter(cls._type_info.values())) self._gen_row(ctx, cls, [(cls.__orig__ or cls)()], parent, name) # even though there are calls to coroutines here, as the passed objects # are empty, so it's not possible to have push data. so there's no need # to check the returned generators. from_arr = True if issubclass(cls, ComplexModelBase): inst = (cls.__orig__ or cls)() ctx.protocol.inst_stack.append((cls, inst, from_arr)) if cls.Attributes.max_occurs > 1: self._gen_row(ctx, cls, [inst], parent, name, add=True, remove=False, array_index=-1) else: self._gen_row(ctx, cls, inst, parent, name, add=True, remove=False, array_index=-1) else: inst = None ctx.protocol.inst_stack.append((cls, inst, from_arr)) if cls.Attributes.max_occurs > 1: self.model_base_to_parent(ctx, cls, inst, parent, name, from_arr=True, add=True, remove=False, array_index=-1) else: self.model_base_to_parent(ctx, cls, inst, parent, name, add=True, remove=False, array_index=-1) ctx.protocol.inst_stack.pop() name = '%s-%d' % (self.selsafe(name), SOME_COUNTER[0]) SOME_COUNTER[0] += 1 parent.write(self._format_js(ADD_JS, name=name))
class HtmlFormTable(HtmlColumnTable, HtmlWidget): def __init__(self, app=None, ignore_uncap=False, ignore_wrappers=True, cloth=None, attr_name='spyne_id', root_attr_name='spyne', polymorphic=True, doctype=None, hier_delim='.', cloth_parser=None, produce_header=True, table_name_attr='class', field_name_attr='class', border=0, row_class=None, cell_class=None, header_cell_class=None, can_add=True, can_remove=True): super(HtmlFormTable, self).__init__(app=app, ignore_uncap=ignore_uncap, ignore_wrappers=ignore_wrappers, polymorphic=polymorphic, hier_delim=hier_delim, doctype=doctype, cloth=cloth, attr_name=attr_name, root_attr_name=root_attr_name, cloth_parser=cloth_parser, produce_header=produce_header, table_name_attr=table_name_attr, field_name_attr=field_name_attr, border=border, row_class=row_class, cell_class=cell_class, header_cell_class=header_cell_class) self.prot_form = HtmlForm() self.can_add = can_add self.can_remove = can_remove self.use_global_null_handler = False def _init_cloth(self, *args, **kwargs): super(HtmlFormTable, self)._init_cloth(*args, **kwargs) form = E.form(method='POST', enctype="multipart/form-data") if self._root_cloth is None: self._cloth = self._root_cloth = form else: self._root_cloth.append(form) self._root_cloth = form @coroutine def model_base_to_parent(self, ctx, cls, inst, parent, name, from_arr=False, remove=None, **kwargs): if from_arr: td_attrs = {} if self.field_name_attr: td_attrs[self.field_name_attr] = name with parent.element('tr'): with parent.element('td', attrib=td_attrs): ret = self.prot_form.to_parent(ctx, cls, inst, parent, name, from_arr=from_arr, no_label=True, **kwargs) if isgenerator(ret): try: while True: y = (yield) ret.send(y) except Break as b: try: ret.throw(b) except StopIteration: pass if remove is None: remove = True self.extend_data_row(ctx, cls, inst, parent, name, remove=remove, **kwargs) else: ret = self.prot_form.to_parent(ctx, cls, inst, parent, name, from_arr=from_arr, no_label=True, **kwargs) if isgenerator(ret): try: while True: y = (yield) ret.send(y) except Break as b: try: ret.throw(b) except StopIteration: pass def extend_header_row(self, ctx, cls, parent, name, **kwargs): if self.can_add or self.can_remove: parent.write(E.th()) def extend_data_row(self, ctx, cls, inst, parent, name, array_index=None, add=False, remove=True, **kwargs): if array_index is None: return if not (self.can_remove or self.can_add): return td = E.td(style='white-space: nowrap;') self._gen_buttons(td, name, add, remove) parent.write(td) def _gen_buttons(self, elt, name, add, remove): name = "%s-%d" % (self.selsafe(name), SOME_COUNTER[0]) if add: elt.append( E.button('+', **{ "class": "%s_btn_add" % name, "type": "button", }), ) if remove: elt.append( E.button( '-', **{ "class": "%s_btn_remove" % name, "type": "button", }), ) def extend_table(self, ctx, cls, parent, name, **kwargs): if not self.can_add: return # FIXME: just fix me. if issubclass(cls, Array): cls = next(iter(cls._type_info.values())) self._gen_row(ctx, cls, [cls()], parent, name) # even though there are calls to coroutines here, as the passed objects # are empty, it's not possible to have push data. so there's no need to # check the returned generators. if issubclass(cls, ComplexModelBase): if cls.Attributes.max_occurs > 1: self._gen_row(ctx, cls, [cls()], parent, name, add=True, remove=False, array_index=-1) else: self._gen_row(ctx, cls, cls(), parent, name, add=True, remove=False, array_index=-1) else: if cls.Attributes.max_occurs > 1: self.model_base_to_parent(ctx, cls, None, parent, name, from_arr=True, add=True, remove=False, array_index=-1) else: self.model_base_to_parent(ctx, cls, None, parent, name, add=True, remove=False, array_index=-1) name = '%s-%d' % (self.selsafe(name), SOME_COUNTER[0]) SOME_COUNTER[0] += 1 parent.write(self._format_js(ADD_JS, name=name))
class CardDetailScreen(ScreenBase): main = Card.customize( prot=HtmlForm(), form_action="put_card", child_attrs=dict(id=dict(write=False), ), )
class NewCardScreen(ScreenBase): main = Card.customize( prot=HtmlForm(), form_action="put_card", child_attrs=dict(id=dict(exc=True), ), )
from spyne.const.http import HTTP_302 from spyne.protocol.html.table import HtmlColumnTable from neurons.form import HtmlForm, HrefWidget from a2billing_spyne.model import Extensions from a2billing_spyne.service import ReaderServiceBase, ScreenBase, DalBase EXTENSION_CUST = dict(exten=dict(order=1), priority=dict(order=2), app=dict(order=3), appdata=dict(order=4), context=dict(order=5)) ExtScreen = Extensions.customize( prot=HtmlForm(), form_action="put_ext", child_attrs_all=dict(exc=False, ), child_attrs=dict(id=dict(order=0, write=False), **EXTENSION_CUST), ) class NewExtScreen(ScreenBase): main = ExtScreen class NewExtDetailScreen(ScreenBase): main = ExtScreen def _write_new_ext_link(ctx, cls, inst, parent, name, *kwargs):