Exemplo n.º 1
0
    def build_title_content(self):
        content = E.table(
            E.tr(
                E.th(self.T('Time')),
                E.th(self.T('Message')),
                E.th(self.T('Count'))
            )
        )

        for message in self._messages:
            message_dict = dict(message.data_iter)

            row = E.tr(
                E.td(self.handler.locale.format_date(message.datetime),
                    rowspan=str(len(message_dict)))
            )

            for key, count in sorted(message_dict.items()):
                row.extend([E.td(to_hex(key)), E.td(str(count))])
                content.append(row)
                row = E.tr()

        self.elements.content.append(content)

        if self._pager_next:
            self.elements.content.append(
                E.a(self.T('Older'), href='?before=' + str(self._pager_next))
            )

        self.add_footer()
Exemplo n.º 2
0
    def serialize_complex_model(self, cls, value):
        sti = None
        fti = cls.get_flat_type_info(cls)

        first_child = iter(fti.values()).next()
        if len(fti) == 1:
            fti = first_child.get_flat_type_info(first_child)
            first_child = iter(fti.values()).next()
            if len(fti) == 1 and first_child.Attributes.max_occurs > 1:
                if issubclass(first_child, ComplexModelBase):
                    sti = first_child.get_simple_type_info(first_child)
                value = value[0]
            else:
                raise Exception("Can only serialize Array(...) types")
        else:
            raise Exception("Can only serialize single Array(...) return types")

        header_row = E.tr()
        class_name = first_child.get_type_name()
        if sti is None:
            header_row.append(E.th(class_name))
        else:
            if self.field_name_attr is None:
                for k, v in sti.items():
                    header_row.append(E.th(k))
            else:
                for k, v in sti.items():
                    header_row.append(E.th(k,
                                        **{self.field_name_attr: k}))

        yield header_row

        if sti is None:
            if self.field_name_attr is None:
                for val in value:
                    yield E.tr(E.td(first_child.to_string(val)), )
            else:
                for val in value:
                    yield E.tr(E.td(first_child.to_string(val)),
                                           **{self.field_name_attr: class_name})

        else:
            for val in value:
                row = E.tr()
                print val
                for k, v in sti.items():
                    subvalue = val
                    for p in v.path:
                        subvalue = getattr(subvalue, p, "`%s`" % k)
                    if self.field_name_attr is None:
                        row.append(E.td(v.type.to_string(subvalue)))
                    else:
                        row.append(E.td(v.type.to_string(subvalue),
                                                   **{self.field_name_attr: k}))
                yield row
Exemplo n.º 3
0
 def model_base_to_parent(self, ctx, cls, inst, parent, name,  tr_child=False, **kwargs):
     attrs = {}
     if self.field_name_attr is not None:
         attrs = {self.field_name_attr: name}
     retval = E.td(self.to_string(cls, inst), **attrs)
     if not tr_child:
         retval = E.tr(retval)
     parent.write(retval)
Exemplo n.º 4
0
    def model_base_to_parent(self, ctx, cls, inst, parent, name, from_arr=False, **kwargs):
        if from_arr:
            td_attrib = {}
            if False and self.field_name_attr:
                td_attrib[self.field_name_attr] = name

            parent.write(E.tr(E.td(self.to_unicode(cls, inst), **td_attrib)))
        else:
            parent.write(self.to_unicode(cls, inst))
Exemplo n.º 5
0
    def model_base_to_parent(self, ctx, cls, inst, parent, name, from_arr=False, **kwargs):
        if from_arr:
            td_attrib = {}
            if False and self.field_name_attr:
                td_attrib[self.field_name_attr] = name

            parent.write(E.tr(E.td(self.to_unicode(cls, inst), **td_attrib)))
        else:
            parent.write(self.to_unicode(cls, inst))
Exemplo n.º 6
0
    def model_base_to_parent(self, ctx, cls, inst, parent, name, **kwargs):
        retval = E.tr()
        attr = {}
        if self.field_name_attr is not None:
            attr = {self.field_name_attr: name}

        if self.produce_header:
            retval.append(E.th(self.translate(cls, ctx.locale, name), **attr))

        retval.append(E.td(self.to_string(cls, inst), **attr))
        parent.write(retval)
Exemplo n.º 7
0
    def model_base_to_parent(self, ctx, cls, inst, parent, name, **kwargs):
        retval = E.tr()
        attr = {}
        if self.field_name_attr is not None:
            attr = {self.field_name_attr: name}

        if self.produce_header:
            retval.append(E.th(self.translate(cls, ctx.locale, name), **attr))

        retval.append(E.td(self.to_string(cls, inst), **attr))
        parent.write(retval)
Exemplo n.º 8
0
 def model_base_to_parent(self,
                          ctx,
                          cls,
                          inst,
                          parent,
                          name,
                          tr_child=False,
                          **kwargs):
     attrs = {}
     if self.field_name_attr is not None:
         attrs = {self.field_name_attr: name}
     retval = E.td(self.to_string(cls, inst), **attrs)
     if not tr_child:
         retval = E.tr(retval)
     parent.write(retval)
Exemplo n.º 9
0
    def model_base_to_parent(self, ctx, cls, inst, parent, name,
                                                      from_arr=False, **kwargs):
        if from_arr:
            td_attrs = {}
            #if self.field_name_attr:
            #    td_attrs[self.field_name_attr] = name
            parent.write(E.tr(
                E.td(
                    self.to_string(cls, inst),
                    **td_attrs
                )
            ))

        else:
            parent.write(self.to_string(cls, inst))
Exemplo n.º 10
0
    def model_base_to_parent(self, ctx, cls, inst, parent, name,
                                                      from_arr=False, **kwargs):
        inst_str = ''
        if inst is not None:
            inst_str = self.to_unicode(cls, inst)

        if from_arr:
            td_attrs = {}

            self.add_field_attrs(td_attrs, name, cls)

            parent.write(E.tr(E.td(inst_str, **td_attrs)))

        else:
            parent.write(inst_str)
Exemplo n.º 11
0
    def model_base_to_parent(self, ctx, cls, inst, parent, name,
                                                      from_arr=False, **kwargs):
        inst_str = ''
        if inst is not None:
            inst_str = self.to_unicode(cls, inst)

        if from_arr:
            td_attrs = {}

            self.add_field_attrs(td_attrs, name, cls)

            parent.write(E.tr(E.td(inst_str, **td_attrs)))

        else:
            parent.write(inst_str)
Exemplo n.º 12
0
    def model_base_to_parent(self,
                             ctx,
                             cls,
                             inst,
                             parent,
                             name,
                             from_arr=False,
                             **kwargs):
        if from_arr:
            td_attrs = {}
            #if self.field_name_attr:
            #    td_attrs[self.field_name_attr] = name
            parent.write(E.tr(E.td(self.to_string(cls, inst), **td_attrs)))

        else:
            parent.write(self.to_string(cls, inst))
Exemplo n.º 13
0
    def serialize_complex_model(self, cls, value, locale):
        sti = None
        fti = cls.get_flat_type_info(cls)

        first_child = iter(fti.values()).next()
        if len(fti) == 1:
            fti = first_child.get_flat_type_info(first_child)
            first_child = iter(fti.values()).next()

            if len(fti) == 1 and first_child.Attributes.max_occurs > 1:
                if issubclass(first_child, ComplexModelBase):
                    sti = first_child.get_simple_type_info(first_child)

            else:
                raise NotImplementedError("Can only serialize Array(...) types")

            value = value[0]

        else:
            raise NotImplementedError("Can only serialize single Array(...) "
                                                                 "return types")

        # Here, sti can be None when the return type does not have _type_info
        # attribute
        tr = {}
        if self.row_class is not None:
            tr['class'] = self.row_class

        td = {}
        if self.cell_class is not None:
            td['class'] = self.cell_class

        class_name = first_child.get_type_name()
        if self.produce_header:
            header_row = E.tr(**tr)

            th = {}
            if self.header_cell_class is not None:
                th['class'] = self.header_cell_class

            if sti is None:
                header_row.append(E.th(class_name, **th))

            else:
                if self.field_name_attr is None:
                    for k, v in sti.items():
                        header_name = translate(v.type, locale, k)
                        header_row.append(E.th(header_name, **th))

                else:
                    for k, v in sti.items():
                        th[self.field_name_attr] = k
                        header_name = translate(v.type, locale, k)
                        header_row.append(E.th(header_name, **th))

            yield header_row

        if sti is None:
            if self.field_name_attr is None:
                for val in value:
                    yield E.tr(E.td(first_child.to_string(val), **td), **tr)

            else:
                for val in value:
                    td[self.field_name_attr] = class_name
                    yield E.tr(E.td(first_child.to_string(val), **td), **tr)

        else:
            for val in value:
                row = E.tr()
                for k, v in sti.items():
                    subvalue = val
                    for p in v.path:
                        subvalue = getattr(subvalue, p, None)

                    if subvalue is None:
                        if v.type.Attributes.min_occurs == 0:
                            continue
                        else:
                            subvalue = ""
                    else:
                        subvalue = _subvalue_to_html(v, subvalue)

                    if self.field_name_attr is None:
                        row.append(E.td(subvalue, **td))
                    else:
                        td[self.field_name_attr] = k
                        row.append(E.td(subvalue, **td))

                yield row
Exemplo n.º 14
0
    def serialize_complex_model(self, cls, value, locale):
        sti = None
        fti = cls.get_flat_type_info(cls)
        is_array = False

        if len(fti) == 1:
            first_child, = fti.values()

            try:
                fti = first_child.get_flat_type_info(first_child)
            except AttributeError:
                raise NotImplementedError("Can only serialize complex return types")

            first_child_2 = iter(fti.values()).next()

            if len(fti) == 1 and first_child_2.Attributes.max_occurs > 1:
                if issubclass(first_child_2, ComplexModelBase):
                    sti = first_child_2.get_simple_type_info(first_child_2)
                is_array = True

            else:
                if issubclass(first_child, ComplexModelBase):
                    sti = first_child.get_simple_type_info(first_child)

            value = value[0]

        else:
            raise NotImplementedError("Can only serialize single return types")

        tr = {}
        if self.row_class is not None:
            tr['class'] = self.row_class

        td = {}
        if self.cell_class is not None:
            td['class'] = self.cell_class

        th = {}
        if self.header_cell_class is not None:
            th['class'] = self.header_cell_class

        class_name = first_child.get_type_name()
        if sti is None:
            if self.field_name_attr is not None:
                td[self.field_name_attr] = class_name

            if is_array:
                for val in value:
                    yield E.tr(E.td(first_child_2.to_string(val), **td), **tr)
            else:
                yield E.tr(E.td(first_child_2.to_string(value), **td), **tr)

        else:
            for k, v in sti.items():
                row = E.tr(**tr)
                subvalue = value
                for p in v.path:
                    subvalue = getattr(subvalue, p, None)
                    if subvalue is None:
                        break

                if subvalue is None:
                    if v.type.Attributes.min_occurs == 0:
                        continue
                    else:
                        subvalue = ""
                else:
                    subvalue = _subvalue_to_html(v, subvalue)

                if self.produce_header:
                    header_text = translate(v.type, locale, k)
                    if self.field_name_attr is None:
                        row.append(E.th(header_text, **th))
                    else:
                        th[self.field_name_attr] = k
                        row.append(E.th(header_text, **th))

                if self.field_name_attr is None:
                    row.append(E.td(subvalue, **td))

                else:
                    td[self.field_name_attr] = k
                    row.append(E.td(subvalue, **td))

                yield row
Exemplo n.º 15
0
    def subserialize(self, ctx, cls, inst, parent, ns=None, name=None):
        attrs = {}
        if self.table_name_attr is not None:
            attrs[self.table_name_attr] = name

        locale = ctx.locale
        with parent.element('table', attrs):
            fti = None
            if issubclass(cls, ComplexModelBase):
                fti = cls.get_flat_type_info(cls)
            if self.produce_header:
                with parent.element('thead'):
                    header_row = E.tr()

                    th = {}
                    if self.header_cell_class is not None:
                        th['class'] = self.header_cell_class

                    # fti is none when the type inside Array is not a ComplexModel.
                    if fti is None:
                        if self.field_name_attr is not None:
                            th[self.field_name_attr] = name
                        header_name = self.translate(cls, ctx.locale, name)
                        header_row.append(E.th(header_name, **th))

                    else:
                        if self.field_name_attr is None:
                            for k, v in fti.items():
                                header_name = self.translate(v, ctx.locale, k)
                                header_row.append(E.th(header_name, **th))

                        else:
                            for k, v in fti.items():
                                th[self.field_name_attr] = k
                                header_name = self.translate(v, ctx.locale, k)
                                header_row.append(E.th(header_name, **th))

                    parent.write(header_row)

            with parent.element('tbody'):
                if cls.Attributes.max_occurs > 1:
                    ret = self.array_to_parent(ctx, cls, inst, parent, name)
                    if isgenerator(ret):
                        try:
                            while True:
                                y = (yield)
                                ret.send(y)
                        except Break as b:
                            try:
                                ret.throw(b)
                            except StopIteration:
                                pass

                else:
                    with parent.element('tr'):
                        ret = self.to_parent(ctx, cls, inst, parent, name)
                        if isgenerator(ret):
                            try:
                                while True:
                                    y = (yield)
                                    ret.send(y)
                            except Break as b:
                                try:
                                    ret.throw(b)
                                except StopIteration:
                                    pass
Exemplo n.º 16
0
    def serialize_complex_model(self, cls, value, locale):
        fti = cls.get_flat_type_info(cls)
        if cls.Attributes._wrapper and not issubclass(cls, Array):
            if len(fti) > 1:
                raise NotImplementedError("Can only serialize one array at a time")
            cls, = cls._type_info.values()
            value, = value

        fti = cls.get_flat_type_info(cls)
        first_child = iter(fti.values()).next()
        if not issubclass(cls, Array):
            raise NotImplementedError("Can only serialize Array(...) types")

        sti = None
        if issubclass(first_child, ComplexModelBase):
            sti = first_child.get_simple_type_info(first_child)

        # Here, sti can be None when the return type does not have _type_info
        # attribute
        tr = {}
        if self.row_class is not None:
            tr['class'] = self.row_class

        td = {}
        if self.cell_class is not None:
            td['class'] = self.cell_class

        class_name = first_child.get_type_name()
        if self.produce_header:
            header_row = E.tr(**tr)

            th = {}
            if self.header_cell_class is not None:
                th['class'] = self.header_cell_class

            # sti is none when the type inside Array is not a ComplexModel.
            if sti is None:
                header_row.append(E.th(class_name, **th))

            else:
                if self.field_name_attr is None:
                    for k, v in sti.items():
                        header_name = translate(v.type, locale, k)
                        header_row.append(E.th(header_name, **th))

                else:
                    for k, v in sti.items():
                        th[self.field_name_attr] = k
                        header_name = translate(v.type, locale, k)
                        header_row.append(E.th(header_name, **th))

            yield header_row

        if value is None:
            raise StopIteration()

        if sti is None:
            if self.field_name_attr is None:
                for val in value:
                    yield E.tr(E.td(self.to_string(first_child, val),**td),**tr)

            else:
                for val in value:
                    td[self.field_name_attr] = class_name
                    yield E.tr(E.td(self.to_string(first_child, val),**td),**tr)

        else:
            for val in value:
                row = E.tr()
                for k, v in sti.items():
                    subvalue = val
                    for p in v.path:
                        subvalue = getattr(subvalue, p, None)

                    if subvalue is None:
                        subvalue = ""
                    else:
                        subvalue = _subvalue_to_html(self, v, subvalue)

                    if self.field_name_attr is None:
                        row.append(E.td(subvalue, **td))
                    else:
                        td[self.field_name_attr] = k
                        row.append(E.td(subvalue, **td))

                yield row
Exemplo n.º 17
0
    def serialize_complex_model(self, cls, value, locale):
        sti = None
        fti = cls.get_flat_type_info(cls)
        is_array = False

        if len(fti) == 1:
            first_child, = fti.values()

            try:
                fti = first_child.get_flat_type_info(first_child)
            except AttributeError:
                raise NotImplementedError(
                    "Can only serialize complex return types")

            first_child_2 = iter(fti.values()).next()

            if len(fti) == 1 and first_child_2.Attributes.max_occurs > 1:
                if issubclass(first_child_2, ComplexModelBase):
                    sti = first_child_2.get_simple_type_info(first_child_2)
                is_array = True

            else:
                if issubclass(first_child, ComplexModelBase):
                    sti = first_child.get_simple_type_info(first_child)

            value = value[0]

        else:
            raise NotImplementedError("Can only serialize single return types")

        tr = {}
        if self.row_class is not None:
            tr['class'] = self.row_class

        td = {}
        if self.cell_class is not None:
            td['class'] = self.cell_class

        th = {}
        if self.header_cell_class is not None:
            th['class'] = self.header_cell_class

        class_name = first_child.get_type_name()
        if sti is None:
            if self.field_name_attr is not None:
                td[self.field_name_attr] = class_name

            if is_array:
                for val in value:
                    yield E.tr(E.td(first_child_2.to_string(val), **td), **tr)
            else:
                yield E.tr(E.td(first_child_2.to_string(value), **td), **tr)

        else:
            for k, v in sti.items():
                row = E.tr(**tr)
                subvalue = value
                for p in v.path:
                    subvalue = getattr(subvalue, p, None)
                    if subvalue is None:
                        break

                if subvalue is None:
                    if v.type.Attributes.min_occurs == 0:
                        continue
                    else:
                        subvalue = ""
                else:
                    subvalue = _subvalue_to_html(v, subvalue)

                if self.produce_header:
                    header_text = translate(v.type, locale, k)
                    if self.field_name_attr is None:
                        row.append(E.th(header_text, **th))
                    else:
                        th[self.field_name_attr] = k
                        row.append(E.th(header_text, **th))

                if self.field_name_attr is None:
                    row.append(E.td(subvalue, **td))

                else:
                    td[self.field_name_attr] = k
                    row.append(E.td(subvalue, **td))

                yield row
Exemplo n.º 18
0
    def serialize_complex_model(self, cls, value, locale):
        sti = None
        fti = cls.get_flat_type_info(cls)

        first_child = iter(fti.values()).next()
        if len(fti) == 1:
            fti = first_child.get_flat_type_info(first_child)
            first_child = iter(fti.values()).next()

            if len(fti) == 1 and first_child.Attributes.max_occurs > 1:
                if issubclass(first_child, ComplexModelBase):
                    sti = first_child.get_simple_type_info(first_child)

            else:
                raise NotImplementedError(
                    "Can only serialize Array(...) types")

            value = value[0]

        else:
            raise NotImplementedError("Can only serialize single Array(...) "
                                      "return types")

        # Here, sti can be None when the return type does not have _type_info
        # attribute
        tr = {}
        if self.row_class is not None:
            tr['class'] = self.row_class

        td = {}
        if self.cell_class is not None:
            td['class'] = self.cell_class

        class_name = first_child.get_type_name()
        if self.produce_header:
            header_row = E.tr(**tr)

            th = {}
            if self.header_cell_class is not None:
                th['class'] = self.header_cell_class

            if sti is None:
                header_row.append(E.th(class_name, **th))

            else:
                if self.field_name_attr is None:
                    for k, v in sti.items():
                        header_name = translate(v.type, locale, k)
                        header_row.append(E.th(header_name, **th))

                else:
                    for k, v in sti.items():
                        th[self.field_name_attr] = k
                        header_name = translate(v.type, locale, k)
                        header_row.append(E.th(header_name, **th))

            yield header_row

        if sti is None:
            if self.field_name_attr is None:
                for val in value:
                    yield E.tr(E.td(first_child.to_string(val), **td), **tr)

            else:
                for val in value:
                    td[self.field_name_attr] = class_name
                    yield E.tr(E.td(first_child.to_string(val), **td), **tr)

        else:
            for val in value:
                row = E.tr()
                for k, v in sti.items():
                    subvalue = val
                    for p in v.path:
                        subvalue = getattr(subvalue, p, None)

                    if subvalue is None:
                        if v.type.Attributes.min_occurs == 0:
                            continue
                        else:
                            subvalue = ""
                    else:
                        subvalue = _subvalue_to_html(v, subvalue)

                    if self.field_name_attr is None:
                        row.append(E.td(subvalue, **td))
                    else:
                        td[self.field_name_attr] = k
                        row.append(E.td(subvalue, **td))

                yield row
Exemplo n.º 19
0
    def subserialize(self, ctx, cls, inst, parent, ns=None, name=None):
        attrs = {}
        if self.table_name_attr is not None:
            attrs[self.table_name_attr] = name

        locale = ctx.locale
        with parent.element('table', attrs):
            fti = None
            if issubclass(cls, ComplexModelBase):
                fti = cls.get_flat_type_info(cls)
            if self.produce_header:
                with parent.element('thead'):
                    header_row = E.tr()

                    th = {}
                    if self.header_cell_class is not None:
                        th['class'] = self.header_cell_class

                    # fti is none when the type inside Array is not a ComplexModel.
                    if fti is None:
                        if self.field_name_attr is not None:
                            th[self.field_name_attr] = name
                        header_name = self.translate(cls, ctx.locale, name)
                        header_row.append(E.th(header_name, **th))

                    else:
                        if self.field_name_attr is None:
                            for k, v in fti.items():
                                header_name = self.translate(v, ctx.locale, k)
                                header_row.append(E.th(header_name, **th))

                        else:
                            for k, v in fti.items():
                                th[self.field_name_attr] = k
                                header_name = self.translate(v, ctx.locale, k)
                                header_row.append(E.th(header_name, **th))

                    parent.write(header_row)

            with parent.element('tbody'):
                if cls.Attributes.max_occurs > 1:
                    ret = self.array_to_parent(ctx, cls, inst, parent, name)
                    if isgenerator(ret):
                        try:
                            while True:
                                y = (yield)
                                ret.send(y)
                        except Break as b:
                            try:
                                ret.throw(b)
                            except StopIteration:
                                pass

                else:
                    with parent.element('tr'):
                        ret = self.to_parent(ctx, cls, inst, parent, name)
                        if isgenerator(ret):
                            try:
                                while True:
                                    y = (yield)
                                    ret.send(y)
                            except Break as b:
                                try:
                                    ret.throw(b)
                                except StopIteration:
                                    pass