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 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 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 grand_button(nombre, link, icono, **kwargs): """ nombre: 1 a 3 palabras""" lista = nombre.split() spanlist = [] for i in lista: spanlist.append(SPAN(i.title())) spanlist.append(BR()) result = DIV(spanlist) if 'vars' in kwargs: url = URL(link, vars=kwargs['vars']) else: url = URL(link) boton = A(TABLE(I(_class='fa ' + str(icono) + ' fa-3x'), result), _class="btn-square-blue", _href=url) return boton
def problem_widget(name, link, link_class, link_title, disable_todo=False, anchor=True): """ Widget to display a problem in UI tables @param name (String): Problem name @param link (String): Problem link @param link_class (String): HTML class to determine solved/unsolved @param link_title (String): Link title corresponding to link_class @param disable_todo (Boolean): Show / Hide todo button @return (DIV) """ problem_div = SPAN() if anchor: problem_div.append( A(name, _href=URL("problems", "index", vars={ "pname": name, "plink": link }, extension=False), _class="problem-listing " + link_class, _title=link_title, _target="_blank", extension=False)) else: problem_div.append(SPAN(name, _class=link_class, _title=link_title)) if current.auth.is_logged_in() and disable_todo is False: problem_div.append( I(_class="add-to-todo-list fa fa-check-square-o tooltipped", _style="padding-left: 10px; display: none; cursor: pointer;", data={ "position": "right", "delay": "10", "tooltip": "Add problem to Todo List" })) return problem_div
def index(): log('acceso') # menu favoritos form = CENTER( FORM(DIV(I(' Personal', _class='fa fa-ticket fa-2x', _id='tit_minigrid'), DIV(grand_button('empleados', 'admin_tabla', 'fa-cart-plus', vars={'tabla': 'empleado'}), grand_button('ver marcadas', 'admin_tabla', 'fa-th-large'), grand_button('informe mes empleado', 'informe_mes_empleado', 'fa-truck'), _id='mini_grid'), _id='indexdiv'), _id='panel_grid')) return dict(form=form)
def formstyle_materialize(form, fields, *args, **kwargs): """ divs only """ if not getattr(form, 'tag', None) == 'form': return DIV(form, fields, *args, **kwargs) form['_class'] = form['_class'] or 'col' form['_class'] = ' '.join(set(['col', 's12'] + form['_class'].split(' '))) table = DIV(_class="row") for id, label, controls, help in fields: _input_field = DIV(_class="input-field col s12") if help: _input_field.add_class('tooltipped') _input_field['_data-tooltip'] = help if getattr(controls, 'tag', None) == 'textarea': controls['_class'] += ' materialize-textarea' if controls['_type'] == 'file': _input_field['_class'] = 'file-field col s12 input-field' _input_field.append( DIV( SPAN(label[0]), controls, _class='btn')) _input_field.append( DIV( INPUT( _class='file-path validate', _readonly = '', _type='text'), _class='file-path-wrapper')) table.append(_input_field) continue if controls['_type'] == 'submit': controls.tag = 'button' controls.components.append(I('send', _class=('material-icons right'))) controls.components.append(controls['_value']) del controls['_value'] controls['_name'] = 'action' controls.add_class('btn right') _input_field.append(controls) _input_field.append(label) table.append(_input_field) return table
def chapter(poem, db, uhdb): """ Return a bootstrap row for a poem row. """ if not poem: raise Exception('No such poem') qry = ((db.verse.book == 1) & (db.verse.chapter == poem.chapter)) verse = db(qry).select().first() title = H3(poem.chapter.title) subtitle = H4('Chapter %i' % poem.chapter.number) published = H5(poem.published.strftime(date_format)) stanzas = verse.en.split('\r\n\r\n') content = [] for stanza in stanzas: content.append(P(XML(stanza.replace('\r\n', '<br />')))) link = P(A(I('Go to the study version'), _href=URL('studies', 'chapter', args=[poem.chapter.number]), _style='color:inherit;', _title='Study version'), _style='font-size:0.9em;padding-top:1em') content.append(P(link)) column = DIV(title, subtitle, published, *content, _class=poem_class) return DIV(column, _class='row', _style='font-size:1.12em;white-space:nowrap;')
def create_item_url(self): return ( URL('plugin_text', 'create.html'), CAT(I(_class="fa fa-file-text-o"), ' ', self.T('Text')))
def get_icon(self): return I(_class='fa fa-file-archive-o')
def render_user_editorials_table(user_editorials, user_id=None, logged_in_user_id=None, read_editorial_class=""): """ Render User editorials table @param user_editorials (Rows): Rows object of the editorials @param user_id (Number): For which user is the listing happening @param logged_in_user_id (Number): Which use is logged in @param read_editorial_class (String): HTML class for GA tracking @return (HTML): HTML table representing the user editorials """ db = current.db atable = db.auth_user ptable = db.problem T = current.T user_ids = set([x.user_id for x in user_editorials]) users = db(atable.id.belongs(user_ids)).select() user_mappings = {} for user in users: user_mappings[user.id] = user query = (ptable.id.belongs([x.problem_id for x in user_editorials])) problem_records = db(query).select(ptable.id, ptable.name, ptable.link) precords = {} for precord in problem_records: precords[precord.id] = {"name": precord.name, "link": precord.link} table = TABLE(_class="centered user-editorials-table") thead = THEAD( TR(TH(T("Problem")), TH(T("Editorial By")), TH(T("Added on")), TH(T("Votes")), TH())) tbody = TBODY() color_mapping = {"accepted": "green", "rejected": "red", "pending": "blue"} for editorial in user_editorials: if logged_in_user_id != 1 and user_id != editorial.user_id and editorial.verification != "accepted": continue user = user_mappings[editorial.user_id] record = precords[editorial.problem_id] number_of_votes = len( editorial.votes.split(",")) if editorial.votes else 0 link_class = get_link_class(record["link"], logged_in_user_id) link_title = (" ".join(link_class.split("-"))).capitalize() tr = TR( TD( problem_widget(record["name"], record["link"], link_class, link_title))) if logged_in_user_id is not None and \ (editorial.user_id == logged_in_user_id or logged_in_user_id == 1): tr.append(TD(A(user.first_name + " " + user.last_name, _href=URL("user", "profile", args=user.stopstalk_handle)), " ", DIV(editorial.verification.capitalize(), _class="verification-badge " + \ color_mapping[editorial.verification]))) else: tr.append( TD( A(user.first_name + " " + user.last_name, _href=URL("user", "profile", args=user.stopstalk_handle)))) tr.append(TD(editorial.added_on)) vote_class = "" if logged_in_user_id is not None and \ str(logged_in_user_id) in set(editorial.votes.split(",")): vote_class = "red-text" tr.append( TD( DIV(SPAN(I(_class="fa fa-heart " + vote_class), _class="love-editorial", data={"id": editorial.id}), " ", DIV(number_of_votes, _class="love-count", _style="margin-left: 5px;"), _style="display: inline-flex;"))) actions_td = TD( A(I(_class="fa fa-eye fa-2x"), _href=URL("problems", "read_editorial", args=editorial.id, extension=False), _class="btn btn-primary tooltipped " + read_editorial_class, _style="background-color: #13AA5F;", data={ "position": "bottom", "delay": 40, "tooltip": T("Read Editorial") })) if logged_in_user_id is not None and \ (user.id == logged_in_user_id or logged_in_user_id == 1) and \ editorial.verification != "accepted": actions_td.append( BUTTON( I(_class="fa fa-trash fa-2x"), _style="margin-left: 2%;", _class="btn btn-primary red tooltipped delete-editorial", data={ "position": "bottom", "delay": 40, "tooltip": T("Delete Editorial"), "id": editorial.id })) tr.append(actions_td) tbody.append(tr) table.append(thead) table.append(tbody) return table
## your http://google.com/analytics id response.google_analytics_id = None ######################################################################### ## main application menu ######################################################################### app = request.application ctr = request.controller response.menu = [] if auth.has_membership('editors', auth.user_id): response.menu += [ (T('Drafts'), False, A(I(_class='fa fa-book'), SPAN(' Drafts', _class="visible-lg-inline"), _href=URL('default', 'page', args=['drafts']), _class='draftslink'), []), ] if auth.has_membership('administrators', auth.user_id): response.menu += [ (T('Admin'), False, A(I(_class='fa fa-cog'), SPAN(' Admin', _class="visible-lg-inline"), _href='#', _class='adminlink'), [ (T('Documents'), False, A('Documents', _href=URL('default', 'listing', args=['docs'])), []),
def get_icon(self): return I(_class="fa fa-file-text-o")
def get_icon(self): return I(_class="fa fa-file")
def icon_title(icon, title): return I(f' {str(title)}', _class=f'fa {str(icon)} fa-1x')
def materialize_form(form, fields): """ Change layout of SQLFORM forms @params form (FORM): FORM object representing the form DOM @params fields (List): List of fields in the form @return (DIV): Materialized form wrapped with a DIV """ form.add_class("form-horizontal center") main_div = DIV(_class="center") for _, label, controls, field_tooltip in fields: curr_div = DIV(_class="row center valign-wrapper") input_field = None _controls = controls try: _name = controls.attributes["_name"] except: _name = "" try: _type = controls.attributes["_type"] except: _type = "string" try: _id = controls.attributes["_id"] except: _id = "" if isinstance(controls, INPUT): if _type == "file": # Layout for file type inputs input_field = DIV( DIV(SPAN("Upload"), INPUT(_type=_type, _id=_id), _class="btn"), DIV(INPUT(_type="text", _class="file-path", _placeholder=label.components[0]), _class="file-path-wrapper"), _class="col input-field file-field offset-s3 s6") elif _type == "checkbox": # Checkbox input field does not require input-field class input_field = DIV(_controls, label, _class="col offset-s3 s6") if isinstance(controls, SPAN): # Mostly for ids which cannot be edited by user _controls = INPUT(_value=controls.components[0], _id=_id, _name=_name, _disabled="disabled") elif isinstance(controls, TEXTAREA): # Textarea inputs try: _controls = TEXTAREA(controls.components[0], _name=_name, _id=_id, _class="materialize-textarea text") except IndexError: _controls = TEXTAREA(_name=_name, _id=_id, _class="materialize-textarea text") elif isinstance(controls, SELECT): # Select inputs _controls = SELECT(OPTION(label, _value=""), _name=_name, _class="browser-default", *controls.components[1:]) # Note now label will be the first element # of Select input whose value would be "" input_field = DIV(_controls, _class="col offset-s3 s6") elif isinstance(controls, A): # For the links in the bottom while updating tables like auth_user label = "" elif isinstance(controls, INPUT) is False: # If the values are readonly _controls = INPUT(_value=controls, _name=_name, _disabled="") if input_field is None: input_field = DIV(_controls, label, _class="input-field col offset-s3 s6") curr_div.append(input_field) if field_tooltip: curr_div.append( DIV(I(_class="fa fa-info-circle tooltipped", data={ "position": "top", "delay": "30", "tooltip": field_tooltip }, _style="cursor: pointer;"), _class="col s1 valign")) main_div.append(curr_div) return main_div
def create_item_url(self): return ( URL('plugin_package', 'create.html'), CAT(I(_class='fa fa-file-archive-o'), ' ', self.T('Package')))
def create_item_url(self): return (URL('plugin_picture', 'create.html'), CAT(I(_class='fa fa-picture-o'), ' ', self.T('Picture')))
def p_seen_rpr(v, r): if v: return I(_class="fa fa-envelope-open-o") return I(_class="fa fa-envelope")
def get_icon(self): return I(_class="fa fa-object-group")