Example #1
0
def grid(options, id=None):
    if not id:
        id = 'grid_%s' % get_random_string(5)
    script = grid_script % (id, json.dumps(options))
    container = Html('div').attr('rest-grid', 'luxgrids.%s' % id)
    container.append(script)
    return container.render()
Example #2
0
 def _inner_form(self, form, request):
     yield form.is_valid()
     html = Html(None)
     for child in self.children:
         html.append(child(form, request))
     for child in form.inputs:
         html.append(child)
     content = yield html.render(request)
     coroutine_return(content)
Example #3
0
 def _inner_form(self, form, request):
     yield form.is_valid()
     html = Html(None)
     for child in self.children:
         html.append(child(form, request))
     for child in form.inputs:
         html.append(child)
     content = yield html.render(request)
     coroutine_return(content)
Example #4
0
    def inner_html(self, request, page, self_comp=''):
        '''Build page html content using json layout.
        :param layout: json (with rows and components) e.g.
            layout = {
                'rows': [
                    {},
                    {cols: ['col-md-6', 'col-md-6']},
                    {cols: ['col-md-6', 'col-md-6']}
                ],
                'components': [
                    {'type': 'text', 'id': 1, 'row': 0, 'col': 0, 'pos': 0},
                    {'type': 'gallery', 'id': 2, 'row': 1, 'col': 1, 'pos': 0}
                ]
            }
        :return: raw html
            <div class="row">
                <div class="col-md-6">
                    <render-component id="1" text></render-component>
                </div>
                <div class="col-md-6"></div>
            </div>
            <div class="row">
                    <div class="col-md-6"></div>
                    <div class="col-md-6">
                        <render-component id="2" gallery></render-component>
                    </div>
            </div>
        '''
        layout = page.layout
        if layout:
            try:
                layout = json.loads(layout)
            except Exception:
                request.app.logger.exception('Could not parse layout')
                layout = None

        if not layout:
            layout = dict(rows=[{}])

        components = layout.get('components') or []
        if not components:
            components.append(dict(type='self'))

        inner = Html(None)

        # Loop over rows
        for row_idx, row in enumerate(layout.get('rows', ())):
            row = AttributeDictionary(row)
            if row.cols:
                html = self._row(row, components, self_comp)
            else:
                html = self._component(components[0], self_comp)
                html = super().inner_html(request, page, html)

            inner.append(html)

        return inner.render(request)
Example #5
0
    def inner_html(self, request, page, self_comp=''):
        '''Build page html content using json layout.
        :param layout: json (with rows and components) e.g.
            layout = {
                'rows': [
                    {},
                    {cols: ['col-md-6', 'col-md-6']},
                    {cols: ['col-md-6', 'col-md-6']}
                ],
                'components': [
                    {'type': 'text', 'id': 1, 'row': 0, 'col': 0, 'pos': 0},
                    {'type': 'gallery', 'id': 2, 'row': 1, 'col': 1, 'pos': 0}
                ]
            }
        :return: raw html
            <div class="row">
                <div class="col-md-6">
                    <render-component id="1" text></render-component>
                </div>
                <div class="col-md-6"></div>
            </div>
            <div class="row">
                    <div class="col-md-6"></div>
                    <div class="col-md-6">
                        <render-component id="2" gallery></render-component>
                    </div>
            </div>
        '''
        layout = page.layout
        if layout:
            try:
                layout = json.loads(layout)
            except Exception:
                request.app.logger.exception('Could not parse layout')
                layout = None

        if not layout:
            layout = dict(rows=[{}])

        components = layout.get('components') or []
        if not components:
            components.append(dict(type='self'))

        inner = Html(None)

        # Loop over rows
        for row_idx, row in enumerate(layout.get('rows', ())):
            row = AttributeDictionary(row)
            if row.cols:
                html = self._row(row, components, self_comp)
            else:
                html = self._component(components[0], self_comp)
                html = super().inner_html(request, page, html)

            inner.append(html)

        return inner.render(request)
Example #6
0
 def navigation(self, request, routers, levels=None):
     '''Create an ul with links.'''
     levels = levels or self.config['NAVIGATION_LEVELS']
     ul = Html('ul', cn=self.config['NAVIGATION_CLASSES'])
     for _, router in sorted(self._ordered_nav(routers),
                             key=lambda x: x[0]):
         if router.parameters.navigation:
             try:
                 link = router.link()
             except KeyError:
                 continue
             ul.append(link)
     return ul.render(request)
Example #7
0
 def navigation(self, request, routers, levels=None):
     '''Create an ul with links.'''
     levels = levels or self.config['NAVIGATION_LEVELS']
     ul = Html('ul', cn=self.config['NAVIGATION_CLASSES'])
     for _, router in sorted(self._ordered_nav(routers),
                             key=lambda x: x[0]):
         if router.parameters.navigation:
             try:
                 link = router.link()
             except KeyError:
                 continue
             ul.append(link)
     return ul.render(request)