def lnk(self, commit_or_id, repo_name): from rhodecode.lib.helpers import tooltip if isinstance(commit_or_id, (BaseCommit, AttributeDict)): lazy_cs = True if (getattr(commit_or_id, 'op', None) and getattr(commit_or_id, 'ref_name', None)): lazy_cs = False lbl = '?' if commit_or_id.op == 'delete_branch': lbl = '%s' % _('Deleted branch: %s') % commit_or_id.ref_name title = '' elif commit_or_id.op == 'tag': lbl = '%s' % _('Created tag: %s') % commit_or_id.ref_name title = '' _url = '#' else: lbl = '%s' % (commit_or_id.short_id[:8]) _url = url('changeset_home', repo_name=repo_name, revision=commit_or_id.raw_id) title = tooltip(commit_or_id.message) else: # commit cannot be found/striped/removed etc. lbl = ('%s' % commit_or_id)[:12] _url = '#' title = _('Commit not found') if self.parse_commits: return link_to(lbl, _url, title=title, class_='tooltip') return link_to(lbl, _url, raw_id=commit_or_id.raw_id, repo_name=repo_name, class_='lazy-cs' if lazy_cs else '')
def _link(pagenr, text): """ Create a URL that links to another page """ # Let the url_for() from webhelpers create a new link and set # the variable called 'link_var'. Example: # You are in '/foo/bar' (controller='foo', action='bar') # and you want to add a parameter 'pagenr'. Then you # call the navigator method with link_var='pagenr' and # the url_for() call will create a link '/foo/bar?pagenr=...' # with the respective page number added. # Further kwargs that are passed to the navigator will # also be added as URL parameters. arg_dict = {link_var:pagenr} arg_dict.update(kwargs) link_url = routes.url_for(**arg_dict) if ajax_id: # Return an AJAX link that will update the HTML element # named by ajax_id. if framework == 'jquery': return tags.link_to(text, onclick="""$('#%s').load('%s'); return false""" % \ (ajax_id, link_url)) else: raise Exception, "Unsupported Javascript framework: %s" % \ framework else: # Return a normal a-href link that will call the same # controller/action with the link_var set to the new # page number. return tags.link_to(text, link_url)
def lnk(rev, repo_name): if isinstance(rev, BaseChangeset) or isinstance( rev, AttributeDict): lazy_cs = True if getattr(rev, 'op', None) and getattr(rev, 'ref_name', None): lazy_cs = False lbl = '?' if rev.op == 'delete_branch': lbl = '%s' % _('Deleted branch: %s') % rev.ref_name title = '' elif rev.op == 'tag': lbl = '%s' % _('Created tag: %s') % rev.ref_name title = '' _url = '#' else: lbl = '%s' % (rev.short_id[:8]) _url = url('changeset_home', repo_name=repo_name, revision=rev.raw_id) title = tooltip(rev.message) else: ## changeset cannot be found/striped/removed etc. lbl = ('%s' % rev)[:12] _url = '#' title = _('Changeset not found') if parse_cs: return link_to(lbl, _url, title=title, class_='tooltip') return link_to(lbl, _url, raw_id=rev.raw_id, repo_name=repo_name, class_='lazy-cs' if lazy_cs else '')
def lnk(rev, repo_name): lazy_cs = False title_ = None url_ = '#' if isinstance(rev, BaseChangeset) or isinstance(rev, AttributeDict): if rev.op and rev.ref_name: if rev.op == 'delete_branch': lbl = _('Deleted branch: %s') % rev.ref_name elif rev.op == 'tag': lbl = _('Created tag: %s') % rev.ref_name else: lbl = 'Unknown operation %s' % rev.op else: lazy_cs = True lbl = rev.short_id[:8] url_ = url('changeset_home', repo_name=repo_name, revision=rev.raw_id) else: # changeset cannot be found - it might have been stripped or removed lbl = rev[:12] title_ = _('Changeset %s not found') % lbl if parse_cs: return link_to(lbl, url_, title=title_, **{'data-toggle': 'tooltip'}) return link_to(lbl, url_, class_='lazy-cs' if lazy_cs else '', **{'data-raw_id':rev.raw_id, 'data-repo_name':repo_name})
def lnk(rev, repo_name): if isinstance(rev, BaseChangeset) or isinstance(rev, AttributeDict): lazy_cs = True if getattr(rev, 'op', None) and getattr(rev, 'ref_name', None): lazy_cs = False lbl = '?' if rev.op == 'delete_branch': lbl = '%s' % _('Deleted branch: %s') % rev.ref_name title = '' elif rev.op == 'tag': lbl = '%s' % _('Created tag: %s') % rev.ref_name title = '' _url = '#' else: lbl = '%s' % (rev.short_id[:8]) _url = url('changeset_home', repo_name=repo_name, revision=rev.raw_id) title = tooltip(rev.message) else: ## changeset cannot be found/striped/removed etc. lbl = ('%s' % rev)[:12] _url = '#' title = _('Changeset not found') if parse_cs: return link_to(lbl, _url, title=title, class_='tooltip') return link_to(lbl, _url, raw_id=rev.raw_id, repo_name=repo_name, class_='lazy-cs' if lazy_cs else '')
def lnk(rev, repo_name): lazy_cs = False title_ = None url_ = '#' if isinstance(rev, BaseChangeset) or isinstance( rev, AttributeDict): if rev.op and rev.ref_name: if rev.op == 'delete_branch': lbl = _('Deleted branch: %s') % rev.ref_name elif rev.op == 'tag': lbl = _('Created tag: %s') % rev.ref_name else: lbl = 'Unknown operation %s' % rev.op else: lazy_cs = True lbl = rev.short_id[:8] url_ = url('changeset_home', repo_name=repo_name, revision=rev.raw_id) else: # changeset cannot be found - it might have been stripped or removed lbl = rev[:12] title_ = _('Changeset %s not found') % lbl if parse_cs: return link_to(lbl, url_, title=title_, **{'data-toggle': 'tooltip'}) return link_to(lbl, url_, class_='lazy-cs' if lazy_cs else '', **{ 'data-raw_id': rev.raw_id, 'data-repo_name': repo_name })
def _pagerlink(pagenr, text): """ Create a URL that links to another page using url_for() Parameters: pagenr Number of the page that the link points to text Text to be printed in the A-HREF tag """ # Let the url_for() from webhelpers create a new link and set # the variable called 'link_var'. Example: # You are in '/foo/bar' (controller='foo', action='bar') # and you want to add a parameter 'pagenr'. Then you # call the navigator method with link_var='pagenr' and # the url_for() call will create a link '/foo/bar?pagenr=...' # with the respective page number added. link_params = {} # Use the instance kwargs from Page.__init__ as URL parameters link_params.update(self.kwargs) # Add keyword arguments from pager() to the link as parameters link_params.update(kwargs) link_params[link_var] = pagenr # Create the URL to load a certain page link_url = routes.url_for(**link_params) log.debug("link_url(**%r) => %r", link_params, link_url) # Create the URL to load the page area part of a certain page (AJAX updates) link_params[partial_var] = 1 partial_url = routes.url_for(**link_params) log.debug("partial_url(**%r) => %r", link_params, partial_url) if ajax_id: # Return an AJAX link that will update the HTML element # named by ajax_id. # Degrade gracefully if Javascript is not available by using # 'partial_url' in the onclick URLs while using 'link_url' # in the A-HREF URL. if framework == 'jquery': return tags.link_to(text, url=link_url, onclick="""%s$('#%s').load('%s'); return false""" % \ (javascript_before, ajax_id, partial_url), **link_attr) elif framework == 'yui': js = """%sYAHOO.util.Connect.asyncRequest('GET','%s',{ success:function(o){YAHOO.util.Dom.get('%s').innerHTML=o.responseText;} },null); return false;""" % (javascript_before, partial_url, ajax_id) return tags.link_to(text, url=link_url, onclick=js, **link_attr) elif framework == 'extjs': js = """%sExt.get('%s').load({url:'%s'}); return false;""" % (javascript_before, ajax_id, partial_url) return tags.link_to(text, url=link_url, onclick=js, **link_attr) else: raise Exception, "Unsupported Javascript framework: %s" % framework else: # Return a normal a-href link that will call the same # controller/action with the link_var set to the new # page number. return tags.link_to(text, link_url, **link_attr)
def bugs_page_link(package): """Return the URL to the bug reports page depending on the origin. For Ubuntu packages it points to edge.launchpad.net while for all other packages it points to bugs.debian.org.""" if package.origin is not None and package.origin.lower() == "ubuntu": return tags.link_to("Bug reports", "https://launchpad.net/distros/ubuntu/+source/%s/+bugs" % package.name) else: return tags.link_to("Bug reports", "http://bugs.debian.org/%s" % package.name)
def package_page_link(package): """Return the URL to the package page depending on the origin. For Ubuntu packages it points to packages.ubuntu.com while for all other packages it points to packages.debian.org.""" if package.origin is not None and package.origin.lower() == "ubuntu": return tags.link_to("Package page on ubuntu.com", "http://packages.ubuntu.com/%s" % package.name) else: return tags.link_to("Package page on debian.org", "http://packages.debian.org/%s" % package.name)
def postPanelCallback(self, thread, post, userInst): result = '' if userInst.isAdmin() and userInst.canManageUsers(): if post.uidNumber: result += link_to(_("[User]"), h.url_for('hsUserEditAttempt', pid=post.id)) if post.ip: result += link_to(_("[IP Ban]"), h.url_for('hsIpBanAttempt', pid=post.id)) return result
def get_cs_links(): revs_limit = 3 #display this amount always revs_top_limit = 50 #show upto this amount of changesets hidden revs = action_params.split(',') repo_name = user_log.repository.repo_name from rhodecode.model.scm import ScmModel repo = user_log.repository.scm_instance message = lambda rev: get_changeset_safe(repo, rev).message cs_links = [] cs_links.append(" " + ', '.join ([link_to(rev, url('changeset_home', repo_name=repo_name, revision=rev), title=tooltip(message(rev)), class_='tooltip') for rev in revs[:revs_limit] ])) compare_view = (' <div class="compare_view tooltip" title="%s">' '<a href="%s">%s</a> ' '</div>' % (_('Show all combined changesets %s->%s' \ % (revs[0], revs[-1])), url('changeset_home', repo_name=repo_name, revision='%s...%s' % (revs[0], revs[-1]) ), _('compare view')) ) if len(revs) > revs_limit: uniq_id = revs[0] html_tmpl = ('<span> %s ' '<a class="show_more" id="_%s" href="#more">%s</a> ' '%s</span>') if not feed: cs_links.append(html_tmpl % (_('and'), uniq_id, _('%s more') \ % (len(revs) - revs_limit), _('revisions'))) if not feed: html_tmpl = '<span id="%s" style="display:none"> %s </span>' else: html_tmpl = '<span id="%s"> %s </span>' cs_links.append(html_tmpl % (uniq_id, ', '.join([link_to(rev, url('changeset_home', repo_name=repo_name, revision=rev), title=message(rev), class_='tooltip') for rev in revs[revs_limit:revs_top_limit]]))) if len(revs) > 1: cs_links.append(compare_view) return ''.join(cs_links)
def __call__(self, repo_name, rev, paths): if isinstance(paths, str): paths = safe_unicode(paths) url_l = [link_to(repo_name, url('files_home', repo_name=repo_name, revision=rev, f_path=''))] paths_l = paths.split('/') for cnt, p in enumerate(paths_l): if p != '': url_l.append(link_to(p, url('files_home', repo_name=repo_name, revision=rev, f_path='/'.join(paths_l[:cnt + 1])))) return literal('/'.join(url_l))
def link_print(label, url='', **attrs): if attrs.has_key('class_'): attrs['class_'] += ' btn action print' else: attrs['class_'] = ' btn action print' span = '<span><span>' + label + '</span></span>' return link_to(literal(span), url, **attrs)
def renderSubLink(menuitem): texttemplate = g.OPT.dvachStyleMenu and '%s' or '/%s/' return '<b>%s</b>' % link_to(texttemplate % menuitem.text, menuitem.route or '#', title=menuitem.hint, onclick=menuitem.onclick, target=menuitem.target)
def __unicode__(self): if self.icon: text = self.icon + u' ' + self.text else: text = self.text return link_to(text, self.href or u'#', **self.kw)
def userInfo(self): checkLogIn(session) c.site = "Projects" c.name = session['user_id'] c.menu = genMenu(self) res = getUserData(c.name) c.lineData = [("Username", res[0]), ("Name", res[1]), ("Last name", res[2]), ("Email", res[3])] c.content = render("/line_by_line.html") + html.literal("<br />") c.header = ["All my projects"] proj = userProjects(c.name) c.rows = [] for x in proj: url_old = urlparse(request.url) url = url_old.scheme + '://' + url_old.netloc + getProjectUrl(x[0]) c.rows.append((link_to(x[0], url), )) c.style = "width:70%; text-align: left" #XXX: move css to templates c.content += render("/table.html") return render("/temp.html")
def image_fixups(content, msgid, archive, richformat, allowimgs): "Replace the CID links stored messages" html = local_fromstring(content) for element, attribute, link, _ in iterlinks(html): if not link.startswith('cid:'): if not allowimgs and attribute == 'src': element.attrib['src'] = '%simgs/blocked.gif' % media_url() element.attrib['title'] = link if richformat: if archive: displayurl = url('message-preview-archived-with-imgs', msgid=msgid) else: displayurl = url('message-preview-with-imgs', msgid=msgid) flash( ugettext('This message contains external' ' images, which have been blocked. ') + literal(link_to(ugettext('Display images'), displayurl))) else: imgname = link.replace('cid:', '') if archive: imgurl = url('messages-preview-archived-img', img=imgname.replace('/', '__xoxo__'), msgid=msgid) else: imgurl = url('messages-preview-img', img=imgname.replace('/', '__xoxo__'), msgid=msgid) element.attrib['src'] = imgurl return tostring(html)
def link_to_ref(repo_name, ref_type, ref_name, rev=None): """ Return full markup for a href to changeset_home for a changeset. If ref_type is branch it will link to changelog. ref_name is shortened if ref_type is 'rev'. if rev is specified show it too, explicitly linking to that revision. """ txt = short_ref(ref_type, ref_name) if ref_type == 'branch': u = url('changelog_home', repo_name=repo_name, branch=ref_name) else: u = url('changeset_home', repo_name=repo_name, revision=ref_name) l = link_to(repo_name + '#' + txt, u) if rev and ref_type != 'rev': l = literal('%s (%s)' % (l, link_to(short_id(rev), url('changeset_home', repo_name=repo_name, revision=rev)))) return l
def linked_user_comments(user, maxlength=0, avatar=20): if not isinstance(user, model.User): user_name = unicode(user) user = model.User.get(user_name) if not user: return user_name if user: name = user.name if model.User.VALID_NAME.match(user.name) else user.id displayname = user.display_name user_name = user.name if model.User.VALID_NAME.match(user.name) else user.id if maxlength and len(user.display_name) > maxlength: displayname = displayname[:maxlength] + '...' if maxlength and len(user.name) > maxlength: user_name = user_name[:maxlength] + '...' return tags.literal(u'{icon} {link}'.format( icon=gravatar( email_hash=user.email_hash, size=avatar ), link=tags.link_to( user_name, url_for(controller='user', action='read', id=name) ) ))
def postPanelCallback(self, thread, post, userInst): result = '' if g.OPT.enableFinalAnonymity and ( g.OPT.memcachedPosts or (not userInst.Anonymous and post.uidNumber == c.uidNumber)): result += link_to(_("[FA]"), h.url_for('anonymize', post=post.id)) return result
def image_fixups(content, msgid, archive, richformat, allowimgs): "Replace the CID links stored messages" html = local_fromstring(content) for element, attribute, link, _ in iterlinks(html): if not link.startswith('cid:'): if not allowimgs and attribute == 'src': element.attrib['src'] = '%simgs/blocked.gif' % media_url() element.attrib['title'] = link if richformat: if archive: displayurl = url('message-preview-archived-with-imgs', msgid=msgid) else: displayurl = url('message-preview-with-imgs', msgid=msgid) flash(ugettext('This message contains external' ' images, which have been blocked. ') + literal(link_to(ugettext('Display images'), displayurl))) else: imgname = link.replace('cid:', '') if archive: imgurl = url('messages-preview-archived-img', img=imgname.replace('/', '__xoxo__'), msgid=msgid) else: imgurl = url('messages-preview-img', img=imgname.replace('/', '__xoxo__'), msgid=msgid) element.attrib['src'] = imgurl return tostring(html)
def userInfo(self): checkLogIn(session) c.site = "Projects" c.name = session['user_id'] c.menu = genMenu(self) res = getUserData(c.name) c.lineData = [("Username", res[0]), ("Name", res[1]), ("Last name", res[2]), ("Email", res[3])] c.content = render("/line_by_line.html") + html.literal("<br />") c.header = ["All my projects"] proj = userProjects(c.name) c.rows = [] for x in proj: url_old = urlparse(request.url) url = url_old.scheme +'://' + url_old.netloc + getProjectUrl(x[0]) c.rows.append((link_to(x[0], url),)) c.style = "width:70%; text-align: left" #XXX: move css to templates c.content += render("/table.html") return render("/temp.html")
def get_fork_name(): repo_name = action_params return _('fork name ') + str( link_to(action_params, url( 'summary_home', repo_name=repo_name, )))
def options_td(col_num, i, item): # XXX This module can't depend on 'app_globals' or 'url' or # external data. Define data within this method or class or # in a base class. # Could use HTML.a() instead of link_to(). u = url("/tickets/view", ticket_id=item["id"]) a = link_to(item["options"], u) return HTML.td(a)
def _dataset_link(package_or_package_dict): if isinstance(package_or_package_dict, dict): name = package_or_package_dict['name'] else: name = package_or_package_dict.name text = dataset_display_name(package_or_package_dict) return tags.link_to( text, h.url_for(controller='package', action='read', id=name))
def postHeaderCallback(self, thread, post, userInst): result = '' if g.OPT.hlAnonymizedPosts and post.uidNumber == 0: result = '<b class="signature">%s</b>' % link_to( _("FA"), h.url_for('static', page='finalAnonymity'), target="_blank") return result
def threadPanelCallback(self, thread, userInst): #result = self.postPanelCallback(thread, thread, userInst) result = '' if g.OPT.enableFinalAnonymity and (not userInst.Anonymous and thread.uidNumber == c.uidNumber): result += link_to(_("[FA]"), h.url_for('anonymize', post=thread.id)) return result
def render(self, **kwargs): return tags.link_to( self.field.label(), self.field.parent.active_request.route_url( self.field.name[1:], model=self.field.model.__class__.__name__, id=self.field.model.id, ) )
class SheetsCrudController(FilterCrudRestController): model = Sheet __table_options__ = { '__omit_fields__': [ 'id', 'description', 'event_id', 'event', 'teacher', '_teacher', 'teacher_id', '_url', '_start_time', '_end_time', ], '__field_order__': [ 'sheet_id', 'name', 'public', 'start_time', 'end_time', 'assignments', ], '__search_fields__': ['id', 'sheet_id', 'name', ('assignments', 'assignment_id')], '__xml_fields__': ['assignments'], 'start_time': lambda filler, obj: \ obj.start_time.strftime('%c'), 'end_time': lambda filler, obj: \ obj.end_time.strftime('%c'), 'assignments': lambda filler, obj: \ ', '.join(link_to(ass.name, '../assignments/%d/edit' % ass.id) \ for ass in obj.assignments), '__base_widget_args__': {'sortList': [[1, 0]]}, } __form_options__ = { '__omit_fields__': ['id', '_url', 'assignments', 'teacher', '_teacher'], '__hide_fields__': ['event'], '__field_order__': [ 'id', 'sheet_id', 'name', 'description', 'public', '_start_time', '_end_time', ], '__field_widget_args__': { '_start_time': { 'help_text': u'Leave empty to use value from event', }, '_end_time': { 'help_text': u'Leave empty to use value from event', }, 'sheet_id': { 'label': u'Sheet Id', 'help_text': u'This id will be part of the url and has to be unique for the parent event', }, 'public': { 'help_text': u'Make sheet visible for students', }, }, '__require_fields__': ['sheet_id'], }
def get_pull_request(self): pull_request_id = self.action_params if self.is_deleted(): repo_name = self.user_log.repository_name else: repo_name = self.user_log.repository.repo_name return link_to( _('Pull request #%s') % pull_request_id, url('pullrequest_show', repo_name=repo_name, pull_request_id=pull_request_id))
def webmaster_email(text=None): """ E-mail link for the conference contact. Renders a link to the committee; optionally takes a text, which will be the text of the anchor (defaults to the e-mail address). """ email = lca_info['webmaster_email'] if text == None: text = email return link_to(text, 'mailto:' + email)
def get_pull_request(): pull_request_id = action_params deleted = user_log.repository is None if deleted: repo_name = user_log.repository_name else: repo_name = user_log.repository.repo_name return link_to(_('Pull request #%s') % pull_request_id, url('pullrequest_show', repo_name=repo_name, pull_request_id=pull_request_id))
def logout(self): if session.get('identity'): # Update last logged in user = meta.Session.query(User).filter_by(username=session['identity'].username).filter_by(password=session['identity'].password).first() user.lastlogin = datetime.now() meta.Session.commit() del session['identity'] session.save() return "You have successfully logged out<br /><br />%s" % link_to("Log back in?", url_for(controller="account", action="login"))
def linked_organization(org): organization = helpers.get_organization(org) if organization: return tags.literal(u'{icon} {link}'.format( icon=helpers.icon_html( organization['image_display_url'], alt='', inline=False), link=tags.link_to(organization['title'], url_for( controller='organization', action='read', id=organization['name'])))) return 'Not Existed'
def threadInfoCallback(self, thread, userInst): ns = self.namespace() result = '' if not userInst.Anonymous: tags = ns.UserTag.getPostTags(thread.id, userInst.uidNumber) result = " " for t in tags: result += ("%s ") % link_to("/$%s/" % t.tag, h.url_for('boardBase', board='$' + t.tag), title=t.comment) return result
def __call__(self, repo_name, rev, paths): if isinstance(paths, str): paths = safe_unicode(paths) url_l = [ link_to( repo_name, url('files_home', repo_name=repo_name, revision=rev, f_path='')) ] paths_l = paths.split('/') for cnt, p in enumerate(paths_l): if p != '': url_l.append( link_to( p, url('files_home', repo_name=repo_name, revision=rev, f_path='/'.join(paths_l[:cnt + 1])))) return literal('/'.join(url_l))
def get_pull_request(): pull_request_id = action_params deleted = user_log.repository is None if deleted: repo_name = user_log.repository_name else: repo_name = user_log.repository.repo_name return link_to( _('Pull request #%s') % pull_request_id, url('pullrequest_show', repo_name=repo_name, pull_request_id=pull_request_id))
def link_to_ref(repo_name, ref_type, ref_name, rev=None): """ Return full markup for a href to changeset_home for a changeset. If ref_type is branch it will link to changelog. ref_name is shortened if ref_type is 'rev'. if rev is specified show it too, explicitly linking to that revision. """ txt = short_ref(ref_type, ref_name) if ref_type == 'branch': u = url('changelog_home', repo_name=repo_name, branch=ref_name) else: u = url('changeset_home', repo_name=repo_name, revision=ref_name) l = link_to(repo_name + '#' + txt, u) if rev and ref_type != 'rev': l = literal( '%s (%s)' % (l, link_to(short_id(rev), url('changeset_home', repo_name=repo_name, revision=rev)))) return l
class TeamsCrudController(FilterCrudRestController): model = Team __table_options__ = { #'__omit_fields__': ['lesson_id'], '__field_order__': ['id', 'name', 'lesson_id', 'lesson', 'members', 'email'], '__search_fields__': ['id', 'lesson_id', 'name'], '__xml_fields__': ['lesson', 'members', 'email'], 'lesson': lambda filler, obj: \ link_to(obj.lesson.name, '../lessons/%d/edit' % obj.lesson.id), 'members': lambda filler, obj: \ ', '.join(link_to(student.display_name, '../students/%d/edit' % student.id) \ for student in obj.members), 'email': _email_team, '__base_widget_args__': {'sortList': [[3, 0], [1, 0]]}, } __form_options__ = { '__omit_fields__': ['id'], '__field_order__': ['id', 'name', 'lesson', 'members'], '__dropdown_field_names__': ['user_name', '_name', 'name', 'title'], }
def lnk(rev, repo_name): if isinstance(rev, BaseChangeset): lbl = 'r%s:%s' % (rev.revision, rev.short_id) _url = url('changeset_home', repo_name=repo_name, revision=rev.raw_id) title = tooltip(rev.message) else: lbl = '%s' % rev _url = '#' title = _('Changeset not found') return link_to(lbl, _url, title=title, class_='tooltip',)
def usersRequests(self): checkLogin() c.site = "User requests" c.name = session['project_id'] c.menu = genMenu(self) p = Project() p.load(c.name, getConfig()) c.header = ('Login', 'EMail', 'Accept as member', "Decline") c.rows = [(x[0], mail_to(x[1]), link_to("Accept", \ url(controller="project", action='requestAccept', id = x[0])), \ link_to("Decline", \ url(controller="project", action='requestDecline', id = x[0]))) \ for x in p.getRequests()] c.style = "width: 70%; text-align: center;" c.content = render("/table.html") return render("/temp.html")
def threadPanelCallback(self, thread, userInst): result = self.postPanelCallback(thread, thread, userInst) """ if userInst.isAdmin() and userInst.canManageUsers(): if post.uidNumber: result += link_to(_("[User]"), h.url_for('hsUserEditAttempt', pid = thread.id)) if post.ip: result += link_to(_("[IP Ban]"), h.url_for('hsIpBanAttempt', pid = thread.id)) """ if c.userInst.isAdmin() and c.userInst.canManageMappings(): result += link_to( _("[Tags]"), h.url_for('hsMappings', act='show', id=thread.id)) if c.userInst.isAdmin() and c.userInst.canManageMappings(): if thread.pinned: result += link_to( _("[Unpin]"), h.url_for('hsPin', act='unpin', id=thread.id)) else: result += link_to(_("[Pin]"), h.url_for('hsPin', act='pin', id=thread.id)) return result
def get_pull_request(): from kallithea.model.db import PullRequest pull_request_id = action_params nice_id = PullRequest.make_nice_id(pull_request_id) deleted = user_log.repository is None if deleted: repo_name = user_log.repository_name else: repo_name = user_log.repository.repo_name return link_to(_('Pull request %s') % nice_id, url('pullrequest_show', repo_name=repo_name, pull_request_id=pull_request_id))
def ogdch_list_user(user, maxlength=0): """display user in user list""" user_memberships = user.get('memberships', []) memberships_display = [] if not user.get('sysadmin'): for role in user_memberships: memberships_display.append( tags.link_to( role.capacity.capitalize() + ": " + get_localized_value_for_display( role.organization.title), # noqa url_for('organization_read', action='read', id=role.organization.name))) # noqa display_email = user.get('email') if not display_email: display_email = '' return { 'link': tags.link_to(user['name'], url_for('user.read', id=user['name'])), 'email': display_email, 'userroles': memberships_display, }
def get_title(self): current_ordering = request.GET.get("order_by") if current_ordering == self.options["sort_field"] and not request.GET.get("desc"): desc = 1 else: desc = 0 new_params = dict(request.GET) if desc: new_params["desc"] = 1 else: new_params.pop("desc", None) new_params["order_by"] = self.options["sort_field"] return link_to(self._title_, url=url(request.path_url, params=new_params))
def get_title(self): current_ordering = request.GET.get('order_by') if current_ordering == self.options['sort_field'] and not request.GET.get('desc'): desc = 1 else: desc = 0 new_params = dict(request.GET) if desc: new_params['desc'] = 1 else: new_params.pop('desc', None) new_params['order_by'] = self.options['sort_field'] return link_to(self._title_, url=url(request.path_url, params=new_params))
def get_pull_request(): from kallithea.model.db import PullRequest pull_request_id = action_params nice_id = PullRequest.make_nice_id(pull_request_id) deleted = user_log.repository is None if deleted: repo_name = user_log.repository_name else: repo_name = user_log.repository.repo_name return link_to( _('Pull request %s') % nice_id, url('pullrequest_show', repo_name=repo_name, pull_request_id=pull_request_id))
def helper_linked_user(user, maxlength=0, avatar=20): """ Return user as HTML item """ if not isinstance(user, model.User): user_name = unicode(user) user = model.User.get(user_name) if not user: return user_name if user: name = user.name if model.User.VALID_NAME.match(user.name) else user.id icon = _user_image(user, avatar) displayname = user.display_name if maxlength and len(user.display_name) > maxlength: displayname = displayname[:maxlength] + '...' return icon + u' ' + link_to( displayname, helpers.url_for(controller='user', action='read', id=name), class_='')
def helper_linked_user(user, maxlength=0, avatar=20): """ Return user as HTML item """ if helper_is_pseudo(user): return user if not isinstance(user, model.User): user_name = unicode(user) user = model.User.get(user_name) if not user: return user_name if user: name = user.name if model.User.VALID_NAME.match(user.name) else user.id icon = _user_image(user, avatar) displayname = user.display_name if maxlength and len(user.display_name) > maxlength: displayname = displayname[:maxlength] + '...' return icon + u' ' + link_to(displayname, helpers.url_for(controller='user', action='read', id=name), class_='')
def img_fixups(content, queueid, allowimgs, richformat): "Replace the CID links in Queued messages" html = local_fromstring(content) for element, attribute, link, _ in iterlinks(html): if not link.startswith('cid:'): if not allowimgs and attribute == 'src': element.attrib['src'] = '%simgs/blocked.gif' % media_url() element.attrib['title'] = link if richformat: flash(ugettext('This message contains external ' 'images, which have been blocked. ') + literal(link_to(ugettext('Display images'), url('queue-preview-with-imgs', queueid=queueid)))) else: imgname = link.replace('cid:', '') element.attrib['src'] = url('queue-preview-img', imgid=imgname.replace('/', '__xoxo__'), queueid=queueid) return tostring(html)
def repo_link(groups_and_repos): """ Makes a breadcrumbs link to repo within a group joins » on each group to create a fancy link ex:: group >> subgroup >> repo :param groups_and_repos: :param last_url: """ groups, just_name, repo_name = groups_and_repos last_url = url('summary_home', repo_name=repo_name) last_link = link_to(just_name, last_url) def make_link(group): return link_to(group.name, url('repos_group_home', group_name=group.group_name)) return literal(' » '.join(map(make_link, groups) + ['<span>%s</span>' % last_link]))
def _url_func(changeset): author = escape(changeset.author) date = changeset.date message = escape(changeset.message) tooltip_html = ("<b>Author:</b> %s<br/>" "<b>Date:</b> %s</b><br/>" "<b>Message:</b> %s") % (author, date, message) lnk_format = show_id(changeset) uri = link_to( lnk_format, url('changeset_home', repo_name=repo_name, revision=changeset.raw_id), style=get_color_string(changeset.raw_id), **{'data-toggle': 'popover', 'data-content': tooltip_html} ) uri += '\n' return uri
def users(self): checkLogin() c.site = "User administration" c.name = session['project_id'] c.menu = genMenu(self) p = Project() p.load(c.name, getConfig()) c.header = ('Login', 'EMail', "Remove?") c.rows = [(x[0], mail_to(x[3]), link_to("Remove", \ url(controller="project", action='userRemove', id = x[0]), \ confirm="Are You sure?")) \ for x in p.getUsers()] c.style = "width: 70%; text-align: center;" c.content = render("/table.html") return render("/temp.html")
def _url_func(changeset): author = escape(changeset.author) date = changeset.date message = escape(changeset.message) tooltip_html = ("<b>Author:</b> %s<br/>" "<b>Date:</b> %s</b><br/>" "<b>Message:</b> %s") % (author, date, message) lnk_format = show_id(changeset) uri = link_to(lnk_format, url('changeset_home', repo_name=repo_name, revision=changeset.raw_id), style=get_color_string(changeset.raw_id), **{ 'data-toggle': 'popover', 'data-content': tooltip_html }) uri += '\n' return uri
def myProjects(self): checkLogIn(session) c.site = "Projects" c.name = session['user_id'] c.menu = genMenu(self) c.header = ["Projects belong to me"] #XXX get user admin projects c.rows = [] for x in getOwnedProject(c.name): url_old = urlparse(request.url) url = url_old.scheme +'://' + url_old.netloc + getProjectUrl(x[0]) c.rows.append((link_to(x[0], url),)) c.style = "width:70%; text-align: left" #XXX css to templates c.content = render("/table.html") return render("/temp.html")
def projects(self): checkLogIn(session) c.site = "User information" c.name = session['user_id'] c.menu = genMenu(self) c.header = ["All my projects"] proj = userProjects(c.name) c.rows = [] for x in proj: url_old = urlparse(request.url) url = url_old.scheme +'://' + url_old.netloc + getProjectUrl(x[0]) c.rows.append((link_to(x[0], url),)) c.style = "width:70%; text-align: left" c.content = render("/table.html") return render("/temp.html")