def widget_contents(self): """ Main method to create the ajaxselect widget. Calls helper methods and returns the wrapper element containing all associated elements """ # session = current.session # request = current.request wrapper = CAT() # create and add content of SPAN widget = self.create_widget() refreshlink = self.make_refresher(self.wrappername, self.linktable, self.uargs, self.uvars) adder, modal = self.make_adder(self.wrappername, self.linktable) wrapper.components.extend([widget, refreshlink, adder]) # create and add tags/links if multiple select widget if self.multi and (self.lister == "simple"): taglist = self.make_taglist() elif self.multi and (self.lister == "editlinks"): taglist = self.make_linklist() else: taglist = "" wrapper.append(taglist) return wrapper, modal
def widget_contents(self): """ Main method to create the ajaxselect widget. Calls helper methods and returns the wrapper element containing all associated elements """ #session = current.session #request = current.request wrapper = CAT() # create and add content of SPAN widget = self.create_widget() refreshlink = self.make_refresher(self.wrappername, self.linktable, self.uargs, self.uvars) adder, modal = self.make_adder(self.wrappername, self.linktable) wrapper.components.extend([widget, refreshlink, adder]) # create and add tags/links if multiple select widget if self.multi and (self.lister == 'simple'): taglist = self.make_taglist() elif self.multi and (self.lister == 'editlinks'): taglist = self.make_linklist() else: taglist = '' wrapper.append(taglist) return wrapper, modal
def _history_link(row): co = CAT() db = query._db tablas = db._adapter.tables(query) if len(tablas) > 1: for tbl in tablas: #print row.keys() if row.has_key(tbl): if row[tbl].has_key('id'): enl = URL('escuela', 'historial', args=[tbl, row[tbl].id]) co.append(Accion(SPAN('', _class='glyphicon glyphicon-time'), enl, puede_historial, _class="btn btn-default btn-xs", _title=T("Historial {}".format(tbl)))) else: enl = URL('escuela', 'historial', args=[tablas[0], row.id]) co.append(Accion(SPAN('', _class='glyphicon glyphicon-time'), enl, puede_historial, _class="btn btn-default btn-xs", _title=T("Historial {}".format(tablas[0])))) return co
def __init__(self, *components, **attributes): if '_class' in attributes.keys(): attributes['_class'] += ' dropdown-menu' else: attributes['_class'] = 'dropdown-menu' co = CAT() for c in components: co.append(LI(c)) super(MenuDespegable, self).__init__(co, **attributes)
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 __init__(self, vistas, *components, **attributes): request = current.request if '_class' in attributes.keys(): attributes['_class'] += ' list_group' else: attributes['_class'] = 'list_group' co = CAT() for c in components: a = 'active' if request.function in vistas else '' if '_class' in c.attributes.keys(): c.attributes['_class'] += ' list-group-item {0}'.format(a) else: c.attributes['_class'] = 'list-group-item {0}'.format(a) c.append(SPAN(SPAN(_class='glyphicon glyphicon-hand-up'), _class='badge')) co.append(c) super(MenuLateral, self).__init__(co, **attributes)
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 delete_photo(): item = application.getItemByUUID(request.args(0)) content = db.plugin_photoset_content(item_id=item.unique_id) photo = db.plugin_photoset_photo(request.args(1)) content.photoset.remove(photo.id) del db.plugin_photoset_photo[photo.id] content.update_record() application.notifyChanges(item.unique_id) return CAT('')
def widget(self): """ Place initial load container for controller to fill. """ wrapper = CAT() # create and add content of SPAN widget = self._create_widget() refreshlink = self._make_refresher(self.wrappername, self.linktable, self.uargs, self.uvars) adder, modal = self._make_adder(self.wrappername, self.linktable) wrapper.components.extend([widget, refreshlink, adder]) # create and add tags/links if multiple select widget if self.multi and (self.lister == "simple"): taglist = self._make_taglist() elif self.multi and (self.lister == "editlinks"): taglist = self._make_linklist() else: taglist = "" wrapper.append(taglist) return wrapper, modal
def widget(self): """ Place initial load container for controller to fill. """ wrapper = CAT() # create and add content of SPAN widget = self._create_widget() refreshlink = self._make_refresher(self.wrappername, self.linktable, self.uargs, self.uvars) adder, modal = self._make_adder(self.wrappername, self.linktable) wrapper.components.extend([widget, refreshlink, adder]) # create and add tags/links if multiple select widget if self.multi and (self.lister == 'simple'): taglist = self._make_taglist() elif self.multi and (self.lister == 'editlinks'): taglist = self._make_linklist() else: taglist = '' wrapper.append(taglist) return wrapper, modal
def delete_rendition(): item = application.getItemByUUID(request.args(0)) content = db.plugin_picture_info(item_id=item.unique_id) rend = db.plugin_picture_rendition(request.args(1)) if item and content and rend: # remove rendition # update content.renditions # update content db record r_id = rend.id del db.plugin_picture_rendition[r_id] content.renditions.remove(r_id) content.update_record() return CAT('')
def __init__(self, accion, menu): c = CAT() if '_class' in accion.attributes.keys(): accion.attributes['_class'] += "btn btn-default" else: accion.attributes['_class'] = "btn btn-default" c.append(accion) c.append(A(SPAN(_class='caret'), **{'_class': 'btn btn-default dropdown-toggle', '_data-toggle':'dropdown', '_aria-haspopup':'true', '_aria-expanded':'false'})) c.append(menu) super(BotonConMenu, self).__init__(c, _class='btn-group')
def ICONLINK(user, icon, text, action=None, title="Click", theme_name="basic"): from gluon import current request = current.request bt = A(_class="icon-link", _onclick=action if user else "window.location = '%s'" % URL('default', 'user', args='login', vars=dict(_next=URL('article', 'show', args=request.args))), _style="cursor:pointer;", _title=title) bt.append( CAT( IMG(_src=URL('static', '%s/images/icons' % theme_name, args="%s.png" % icon), _width=16), SPAN(text, _style="line-height:16px;"))) return bt
def create_item_url(self): return ( URL('plugin_package', 'create.html'), CAT(I(_class='fa fa-file-archive-o'), ' ', self.T('Package')))
def action_links(self): CURL = self.CURL article = self.context.article request = self.request T = self.T userid = self.session.auth.user.id if self.session.auth else 0 icons = { "views": ICONLINK( userid, "views", T("Views (%s)" % article.views or 0), title=T("The number of times this page has been displayed"), theme_name=self.context.theme_name), "favorite": ICONLINK(userid, "favorite", T("Favorite (%s)" % article.favorited or 0), "ajax('%s',[], 'links')" % CURL('favorite', args=request.args), T("Click to add to your favorites"), theme_name=self.context.theme_name), "unfavorite": ICONLINK(userid, "unfavorite", T("Favorite (%s)" % article.favorited or 0), "ajax('%s',[], 'links')" % CURL('unfavorite', args=request.args), T("Click to remove from your favorites"), theme_name=self.context.theme_name), "like": ICONLINK(userid, "like", T("Like (%s)" % article.likes or 0), "ajax('%s',[], 'links')" % CURL('like', args=request.args), T("Click to like"), theme_name=self.context.theme_name), "unlike": ICONLINK(userid, "unlike", T("Like (%s)" % article.likes or 0), "ajax('%s',[], 'links')" % CURL('unlike', args=request.args), T("Click to remove the like"), theme_name=self.context.theme_name), "dislike": ICONLINK(userid, "dislike", T("Dislike (%s)" % article.dislikes or 0), "ajax('%s',[], 'links')" % CURL('dislike', args=request.args), T("Click to dislike"), theme_name=self.context.theme_name), "undislike": ICONLINK(userid, "undislike", T("Dislike (%s)" % article.dislikes or 0), "ajax('%s',[], 'links')" % CURL('undislike', args=request.args), T("Click to remove the dislike"), theme_name=self.context.theme_name), "subscribe": ICONLINK(userid, "subscribe", T("Subscribe (%s)" % article.subscriptions or 0), "ajax('%s',[], 'links')" % CURL('subscribe', args=request.args), T("Click to subscribe to this article updates"), theme_name=self.context.theme_name), "unsubscribe": ICONLINK(userid, "unsubscribe", T("Subscribe (%s)" % article.subscriptions or 0), "ajax('%s',[], 'links')" % CURL('unsubscribe', args=request.args), T("Click to unsubscribe from this article updates"), theme_name=self.context.theme_name), "edit": ICONLINK(userid, "edit", T("Edit"), "window.location = '%s'" % CURL('edit', args=request.args), T("Click to edit"), theme_name=self.context.theme_name) } links = ['views'] favorited = self.db.Favoriters(article_id=self.context.article.id, user_id=userid) if userid else None liked = self.db.Likers(article_id=self.context.article.id, user_id=userid) if userid else None disliked = self.db.Dislikers(article_id=self.context.article.id, user_id=userid) if userid else None subscribed = self.db.Subscribers(article_id=self.context.article.id, user_id=userid) if userid else None links.append('unfavorite' if favorited else 'favorite') links.append('unlike' if liked else 'like') links.append('undislike' if disliked else 'dislike') if self.config.comment.system == "internal": links.append('unsubscribe' if subscribed else 'subscribe') if has_permission_to_edit(self.session, self.context.article): links.append('edit') return CAT(*[icons[link] for link in links])
def create_item_url(self): return ( URL('plugin_text', 'create.html'), CAT(I(_class="fa fa-file-text-o"), ' ', self.T('Text')))
def create_item_url(self): return (URL('plugin_picture', 'create.html'), CAT(I(_class='fa fa-picture-o'), ' ', self.T('Picture')))
def MODAL(triggertext, headertext, body, footer=None, modal_classes='', trigger_classes=None, id='mymodal', trigger_type='link', attributes=None): ''' Returns a bootstrap 3 modal widget wrapped in a web2py CAT() helper. The returned widget can be included in a view as a single helper, in which case the hidden modal window is placed immediately following the trigger element in the DOM. This is not desireable, though, if the parent of the trigger element has relative positioning, since the modal window will appear behind its dark background mask (and possibly behind other page elements). In that case, one can include the link alone as MODAL()[0]. The modal window can then be included separately at a higher level of the html structure by calling MODAL()[1] at the appropriate point in the view. The following positional arguments are required: [0] triggertext (str) The text for the link to trigger the modal. [1] headertext (str or 0) The text for the modal header. If the value is 0, no header will be included. [2] body (str or helper obj) The content to be displayed in the modal body. If this is a LOAD helper the body content will be loaded via ajax *on page load*, not when the modal is shown. The following named arguments are optional: :footer (str, helper obj, or 0) The content to be displayed in the modal footer. If this argument is not provided, the default footer is a simple "Close" button. If the value is the integer 0, no footer will be included at all. :modal_classes (str) A string including the extra classes to be assigned to the modal div. :trigger_classes (str) A string including the extra classes to be assigned to the button/link triggering the modal. :id (str or int) The id to be assigned to the modal div. defaults to 'mymodal'. If multiple modals are present on a paget this value must be specified (and distinct) for each. The id for the trigger will always be this same string with the suffix '_trigger'. :trigger_type (str: 'button' | 'link') Specifies the html entity to be used to trigger the modal. Defaults to 'link' which returns an A() helper. :attributes (dict) The names and values of any attributes to be assigned to the modal trigger. These can include data-attributes for setting additional modal options (as per the bootstrap 2.3.2 api). These attributes can also include an _href url (if the trigger type is 'link'). Otherwise the trigger link will not have any href value, since it is not needed by the Bootstrap modal script. The close button in the default footer requires no extra javascript (beyond the Bootstrap modal plugin). ''' # create trigger t_classes = trigger_classes if trigger_classes else '' if trigger_type == 'button': t_classes += 'btn' t_args = { '_data-toggle': 'modal', '_data-target': '#{}'.format(id), '_data-keyboard': True, '_href': '#{}'.format(id), '_id': '{}_trigger'.format(id), '_class': t_classes } if attributes: t_args.update(attributes) if trigger_type == 'link': trigger = A(triggertext, **t_args) else: trigger = BUTTON(triggertext, **t_args) # create wrapper div for modal modal_attrs = { '_tabindex': '-1', '_role': 'dialog', '_data-keyboard': 'true', '_aria-labelledby': '{}_trigger'.format(id), '_aria-hidden': 'true' } modal = DIV(DIV(DIV(_class="modal-content"), _class="modal-dialog modal-lg"), _class="modal fade {}".format(modal_classes), _id=id, **modal_attrs) # add header if headertext != 0: m_head = DIV(H3(headertext, _id="myModalLabel", _class="modal-title"), _class="modal-header") modal[0][0].append(m_head) else: pass # add body content modal[0][0].append(DIV(body, _class='modal-body {}'.format(modal_classes))) # add footer if footer and footer != 0: modal[0][0].append(DIV(footer, _class='modal-footer')) elif not footer: attrs = { '_type': 'button', '_data-dismiss': "modal", '_class': "pull-right", '_aria-hidden': "true" } modal[0][0].append(DIV(BUTTON('Close', **attrs), _class='modal-footer')) else: pass return CAT(trigger, modal)