def BREADCUMBS(*args): # todo: fix and change breadcrumbs """ Args: *args: Returns: <span class="breadcrumb"> <span class="hide-on-small-and-down"> Fisrt</span> <span class="hide-on-med-and-up"> Last </span> </span> <span class="breadcrumb hide-on-med-and-down"> Mid 1</span> <span class="breadcrumb hide-on-med-and-down"> Mid 2</span> <span class="breadcrumb hide-on-med-and-down"> Mid ...</span> <span class="breadcrumb hide-on-small-and-down"> Last</span> """ l = list(*args) last = l.pop() first = l and l.pop(0) or None if first: current.response.write( SPAN(SPAN(A(first[0], _href=first[1]), _class="hide-on-small-and-down"), SPAN(last, _class="hide-on-med-and-up"), _class="breadcrumb")) for i in l: name, link = i current.response.write( SPAN(A(first[0], _href=first[1]), _class="breadcrumb hide-on-med-and-down")) current.response.write( SPAN(last, _class="breadcrumb hide-on-small-and-down")) else: current.response.write(SPAN(last, _class="breadcrumb"))
def bookmark(cls, r, tablename, record_id): """ Get a bookmark link for a record in order to embed it in the view, also renders a link to the duplicate bookmark list to initiate the merge process from @param r: the S3Request @param tablename: the table name @param record_id: the record ID """ auth = current.auth system_roles = auth.get_system_roles() if not auth.s3_has_role(system_roles.ADMIN): return "" if r.component and not r.component.multiple: # Cannot de-duplicate single-components return "" s3 = current.session.s3 DEDUPLICATE = cls.DEDUPLICATE remove = DEDUPLICATE in s3 and \ tablename in s3[DEDUPLICATE] and \ str(record_id) in s3[DEDUPLICATE][tablename] and \ True or False mark = "mark-deduplicate action-lnk" unmark = "unmark-deduplicate action-lnk" deduplicate = "deduplicate action-lnk" if remove: mark += " hide" else: unmark += " hide" deduplicate += " hide" T = current.T link = DIV(A(T("Mark as duplicate"), _class=mark, ), A(T("Unmark as duplicate"), _class=unmark, ), A("", _href=r.url(method="deduplicate", vars={}), _id="markDuplicateURL", _class="hide", ), A(T("De-duplicate"), _href=r.url(method="deduplicate", target=0, vars={}), _class=deduplicate, ), _id="markDuplicate", ) return link
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
def xml(self): from gluon import current pages, rem = divmod(self.records, self.items_per_page) li = [] if rem: pages += 1 if self.page > 0: li.append( LI( A(XML('<i class="glyphicon glyphicon-fast-backward"></i>'), _href=URL(args=current.request.args, vars=dict(page=0))))) else: li.append( LI(A(XML('<i class="glyphicon glyphicon-fast-backward"></i>'), _href="#"), _class="disabled")) if self.page >= 1: li.append( LI( A(XML('<i class="glyphicon glyphicon-backward"></i>'), _href=URL(args=current.request.args, vars=dict(page=self.page - 1))))) else: li.append( LI(A(XML('<i class="glyphicon glyphicon-backward"></i>'), _href="#"), _class="disabled")) li.append( LI(A( XML('<i class="glyphicon glyphicon-file"></i>Página %s de %s' % (self.page + 1, int(self.records / self.items_per_page) + 1))), _class="disabled")) if self.page <= pages - 2: li.append( LI(A(XML('<i class="glyphicon glyphicon-forward"></i>'), _href=URL(args=current.request.args, vars=dict(page=self.page + 1))), _class="next")) else: li.append( LI(A(XML('<i class="glyphicon glyphicon-forward"></i>'), _href="#"), _class="disabled")) if self.page < pages - 1: li.append( LI( A(XML('<i class="glyphicon glyphicon-fast-forward"></i>'), _href=URL(args=current.request.args, vars=dict(page=pages - 1))))) else: li.append( LI(A(XML('<i class="glyphicon glyphicon-fast-forward"></i>'), _href="#"), _class="disabled")) div = DIV(UL(li, _class="pagination pagination-sm")) return DIV.xml(div)
def url_represent(url): return TAG[""](A(T("List"), _href=url, _class="action-btn"), A(T("Matrix"), _href=url.replace("search", "report"), _class="action-btn"), A(T("Chart"), _href=url.replace("search", "report?chart=breakdown%3Arows"), _class="action-btn"), A(T("Map"), _href=url.replace("project/search", "location/map"), _class="action-btn"))
def pager(db): """ Return a row DIV for a pager. """ from gluon import current # Previous/current/next page. if current.request.args(0): current_page = int(current.request.args(0)) else: current_page = 1 prev_page = current_page - 1 next_page = current_page + 1 # List of LI. pages = [] # Previous/left. li_class = '' href = URL('poems', 'page', args=[str(prev_page)]) if prev_page < 1: li_class = 'disabled' href = '#' elif prev_page == 1: href = URL('poems', 'index') span = SPAN(xmlescape(u'\u4e0a'), **{'_aria-hidden': 'true'}) anchor = A(span, _href=href, **{'_aria-label': 'Previous'}) pages.append(LI(anchor, _class=li_class, _title='Previous Page')) # Chapter range links. for page in range(1, 10): li_class = '' href = URL('poems', 'page', args=[str(page)]) page_range = ['%d-%d' % (((page - 1) * 9) + 1, page * 9)] if page == 1: href = URL('poems', 'index') if page == current_page: li_class = 'active' page_range.append(SPAN('(current)', _class='sr-only')) anchor = A(page_range, _href=href) pages.append(LI(anchor, _class=li_class)) # Next/right. li_class = '' href = URL('poems', 'page', args=[str(next_page)]) if next_page > 9: li_class = 'disabled' href = '#' span = SPAN(xmlescape(u'\u4e0b'), **{'_aria-hidden': 'true'}) anchor = A(span, _href=href, **{'_aria-label': 'Next'}) pages.append(LI(anchor, _class=li_class, _title='Next Page')) # Together. return UL(pages, _class='pagination')
def get_vm_snapshots(vm_id): vm_snapshots_list = [] snapshot_dict = {} for snapshot in db(db.snapshot.vm_id == vm_id).select(): snapshot_dict['name'] = snapshot.snapshot_name snapshot_dict['delete'] = A(IMG(_src=URL('static','images/delete-snapshot.gif'), _height = 20, _width = 20), _href=URL(r=request, f='delete_snapshot', args= [vm_id, snapshot.id]), _title = "Delete this snapshot", _alt = "Delete this snapshot") snapshot_dict['revert'] = A(IMG(_src=URL('static','images/revertTosnapshot.png'),_height = 20, _width = 20), _href=URL(r=request, f='revert_to_snapshot', args= [vm_id, snapshot.id]), _title = "Revert to this snapshot", _alt = "Revert to this snapshot") vm_snapshots_list.append(snapshot_dict) return vm_snapshots_list
def layout(item): """ Layout Method (Item Renderer) """ if item.enabled: if item.parent is not None: output = A( SPAN(item.label), _class="zocial %s" % item.opts.api, _href=item.url(), _title=item.opts.get("title", item.label), ) else: items = item.render_components() if items: output = DIV( items, _class="zocial-login", ) else: # Hide if empty output = None else: # Hide if disabled output = None return output
def _make_refresher(self, wrappername, linktable, uargs, uvars): ''' Return link to refresh this widget via ajax. The widget is always created, since its href attribute is used to pass several values to the client-side javascripts. If the widget is instantiated with the 'refresher' parameter set to False, then the link is hidden via CSS. ''' refresher_id = '{}_refresh_trigger'.format(linktable) # prepare to hide 'refresh' button via CSS if necessary rstyle = '' if self.refresher in (False, 'False'): rstyle = 'display:none' comp_url = URL('plugin_ajaxselect', 'get_values', args=self.uargs, vars=self.uvars) ajs = 'ajax("{url}", ["{n}"], "{wn}"); ' \ 'return false;'.format(url=comp_url, wn=self.wrappername, n=self.fieldset[1]) refresh_link = A(SPAN(_class='glyphicon glyphicon-refresh'), _onclick=ajs, _href=comp_url, _id=refresher_id, _class='refresh_trigger badge badge-info ', _style=rstyle) return refresh_link
def related_articles(self): from helpers.article import related_articles related_articles = related_articles(self.db, self.context.article.tags, self.context.article.category_id, self.context.article.id) if related_articles: self.context.related_articles = UL( *[ LI( DIV( IMG(_src=self.get_image( related.thumbnail, related.content_type_id.identifier), _width=120)), A(related.title, _href=self.CURL('article', 'show', args=[related.id, related.slug])), **{ '_data-url': self.CURL('article', 'show', args=[related.id, related.slug]) }) for related in related_articles ], **dict(_class="related-articles")) else: self.context.related_articles = False
def ACCORDION(panels, id='my_accordion'): ''' [0] pid [1] panel link text [2] panel content [3] body classes (string); 'in' marks default panel ''' acc = DIV(_class='panel-group', _id=id) for panel in panels: pid = panel[0] linktext = panel[1] content = panel[2] bclasses = '' if len(panel) <= 3 else panel[3] linkattrs = { '_class': "panel-toggle {}-toggle".format(pid), '_data-toggle': "collapse", '_data-parent': "#{}".format(id), '_href': "#{}".format(pid) } headattrs = {'_class': "panel-heading"} bodyattrs = {'_class': 'panel-body '} innerattrs = { '_class': 'panel collapse {}'.format(bclasses), '_id': pid } p = CAT( DIV(H4(A(linktext, **linkattrs), _class="panel-title"), **headattrs), DIV(DIV(content, **bodyattrs), **innerattrs), ) acc.append(p) return acc
def layout(item): """ Layout for popup link """ if not item.authorized: return None if current.deployment_settings.get_ui_use_button_icons(): label = (ICON("add"), item.label) else: label = item.label # @ToDo Ensure that if we are in an inline component, these links are different for each of the 3 _id = item.attr._id or "%s_add" % item.function popup_link = A(label, _href = item.url(format = "popup"), _class = "s3_add_resource_link", _id = _id, _target = "top", _title = item.opts.info, ) tooltip = item.opts.tooltip if tooltip is not None: ttip = DIV(_class = "tooltip", _title = "%s|%s" % (item.opts.title, tooltip, ), ) else: ttip = "" return TAG[""](popup_link, ttip)
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 layout(item): """ Layout for popup link """ if not item.authorized: return None if current.deployment_settings.get_ui_use_button_icons(): label = (ICON("add"), item.label) else: label = item.label popup_link = A( label, _href=item.url(format="popup"), _class="s3_add_resource_link", _id="%s_add" % item.function, _target="top", _title=item.opts.info, ) tooltip = item.opts.tooltip if tooltip is not None: ttip = DIV(_class="tooltip", _title="%s|%s" % (item.opts.title, tooltip)) else: ttip = "" return TAG[""](popup_link, ttip)
def get_html(self): contest_data = self.get_data() card_content_table = TABLE(_class="bordered centered highlight", _style="line-height: 20px") tbody = TBODY() for contest in contest_data: tbody.append( TR( TD(contest[0]), TD( IMG(_src=current.get_static_url("images/%s_small.png" % str(contest[1])), _class="parent-site-icon-small")), TD( A(I(_class="fa fa-external-link-square"), _class= "btn-floating btn-small accent-4 green view-contest", _href=contest[2], _target="_blank")))) card_content_table.append(tbody) card_html = BaseCard.get_html( self, **dict(card_title=self.card_title, card_content=card_content_table, cta_links=self.get_cta_html(), card_color_class="white", card_text_color_class="black-text")) return card_html
def custom_postp(r, output): # Call standard postp if callable(standard_postp): output = standard_postp(r, output) if not r.component and isinstance(output, dict): if r.record and r.method in (None, "update", "read"): # Custom CRUD buttons if "buttons" not in output: buttons = output["buttons"] = {} else: buttons = output["buttons"] # PDF-button pdf_download = A( T("Download PDF"), _href="/%s/fin/voucher/%s.card" % (r.application, r.record.id), _class="action-btn", ) # Render in place of the delete-button buttons["delete_btn"] = TAG[""](pdf_download, ) return output
def ICONLINK(title, text, icon): linktitle = '{}_icon'.format(title) link_classes = '{} icon-only icon-{}'.format(linktitle, icon) link = A(SPAN(text, _class='accessible'), _href='#', _class=link_classes, _id=linktitle) return link
def gen_links(row): diff = A( SPAN(_class="glyphicon glyphicon-random"), _href=URL('diff', args=[item.unique_id, row.id]), _class="btn btn-default", _title=T("Differences"), ) return CAT(diff)
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
def customise_event_incident_report_controller(**attr): from gluon import A s3 = current.response.s3 # Custom prep standard_prep = s3.prep def custom_prep(r): # Call standard postp if callable(standard_prep): result = standard_prep(r) if not result: return False if r.method in (None, "create"): current.s3db.gis_location.addr_street.label = T( "Street Address or Location Details") from s3 import S3SQLCustomForm crud_form = S3SQLCustomForm( (T("What is it?"), "name"), "incident_type_id", (T("Who am I speaking with?"), "reported_by"), (T("How can we contact you?"), "contact"), (T("Where did this Incident take place?"), "location_id"), (T("Explain the Situation?"), "description"), (T("What are your immediate needs?"), "needs"), ) r.resource.configure( create_next=URL(args=["[id]", "assign"]), crud_form=crud_form, ) return True s3.prep = custom_prep # No sidebar menu current.menu.options = None req_args = current.request.args if len(req_args) > 1 and req_args[1] == "assign": attr["rheader"] = A( T("New Incident"), _class="action-btn", _href=URL( c="event", f="incident", args=["create"], vars={"incident_report_id": req_args[0]}, ), ) else: attr["rheader"] = event_rheader return attr
def hr_name(row): hr_id = row["event_human_resource.human_resource_id"] return A( hr_represent(hr_id), _href=URL( c="event", f=f, args=[record_id, "human_resource", hr_id, "profile"], ), )
def incident_name(row): return A( row["event_incident.name"], _href=URL( c="event", f="incident", args=[row["event_incident.id"], "custom"], extension="", # ensure no .aadata ), )
def team_name(row): group_id = row["event_team.group_id"] return A( group_represent(group_id), _href=URL( c="event", f=f, args=[record_id, "group", group_id, "profile"], extension="", # ensure no .aadata ), )
def layout(item): if item.parent is None: items = item.render_components() return DIV(UL(items), _class='breadcrumbs') else: if item.is_last(): _class = "highlight" else: _class = "ancestor" return LI(A(item.label, _href=item.url(), _class=_class))
def task_name(row): return A( row["project_task.name"], _href=URL( c="event", f=f, args=[ record_id, "task", row["project_task.id"], "profile" ], ), )
def org_name(row): organisation_id = row["event_organisation.organisation_id"] return A( org_represent(organisation_id), _href=URL( c="event", f=f, args=[ record_id, "organisation", organisation_id, "profile" ], ), )
def link(self, k, v, row=None): """ Represent a (key, value) as hypertext link @param k: the key (br_case_activity.id) @param v: the representation of the key @param row: the row with this key """ url = URL(c = "vol", f = "person", args = [row.id], extension = "") return A(v, _href = url)
def get_html(self): contest_data = self.get_data() card_content_table = TABLE(_class="bordered centered highlight", _style="line-height: 20px") tbody = TBODY() for contest in contest_data: try: start_time = datetime.datetime.strptime( contest["start_time"], "%Y-%m-%dT%H:%M:%S.000Z") end_time = datetime.datetime.strptime( contest["end_time"], "%Y-%m-%dT%H:%M:%S.000Z") except Exception as e: print "Unable to parse datetime", contest start_time = datetime.datetime.strptime( contest["start_time"], "%Y-%m-%d %H:%M:%S %Z") end_time = datetime.datetime.strptime(contest["end_time"], "%Y-%m-%d %H:%M:%S %Z") start_time += datetime.timedelta(minutes=330) end_time += datetime.timedelta(minutes=330) contest["start_time"] = start_time contest["end_time"] = end_time tbody.append( TR( TD(contest["name"]), TD( IMG(_src=current.get_static_url( "images/%s_small.png" % str(contest["site"].lower())), _class="parent-site-icon-small")), TD( A(I(_class="fa fa-external-link-square"), _class= "btn-floating btn-small accent-4 green view-contest", _href=contest["url"], _target="_blank")), TD(utilities.get_reminder_button(contest)))) card_content_table.append(tbody) card_html = BaseCard.get_html( self, **dict(card_title=self.card_title, card_content=card_content_table, cta_links=self.get_cta_html(), card_color_class="white", card_text_color_class="black-text")) return card_html
def get_cta_html(self): cta_buttons = [] for cta in self.ctas: cta_buttons.append( A(cta["btn_text"], _href=cta["btn_url"], _class="btn btn-default stopstalk-dashboard-card-cta " + \ cta["btn_class"], _target="_blank") ) return cta_buttons
def _render_tag_div(self, label, controls, help): row = DIV(_class='col s12') label.tag = 'SPAN' row.append(DIV( DIV(label, controls[0], _class='btn'), DIV(INPUT(_class='file-path validate', _type='text'), _class='file-path-wrapper'), _class='file-field input-field' )) row.append(A(controls[3], _href=controls[1][1]['_href'])) row.append(DIV( P(LABEL(controls[1][3], SPAN(controls[1][4][0]))) )) return row