def _gen_table(self, ctx, cls, inst, parent, name, gen_rows, **kwargs): logger.debug("Generate table for %r", cls) cls_attrs = self.get_cls_attrs(cls) attrib = {} table_class = oset() if self.table_class is not None: table_class.add(self.table_class) if self.table_name_attr is not None: tn = (self.table_name if self.table_name is not None else cls.get_type_name()) if self.table_name_attr == 'class': table_class.add(tn) else: attrib[self.table_name_attr] = tn attrib['class'] = ' '.join(table_class) if self.table_width is not None: attrib['width'] = self.table_width self.event_manager.fire_event('before_table', ctx, cls, inst, parent, name, prot=self, **kwargs) with parent.element('table', attrib): write_header = self.header if cls_attrs.header is False: write_header = cls_attrs.header if write_header: ret = False subprot = self.get_subprot(ctx, cls_attrs) if subprot is not None: ret = subprot.column_table_gen_header( ctx, cls, parent, name) if not ret: self._gen_thead(ctx, cls, parent, name) with parent.element('tbody'): ret = gen_rows(ctx, cls, inst, parent, name, **kwargs) if isgenerator(ret): try: while True: sv2 = (yield) ret.send(sv2) except Break as b: try: ret.throw(b) except StopIteration: pass self.extend_table(ctx, cls, parent, name, **kwargs)
def __init__(self, parent, transport, type=None): super(HtmlClothProtocolContext, self).__init__(parent, transport, type) self.assets = [] self.eltstack = defaultdict(list) self.ctxstack = defaultdict(list) self.rootstack = oset() self.tags = set()
def _gen_table(self, ctx, cls, inst, parent, name, gen_rows, **kwargs): logger.debug("Generate table for %r", cls) cls_attrs = self.get_cls_attrs(cls) attrib = {} table_class = oset() if self.table_class is not None: table_class.add(self.table_class) if self.table_name_attr is not None: tn = (self.table_name if self.table_name is not None else cls.get_type_name()) if self.table_name_attr == 'class': table_class.add(tn) else: attrib[self.table_name_attr] = tn attrib['class'] = ' '.join(table_class) if self.table_width is not None: attrib['width'] = self.table_width self.event_manager.fire_event('before_table', ctx, cls, inst, parent, name, **kwargs) with parent.element('table', attrib): write_header = self.header if cls_attrs.header is False: write_header = cls_attrs.header if write_header: ret = False subprot = self.get_subprot(ctx, cls_attrs) if subprot is not None: ret = subprot.column_table_gen_header(ctx, cls, parent, name) if not ret: self._gen_thead(ctx, cls, parent, name) with parent.element('tbody'): ret = gen_rows(ctx, cls, inst, parent, name, **kwargs) if isgenerator(ret): try: while True: sv2 = (yield) ret.send(sv2) except Break as b: try: ret.throw(b) except StopIteration: pass self.extend_table(ctx, cls, parent, name, **kwargs)
def fire_event(self, event_name, ctx, *args, **kwargs): """Run all the handlers for a given event name. :param event_name: The event identifier, indicated by the documentation. Usually, this is a string. :param ctx: The method context. Event-related data is conventionally stored in ctx.event attribute. """ handlers = self.handlers.get(event_name, oset()) for handler in handlers: handler(ctx, *args, **kwargs)
def add_listener(self, event_name, handler): """Register a handler for the given event name. :param event_name: The event identifier, indicated by the documentation. Usually, this is a string. :param handler: A static python function that receives a single MethodContext argument. """ handlers = self.handlers.get(event_name, oset()) handlers.add(handler) self.handlers[event_name] = handlers
def fire_event(self, event_name, ctx): """Run all the handlers for a given event name. :param event_name: The event identifier, indicated by the documentation. Usually, this is a string. :param ctx: The method context. Event-related data is conventionally stored in ctx.event attribute. """ handlers = self.handlers.get(event_name, oset()) for handler in handlers: handler(ctx)
def __init__(self, parent, transport, type=None): super(HtmlClothProtocolContext, self).__init__(parent, transport, type) self.assets = [] self.eltstack = defaultdict(list) self.ctxstack = defaultdict(list) self.rootstack = oset() self.tags = set() self.objcache = dict() # this is supposed to be for neurons.base.screen.ScreenBase subclasses self.screen = None self.prev_view = None self.next_view = None
def __init__(self, parent, transport, type=None): super(HtmlClothProtocolContext, self).__init__(parent, transport, type) self.assets = [] self.eltstack = defaultdict(list) self.ctxstack = defaultdict(list) self.rootstack = oset() self.tags = set() self.objcache = dict() # these are supposed to be for neurons.base.screen.ScreenBase subclasses self.screen = None self.prev_view = None self.next_view = None
def __get_base_event_handlers(self, cls_bases): handlers = {} for base in cls_bases: evmgr = getattr(base, 'event_manager', None) if evmgr is None: continue for k, v in evmgr.handlers.items(): handler=handlers.get(k, oset()) for h in v: handler.add(h) handlers[k]=handler return handlers
def __get_base_event_handlers(self, cls_bases): handlers = {} for base in cls_bases: evmgr = getattr(base, 'event_manager', None) if evmgr is None: continue for k, v in evmgr.handlers.items(): handler = handlers.get(k, oset()) for h in v: handler.add(h) handlers[k] = handler return handlers
def _gen_input_attrs_novalue(self, ctx, cls, name, cls_attrs, **kwargs): elt_class = oset([ camel_case_to_uscore(cls.get_type_name()), name.rsplit(self.hier_delim, 1)[-1], re.sub(r'\[[0-9]+\]', '', name).replace(self.hier_delim, '__'), ]) if self.input_class is not None: elt_class.add(self.input_class) elt_class = ' '.join(elt_class) elt_attrs = tdict(six.string_types, six.string_types, { 'id': self._gen_input_elt_id(name, **kwargs), 'name': self._gen_input_name(name), 'type': 'text', 'class': elt_class, }) if cls_attrs.pattern is not None: elt_attrs['pattern'] = cls_attrs.pattern if cls_attrs.read_only: elt_attrs['readonly'] = "" placeholder = cls_attrs.placeholder if placeholder is None: placeholder = self.placeholder if isinstance(placeholder, six.string_types): elt_attrs['placeholder'] = placeholder elif placeholder: elt_attrs['placeholder'] = self.trc(cls, ctx.locale, name) # Required bool means, in HTML context, a checkbox that needs to be # checked, which is not what we mean here at all. if not issubclass(cls, Boolean): # We used OR here because html forms send empty values anyway. So a # missing value is sent as null as well. if cls_attrs.min_occurs >= 1 or cls_attrs.nullable == False: elt_attrs['required'] = '' return elt_attrs
def _gen_table(self, ctx, cls, inst, parent, name, gen_rows, **kwargs): logger.debug("Generate table for %r", cls) attrib = {} table_class = oset() if self.table_class is not None: table_class.add(self.table_class) if self.table_name_attr is not None: tn = (self.table_name if self.table_name is not None else cls.get_type_name()) if self.table_name_attr == 'class': table_class.add(tn) else: attrib[self.table_name_attr] = tn attrib['class'] = ' '.join(table_class) self.event_manager.fire_event('before_table', ctx, cls, inst, parent, name, **kwargs) with parent.element('table', attrib): if self.header: self._gen_thead(ctx, cls, name, parent) with parent.element('tbody'): ret = gen_rows(ctx, cls, inst, parent, name, **kwargs) if isgenerator(ret): try: while True: sv2 = (yield) ret.send(sv2) except Break as b: try: ret.throw(b) except StopIteration: pass self.extend_table(ctx, cls, parent, name, **kwargs)