Пример #1
0
 def _make_taglist(self):
     """Build a list of selected widget options to be displayed as a
     list of 'tags' below the widget."""
     try:
         db = current.db
         classes = 'taglist'
         if self.sortable:
             classes += ' sortable'
         taglist = UL(_class=classes)
         if self.value:
             for v in self.value:
                 the_row = db(db[self.linktable].id == v).select().first()
                 fmt = db[self.linktable]._format
                 format_string = fmt(the_row) if callable(fmt) \
                     else fmt % the_row
                 listitem = LI(SPAN(format_string,
                                    _id=v,
                                    _class='label label-info'),
                               _id=v,
                               _class='tag')
                 listitem.append(
                     A(SPAN(_class='glyphicon glyphicon-remove'),
                       _href='#',
                       _class='tag tag_remover label label-warning'))
                 taglist.append(listitem)
         else:
             pass
     except Exception:
         print(traceback.format_exc(5))
     return taglist
 def _make_taglist(self):
     """Build a list of selected widget options to be displayed as a
     list of 'tags' below the widget."""
     try:
         db = current.db
         classes = "taglist"
         if self.sortable:
             classes += " sortable"
         taglist = UL(_class=classes)
         if self.value:
             for v in self.value:
                 the_row = db(db[self.linktable].id == v).select().first()
                 fmt = db[self.linktable]._format
                 format_string = fmt(the_row) if callable(fmt) else fmt % the_row
                 listitem = LI(SPAN(format_string, _id=v, _class="label label-info"), _id=v, _class="tag")
                 listitem.append(
                     A(
                         SPAN(_class="glyphicon glyphicon-remove"),
                         _href="#",
                         _class="tag tag_remover " "label label-warning",
                     )
                 )
                 taglist.append(listitem)
         else:
             pass
     except Exception:
         print traceback.format_exc(5)
     return taglist
    def make_linklist(self):
        """
        Build a list of selected widget options to be displayed as a
        list of 'tags' below the widget.
        """
        db = current.db
        xclasses = ' sortable' if self.sortable else ''
        ll = UL(_class='taglist editlist {}'.format(xclasses))

        #append the currently selected items to the list
        if self.value:
            for v in listcheck(self.value):
                myrow = db(db[self.linktable].id == v).select().first()
                if myrow is None:
                    continue
                try:
                    fmt = db[self.linktable]._format
                    formatted = fmt(myrow) if callable(fmt) else fmt % myrow
                except TypeError:
                    formatted = myrow[1]
                linkargs = self.uargs[:]  # new obj so vals don't pile up
                linkargs.append(v)
                ln = LI(SPAN(formatted, _class='badge badge-info'),
                        _id=v,
                        _class='editlink tag')
                myargs = self.uargs[:]
                print 'making linklist: self.uargs is', self.uargs
                myargs.append(v)
                print 'making linklist: myargs is ', myargs
                elink = MODAL(
                    u'\u200B',
                    'Edit {} item {}'.format(self.linktable, v),
                    LOAD('plugin_ajaxselect',
                         'linked_edit_form.load',
                         args=myargs,
                         vars=self.uvars,
                         ajax=True),
                    trigger_classes=
                    'linklist_edit_trigger badge badge-warning icon-edit',
                    trigger_type='link',
                    modal_classes='plugin_ajaxselect modal_linklist_edit',
                    id='{}_{}'.format(self.linktable, v))
                ln.append(elink)
                ln.append(
                    A(u'\u200B',
                      _class='tag tag_remover icon-remove '
                      'label label-important'))
                ll.append(ln)
        return ll
Пример #4
0
def pager(total_records, page_limit, current_page, target_url, page_var):
    """ Generates a simple pagintator navigation block.
    """
    total_pages = int(math.ceil(total_records / float(page_limit)))
    current_page = int(current_page)

    if total_pages <= 1:
        return None

    prev_disabled = current_page <= 1
    next_disabled = current_page == total_pages

    # Build the page links...
    url_fmt = target_url
    # Any other query params?
    if '?' in url_fmt:
        url_fmt += '&'
    else:
        url_fmt += '?'
    url_fmt += page_var + '={0}'

    result = DIV(_class="pagination")
    page_list = UL()

    prev_page = LI()
    next_page = LI()

    if prev_disabled:
        prev_page['_class'] = "disabled"
        prev_page.append(A(I(_class="icon-backward"), _href="#"))
    else:
        prev_page.append(
            A(I(_class="icon-backward"),
              _href=url_fmt.format(current_page - 1)))

    if next_disabled:
        next_page['_class'] = 'disabled'
        next_page.append(A(I(_class="icon-forward"), _href="#"))
    else:
        next_page.append(
            A(I(_class="icon-forward"),
              _href=url_fmt.format(current_page + 1)))

    page_list.append(prev_page)

    for page_num, idx in enumerate(xrange(total_pages), 1):
        entry = LI(A(str(page_num), _href=url_fmt.format(page_num)))
        if page_num == current_page:
            entry['_class'] = "active"
        page_list.append(entry)

    page_list.append(next_page)
    result.append(page_list)

    return result
Пример #5
0
 def serialize(self, data, level=0, menu_name=None):
     if level == 0:
         ul = UL(**self.attributes)
     elif level == 1 and menu_name:
         ul = UL(_class=self['ul_class'], _id=menu_name)
     else:
         return ''  # Navbar 1 level only
     for n, item in enumerate(data):
         if isinstance(item, LI):
             ul.append(item)
         else:
             (name, active, link) = item[:3]
             if isinstance(link, DIV):
                 li = LI(link)
             elif 'no_link_url' in self.attributes and self[
                     'no_link_url'] == link:
                 li = LI(DIV(name))
             elif isinstance(link, dict):
                 li = LI(A(name, **link))
             elif link:
                 li = LI(A(name, _href=link))
             elif not link and isinstance(name, A):
                 li = LI(name)
             else:
                 li = LI(
                     A(name,
                       _href='#',
                       _onclick='javascript:void(0);return false;'))
             if len(item) > 3 and item[3]:
                 li['_class'] = self['li_class']
                 menu_id = "%s-%s" % (self.menu_name, n)
                 a = li.element('a')
                 a['_class'] = "dropdown-button"
                 a['_data-activates'] = menu_id
                 li.append(self.serialize(item[3], level + 1, menu_id))
             if active or ('active_url' in self.attributes
                           and self['active_url'] == link):
                 if li['_class']:
                     li['_class'] = li['_class'] + ' ' + self['li_active']
                 else:
                     li['_class'] = self['li_active']
             if len(item) <= 4 or item[4] == True:
                 ul.append(li)
     return ul
Пример #6
0
 def serialize(self, data, level=0):
     if level == 0:
         ul = UL(**self.attributes)
     else:
         ul = UL(_class=self['ul_class'])
     for item in data:
         if isinstance(item, LI):
             ul.append(item)
         else:
             (name, active, link) = item[:3]
             if isinstance(link, DIV):
                 li = LI(link)
             elif 'no_link_url' in self.attributes and self['no_link_url'] == link:
                 li = LI(DIV(name))
             elif isinstance(link, dict):
                 li = LI(A(name, **link))
             elif link:
                 li = LI(A(name, _href=link))
             elif not link and isinstance(name, A):
                 li = LI(name)
             else:
                 li = LI(A(name, _href='#',
                           _onclick='javascript:void(0);return false;'))
             if level == 0 and item == data[0]:
                 li['_class'] = self['li_first']
             elif level == 0 and item == data[-1]:
                 li['_class'] = self['li_last']
             if len(item) > 3 and item[3]:
                 li['_class'] = self['li_class']
                 li.append(self.serialize(item[3], level + 1))
             if active or ('active_url' in self.attributes and self['active_url'] == link):
                 if li['_class']:
                     li['_class'] = li['_class'] + ' ' + self['li_active']
                 else:
                     li['_class'] = self['li_active']
             if len(item) <= 4:
                 ul.append(li)
             else:
                 if item[4] is False:
                     li['_class'] = 'disabled'
                 ul.append(li)
     return ul
    def _make_linklist(self):
        """
        Build a list of selected widget options to be displayed as a
        list of 'tags' below the widget.
        """
        db = current.db
        xclasses = " sortable" if self.sortable else ""
        ll = UL(_class="taglist editlist {}".format(xclasses))

        # append the currently selected items to the list
        if self.value:
            for v in listcheck(self.value):
                myrow = db(db[self.linktable].id == v).select().first()
                if myrow is None:
                    continue
                try:
                    fmt = db[self.linktable]._format
                    formatted = fmt(myrow) if callable(fmt) else fmt % myrow
                except TypeError:
                    formatted = myrow[1]
                linkargs = self.uargs[:]  # new obj so vals don't pile up
                linkargs.append(v)
                ln = LI(SPAN(formatted, _class="badge badge-info"), _id=v, _class="editlink tag")
                myargs = self.uargs[:]
                myargs.append(v)
                elink = MODAL(
                    SPAN(_class="glyphicon glyphicon-edit"),
                    "Edit {} item {}".format(self.linktable, v),
                    LOAD("plugin_ajaxselect", "linked_edit_form.load", args=myargs, vars=self.uvars, ajax=True),
                    trigger_classes="linklist_edit_trigger badge badge-warning ",
                    trigger_type="link",
                    modal_classes="plugin_ajaxselect modal_linklist_edit",
                    id="{}_{}".format(self.linktable, v),
                )
                ln.append(elink)
                ln.append(
                    A(SPAN(_class="glyphicon glyphicon-remove"), _class="tag tag_remover " "label label-important")
                )
                ll.append(ln)
        return ll
Пример #8
0
 def serialize(self, data, level=0):
     if level == 0:
         ul = UL(**self.attributes)
     else:
         ul = UL(_class=self['ul_class'])
     for item in data:
         if isinstance(item,LI):
             ul.append(item)
         else:
             (name, active, link) = item[:3]
             if isinstance(link, DIV):
                 li = LI(link)
             elif 'no_link_url' in self.attributes and self['no_link_url'] == link:
                 li = LI(DIV(name))
             elif isinstance(link,dict):
                 li = LI(A(name, **link))
             elif link:
                 li = LI(A(name, _href=link))
             elif not link and isinstance(name, A):
                 li = LI(name)
             else:
                 li = LI(A(XML(" ".join(map(lambda s: "%s" %s,name)) ),
                           B(_class="arrow fa fa-angle-down"),
                           _href='#',
                           _class=self['a_submenu_class'],))
             if level == 0 and item == data[0]:
                 li['_class'] = self['li_first']
             elif level == 0 and item == data[-1]:
                 li['_class'] = self['li_last']
             if len(item) > 3 and item[3]:
                 li['_class'] = self['li_class']
                 li.append(self.serialize(item[3], level + 1))
             if active or ('active_url' in self.attributes and self['active_url'] == link):
                 if li['_class']:
                     li['_class'] = li['_class'] + ' ' + self['li_active']
                 else:
                     li['_class'] = self['li_active']
             if len(item) <= 4 or item[4] == True:
                 ul.append(li)
     return ul