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 __call__(self, html, fields, context):
     html.data('fields', len(fields))
     for name, value in iteritems(fields):
         if is_string(value):
             html.append(Html('div', value, field=name))
         else:
             html.append(Html('div', field=name, value=value))
Example #3
0
 def fieldset(self, html, bfield, container):
     type = html.attr('type')
     if type in special_types:
         yield Html('div', Html('label', html, bfield.label), cn=type)
     else:
         yield Html('div',
                    '<label>%s</label>' % bfield.label,
                    html.addClass(control_class),
                    cn=control_group)
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 html_login_link(self, request):
     img = Html('img',
                src=('https://images-na.ssl-images-amazon.com/images'
                     '/G/01/lwa/btnLWA_gold_156x32.png'),
                width=156,
                height=32,
                alt='Login with Amazon')
     href = self.web_oauth(request)
     return Html('a', img, href=href)
Example #6
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 #7
0
 def get(self, request):
     user = request.cache.session.user
     if user.is_authenticated():
         yield smart_redirect(request)
     html = Html("div")
     for api in apis.available(request.app.config):
         a = api.html_login_link(request)
         html.append(a)
     response = yield html.http_response(request)
     coroutine_return(response)
Example #8
0
 def fieldset(self, html, bfield, container):
     control = Html('div', cn='control-group')
     if html.attr('type') == 'checkbox':
         control.append(Html('label', html, bfield.label, cn='checkbox'))
     else:
         label = Html('label', bfield.label, cn='control-label')
         label.attr('for', bfield.id)
         control.append(label)
         control.append(Html('div', html, cn='controls'))
     yield control
Example #9
0
 def get(self, request):
     user = request.cache.session.user
     if user.is_authenticated():
         yield smart_redirect(request)
     html = Html('div')
     for api in apis.available(request.app.config):
         a = api.html_login_link(request)
         html.append(a)
     response = yield html.http_response(request)
     coroutine_return(response)
Example #10
0
 def __call__(self, form, request):
     handler = LAYOUT_HANDLERS.get(self.style, LAYOUT_HANDLERS[''])
     render = getattr(handler, self.name, handler.default)
     html = Html(self.tag)
     if self.legend:
         html.append('<legend>%s</legend>' % self.legend)
     for child in self.children:
         for txt in child(form, request, render):
             html.append(txt)
     return html
Example #11
0
 def as_form(self, ng_controller=None, **attrs):
     data = self.as_dict(**attrs)
     form = data['field']
     directive = form.pop('directive', 'lux-form')
     id = form['id']
     script = form_script % (id, json.dumps(data))
     html = Html(directive, script).data('options', 'luxforms.%s' % id)
     ng_controller = ng_controller or form.pop('ng_controller', None)
     # add controller if required
     if ng_controller:
         html.data('ng-controller', ng_controller)
     return html
Example #12
0
 def __call__(self, form, request=None, tag='form', cn=None, method='post',
              enctype=None, **params):
     enctype = enctype or 'multipart/form-data'
     if request:
         cn = cn or 'ajax'
         request.html_document.head.scripts.require('jquery-form')
     # we need to make sure the form is validated
     html = Html(tag, cn=cn, method=method, enctype=enctype, **params)
     if self.style:
         html.addClass('form-%s' % self.style)
     html.append(self._inner_form(form, request))
     return html
Example #13
0
 def as_form(self, ng_controller=None, **attrs):
     data = self.as_dict(**attrs)
     form = data['field']
     directive = form.pop('directive', 'lux-form')
     id = form['id']
     script = form_script % (id, json.dumps(data))
     html = Html(directive, script).data('options', 'luxforms.%s' % id)
     ng_controller = ng_controller or form.pop('ng_controller', None)
     # add controller if required
     if ng_controller:
         html.data('ng-controller', ng_controller)
     return html
Example #14
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 #15
0
 def html(self, request, context, children, **parameters):
     if request:
         info = request.cache.html_navigation
         if info is None:
             LOGGER.warning('To use the navigation you must include '
                            'lux.extensions.sitemap in your EXTENSIONS '
                            'list')
         else:
             info.load(request)
             nav = Html(None)
             if self.parameters.layout == 'horizontal':
                 nav.addClass('inner clearfix')
             return self.layout(request, info, nav)
Example #16
0
 def html(self, request, context, children, **parameters):
     if request:
         info = request.cache.html_navigation
         if info is None:
             LOGGER.warning('To use the navigation you must include '
                            'lux.extensions.sitemap in your EXTENSIONS '
                            'list')
         else:
             info.load(request)
             nav = Html(None)
             if self.parameters.layout == 'horizontal':
                 nav.addClass('inner clearfix')
             return self.layout(request, info, nav)
Example #17
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 #18
0
 def __call__(self, html, fields, context):
     html.data('fields', 0)
     data = {
         'col-headers': fields.get('fields'),
         'ajax-url': fields.get('url')
     }
     html.append(Html('div', cn='datagrid', data=data))
Example #19
0
 def apply_content(self, elem, content):
     elem.data({'id': content.id, 'content_type': content.content_type})
     for name, value in chain(
         (('title', content.title), ('keywords', content.keywords)),
             iteritems(content.data)):
         if not is_string(value):
             elem.data(name, value)
         elif value:
             elem.append(Html('div', value, field=name))
Example #20
0
    def item(self, url, text=None, icon=None, title=None, **kw):
        '''Create a :class:`.Link` object
        '''
        title = title or text
        return Html('a', text, href=url, icon=icon, title=title, **kw)
        if text and icon:
            text = ' %s' % text

        return Link(href=url, icon=icon, children=(text, ), title=title, **kw)
Example #21
0
    def _row(self, row, components, self_comp):
        fluid = '-fluid' if row.fluid else ''
        container = Html('div', cn='container%s' % fluid)
        htmlRow = Html('div', cn='row')
        container.append(htmlRow)

        for col_idx, col in enumerate(row.cols):
            htmlCol = Html('div', cn=col)
            htmlRow.append(htmlCol)

            for comp in sorted(components, key=lambda c: c.get('pos', 0)):
                html = self._component(comp, self_comp)
                htmlCol.append(Html('div', html, cn='block'))

        return container
Example #22
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 #23
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 #24
0
 def __call__(self, form, request):
     handler = LAYOUT_HANDLERS.get(self.style, LAYOUT_HANDLERS[''])
     render = getattr(handler, self.name, handler.default)
     html = Html(self.tag)
     if self.legend:
         html.append('<legend>%s</legend>' % self.legend)
     for child in self.children:
         for txt in child(form, request, render):
             html.append(txt)
     return html
Example #25
0
 def read(self, request):
     '''Handle the html view of a page in editing mode.
     '''
     page = yield self.get_page(request, **request.urlargs)
     if not page:
         raise Http404
     # We have permissions
     if request.has_permission('update', page):
         this_url = page.path(**request.url_data)
         form = self.form_factory(request=request,
                                  instance=page,
                                  manager=self.manager)
         #
         # Add document information
         doc = request.html_document
         doc.body.addClass(page.body_class)
         edit = form.layout(request, action=request.full_path())
         template = self.page_template(request, page)
         html_page = yield template(request)
         #
         doc.body.append(Html('div', edit, cn='cms-control'))
         #
         doc.data({
             'this_url': this_url,
             'content_urls': self.content_urls(request)
         })
         #
         scheme = 'ws'
         if request.is_secure:
             scheme = 'wss'
         ws = request.absolute_uri('updates', scheme=scheme)
         html_page.data({'editing': page.id, 'backend_url': ws})
         doc.body.append(html_page)
         #
         # Url for api, to add datatable content and retrieve content
         url = request.app.config.get('API_URL')
         if url:
             html_page.data(
                 {'content_url': '%s%s' % (url, CONTENT_API_URL)})
         # Add codemirror css
         doc.head.links.append('codemirror')
         response = yield doc.http_response(request)
         coroutine_return(response)
     else:
         raise PermissionDenied
Example #26
0
 def __call__(self,
              form,
              request=None,
              tag='form',
              cn=None,
              method='post',
              enctype=None,
              **params):
     enctype = enctype or 'multipart/form-data'
     if request:
         cn = cn or 'ajax'
         request.html_document.head.scripts.require('jquery-form')
     # we need to make sure the form is validated
     html = Html(tag, cn=cn, method=method, enctype=enctype, **params)
     if self.style:
         html.addClass('form-%s' % self.style)
     html.append(self._inner_form(form, request))
     return html
Example #27
0
 def user(self, request, data):
     ul = Html('ul', cn='nav user')
     for link in data:
         ul.append(link)
     return ul
Example #28
0
 def html(self, bfield, **params):
     html = Html('select')
     if self.multiple:
         html.attr('multiple', 'multiple')
     self.choices.add_options(bfield, html)
     return html
Example #29
0
 def user(self, request, data):
     ul = Html('ul', cn='nav user')
     for link in data:
         ul.append(link)
     return ul
Example #30
0
 def secondary(self, request, data):
     ul = Html('ul', cn='nav secondary')
     for link in data:
         ul.append(link)
     return ul
Example #31
0
 def main(self, request, data):
     ul = Html('ul', cn='nav')
     for link in data:
         ul.append(link)
     return ul
Example #32
0
 def html_login_link(self, request):
     href = self.web_oauth(request)
     return Html('a',
                 "<i class='icon-github-alt'> Sign in with github</i>",
                 cn='btn',
                 href=href)
Example #33
0
 def fieldset(self, html, bfield, container):
     control = Html('div', cn='control-group')
     if html.attr('type') == 'checkbox':
         control.append(Html('label', html, bfield.label, cn='checkbox'))
     else:
         label = Html('label', bfield.label, cn='control-label')
         label.attr('for', bfield.id)
         control.append(label)
         control.append(Html('div', html, cn='controls'))
     yield control
Example #34
0
    def _row(self, row, components, self_comp):
        fluid = '-fluid' if row.fluid else ''
        container = Html('div', cn='container%s' % fluid)
        htmlRow = Html('div', cn='row')
        container.append(htmlRow)

        for col_idx, col in enumerate(row.cols):
            htmlCol = Html('div', cn=col)
            htmlRow.append(htmlCol)

            for comp in sorted(components, key=lambda c: c.get('pos', 0)):
                html = self._component(comp, self_comp)
                htmlCol.append(Html('div', html, cn='block'))

        return container
Example #35
0
 def get_html(self, request):
     return Html('div', '<p>Well done, $project_name is created!</p>')
Example #36
0
 def html(self, bfield, **params):
     html = Html('select')
     if self.multiple:
         html.attr('multiple', 'multiple')
     self.choices.add_options(bfield, html)
     return html
Example #37
0
 def home(self, request):
     doc = request.html_document
     doc.body.append(Html('div',
                          '<p>Well done, TARS is created!</p>'))
     return doc.http_response(request)
Example #38
0
 def main(self, request, data):
     ul = Html('ul', cn='nav')
     for link in data:
         ul.append(link)
     return ul
Example #39
0
 def __call__(self, form, request):
     return Html(self.tag, Html('button', 'submit', cn='btn',
                                type='submit'))
Example #40
0
 def home(self, request):
     doc = request.html_document
     doc.body.append(Html('div', '<p>${extension_name} is created!</p>'))
     return doc.http_response(request)
Example #41
0
 def brand(self, request, data):
     link = request.app.config['NAVIGATION_BRAND_LINK']
     return Html('a', data, cn='brand', href=link)
Example #42
0
 def visual(self, request):
     doc = request.html_document
     scripts = doc.head.scripts
     scripts.require('jstest/visual.js')
     return Html('div', cn='visual-test').http_response(request)
Example #43
0
 def secondary(self, request, data):
     ul = Html('ul', cn='nav secondary')
     for link in data:
         ul.append(link)
     return ul
Example #44
0
 def _get_content(self, page, context):
     container = Html(None)
     if 'content_ids' not in context:
         context['content_ids'] = {}
     ids = context['content_ids']
     for content in page.content.get(self.key) or ():
         template = content.get('template')
         row = Html('div', template=template)
         for content in content.get('children') or ():
             column = Html('div')
             for bc in content or ():
                 block = Html('div', template=bc.get('template'))
                 for data in bc.get('children') or ():
                     if not data:
                         continue
                     content = data.pop('content', None)
                     if content is None:
                         continue
                     if isinstance(content, dict):
                         elem = Html('div', data=content)
                         # This is THE very special case where the
                         # content in this element is the content
                         # served by the url if there was no cms extension
                         if content.get(CONTENT_URL) == THIS:
                             value = context.get(THIS)
                             elem.append(Html('div', value, field=THIS))
                     else:
                         # id, we need to retrieve the content
                         content = int_or_string(content)
                         elem = Html('div')
                         if content in ids:
                             ids[content].append(elem)
                         else:
                             ids[content] = [elem]
                     elem.data(data)
                     block.append(elem)
                 column.append(block)
             row.append(column)
         container.append(row)
     return container
Example #45
0
 def _get_content(self, page, context):
     container = Html(None)
     if 'content_ids' not in context:
         context['content_ids'] = {}
     ids = context['content_ids']
     for content in page.content.get(self.key) or ():
         template = content.get('template')
         row = Html('div', template=template)
         for content in content.get('children') or ():
             column = Html('div')
             for bc in content or ():
                 block = Html('div', template=bc.get('template'))
                 for data in bc.get('children') or ():
                     if not data:
                         continue
                     content = data.pop('content', None)
                     if content is None:
                         continue
                     if isinstance(content, dict):
                         elem = Html('div', data=content)
                         # This is THE very special case where the
                         # content in this element is the content
                         # served by the url if there was no cms extension
                         if content.get(CONTENT_URL) == THIS:
                             value = context.get(THIS)
                             elem.append(Html('div', value, field=THIS))
                     else:
                         # id, we need to retrieve the content
                         content = int_or_string(content)
                         elem = Html('div')
                         if content in ids:
                             ids[content].append(elem)
                         else:
                             ids[content] = [elem]
                     elem.data(data)
                     block.append(elem)
                 column.append(block)
             row.append(column)
         container.append(row)
     return container