Пример #1
0
    def render_field(self, row, field):
        """
        Render a field

        if only 1 table in the query, the no table name needed when getting the row value - however, if there
        are multiple tables in the query (self.use_tablename == True) then we need to use the tablename as well
        when accessing the value in the row object

        the row object sent in can take
        :param row:
        :param field:
        :return:
        """
        if self.use_tablename:
            field_value = row[field.tablename][field.name]
        else:
            field_value = row[field.name]
        if field.type == 'date':
            _td = TD(XML("<script>\ndocument.write("
                       "moment(\"%s\").format('L'));\n</script>" % field_value) \
                       if row and field and field_value else '',
                     _class='has-text-centered')
        elif field.type == 'boolean':
            #  True/False - only show on True, blank for False
            if row and field and field_value:
                _td = TD(_class='has-text-centered')
                _span = SPAN(_class='icon is-small')
                _span.append(I(_class='fas fa-check-circle'))
                _td.append(_span)
            else:
                _td = TD(XML('&nbsp;'))
        else:
            _td = TD(field_value if row and field and field_value else '')

        return _td
Пример #2
0
    def table(self):
        _html = DIV()
        if self.create_url and self.create_url != '':
            _a = A('',
                   _href=self.create_url,
                   _class='button',
                   _style='margin-bottom: 1rem;')
            _span = SPAN(_class='icon is-small')
            _span.append(I(_class='fas fa-plus'))
            _a.append(_span)
            _a.append(SPAN('New'))
            _html.append(_a)

        _table = TABLE(_id='datatables_table',
                       _class='compact stripe hover cell-border order-column',
                       _style='padding-top: 1rem;')
        _thead = THEAD()
        _tr = TR()
        for field in self.fields:
            _tr.append(TH(field.label, _class='datatables-header'))
        _tr.append(
            TH('ACTIONS',
               _class='datatables-header has-text-centered',
               _style='color: black; width: 1px; white-space: nowrap;'))
        _thead.append(_tr)
        _table.append(_thead)
        _table.append(TBODY())

        _html.append(_table)
        return str(_html)
Пример #3
0
    def render_action_button(self,
                             url,
                             button_text,
                             icon,
                             size='small',
                             row_id=None,
                             user_signature=None,
                             page=None):
        separator = '?'
        if row_id:
            url += '/%s' % (row_id)
        if user_signature:
            url += '%suser_signature=%s' % (separator, user_signature)
            separator = '&'
        if page:
            url += '%spage=%s' % (separator, page)

        if self.include_action_button_text:
            _a = A(_href=url, _class='button is-%s' % size, _title=button_text)
            _span = SPAN(_class='icon is-%s' % size)
            _span.append(I(_class='fas %s' % icon))
            _a.append(_span)
            _a.append(SPAN(button_text))
        else:
            _a = A(I(_class='fas %s' % icon),
                   _href=url,
                   _class='button is-%s' % size,
                   _title=button_text)

        return _a