Ejemplo n.º 1
0
Archivo: _base.py Proyecto: pxiol/spyne
    def serialize(self, ctx, message):
        """Uses ``ctx.out_object``, ``ctx.out_header`` or ``ctx.out_error`` to
        set ``ctx.out_body_doc``, ``ctx.out_header_doc`` and
        ``ctx.out_document`` as an ``lxml.etree._Element instance``.

        Not meant to be overridden.
        """

        assert message in (self.REQUEST, self.RESPONSE)

        self.event_manager.fire_event('before_serialize', ctx)

        if ctx.out_stream is None:
            ctx.out_stream = StringIO()

        if ctx.out_error is not None:
            # All errors at this point must be Fault subclasses.
            inst = ctx.out_error
            cls = inst.__class__
            name = cls.get_type_name()

            ctx.out_document = E.div()
            from lxml import etree
            with etree.xmlfile(ctx.out_stream) as xf:
                retval = HtmlBase.HtmlMicroFormat() \
                                            .to_parent(ctx, cls, inst, xf, name)

        else:
            assert message is self.RESPONSE
            result_message_class = ctx.descriptor.out_message

            name = result_message_class.get_type_name()
            if ctx.descriptor.body_style == BODY_STYLE_WRAPPED:
                if self.ignore_wrappers:
                    ctx.out_object = ctx.out_object[0]
                    result_message = ctx.out_object
                    while result_message_class.Attributes._wrapper:
                        result_message_class = next(
                            iter(result_message_class._type_info.values()))

                else:
                    result_message = result_message_class()

                    for i, attr_name in enumerate(
                            result_message_class._type_info.keys()):
                        setattr(result_message, attr_name, ctx.out_object[i])

            else:
                result_message = ctx.out_object

            retval = self.incgen(ctx, result_message_class, result_message,
                                 name)

        self.event_manager.fire_event('after_serialize', ctx)

        return retval
Ejemplo n.º 2
0
Archivo: html.py Proyecto: chfoo/wuff
    def _build_html_header(self):
        '''Add banner and account links'''
        header = self.elements.header
        index_url = self.links.get(
            'index', self.handler.reverse_url('index'))

        header.append(E.div(
            E.a(self.meta.app_name, href=index_url, id='logo-link'),
            id='logo-wrapper'
        ))
Ejemplo n.º 3
0
    def serialize(self, ctx, message):
        """Uses ``ctx.out_object``, ``ctx.out_header`` or ``ctx.out_error`` to
        set ``ctx.out_body_doc``, ``ctx.out_header_doc`` and
        ``ctx.out_document`` as an ``lxml.etree._Element instance``.

        Not meant to be overridden.
        """

        assert message in (self.REQUEST, self.RESPONSE)

        self.event_manager.fire_event('before_serialize', ctx)

        if ctx.out_stream is None:
            ctx.out_stream = StringIO()

        if ctx.out_error is not None:
            # All errors at this point must be Fault subclasses.
            inst = ctx.out_error
            cls = inst.__class__
            name = cls.get_type_name()

            ctx.out_document = E.div()
            from lxml import etree
            with etree.xmlfile(ctx.out_stream) as xf:
                retval = HtmlBase.HtmlMicroFormat() \
                                            .to_parent(ctx, cls, inst, xf, name)

        else:
            assert message is self.RESPONSE
            result_message_class = ctx.descriptor.out_message

            name = result_message_class.get_type_name()
            if ctx.descriptor.body_style == BODY_STYLE_WRAPPED:
                if self.ignore_wrappers:
                    ctx.out_object = ctx.out_object[0]
                    result_message = ctx.out_object
                    while result_message_class.Attributes._wrapper:
                        result_message_class = next(iter(
                                      result_message_class._type_info.values()))

                else:
                    result_message = result_message_class()

                    for i, attr_name in enumerate(
                                        result_message_class._type_info.keys()):
                        setattr(result_message, attr_name, ctx.out_object[i])

            else:
                result_message = ctx.out_object

            retval = self.incgen(ctx, result_message_class, result_message, name)

        self.event_manager.fire_event('after_serialize', ctx)

        return retval
Ejemplo n.º 4
0
Archivo: base.py Proyecto: chfoo/wuff
    def add_field(self, field):
        translate = self._handler.locale.translate
        wrapper = E.div()

        if field.label:
            wrapper.append(E.label(translate(field.label.text), FOR(field.id)))

        wrapper.append(lxml.html.fromstring(field()))

        if field.errors:
            error_wrapper = E.ul()
            wrapper.append(error_wrapper)

            for error in field.errors:
                error_wrapper.append(E.li(E.strong(str(error))))

        self._element.append(wrapper)
Ejemplo n.º 5
0
Archivo: html.py Proyecto: chfoo/wuff
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        footer = E.footer(role='contentinfo', id='layout-footer')
        content = E.main(role='main', id='layout-content')
        header = E.header(role='banner', id='layout-header')
        layout = E.div(header, content, footer, id='layout-wrapper')
        body = E.body(layout)
        head = E.head(prefix='og: http://ogp.me/ns#')
        html = E.html(head, body, dir='rtl' if self.locale.rtl else 'ltr')

        self.elements = Elements(html=html, head=head, body=body,
            layout=layout, header=header, content=content, footer=footer)
        self.meta = HTMLMeta()
        self.links = HTMLLinks()

        self.stylesheets = []
        self.scripts = []

        self.meta.app_name = self.handler.application.settings[
            'application_name']
Ejemplo n.º 6
0
 def index(self):
     return E.div(
         E.p(E.a("Cards", href="/get_all_card")),
         E.p(E.a("Sip Buddies", href="/get_all_sip_buddy")),
         E.p(E.a("Extensions", href="/get_all_extension")),
     )