当前位置: 首页>>代码示例>>Python>>正文


Python resource.get_resource_url函数代码示例

本文整理汇总了Python中trac.resource.get_resource_url函数的典型用法代码示例。如果您正苦于以下问题:Python get_resource_url函数的具体用法?Python get_resource_url怎么用?Python get_resource_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_resource_url函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: expand_macro

    def expand_macro(self, formatter, name, content):
        env = formatter.env
        req = formatter.req
        if not 'VOTE_VIEW' in req.perm:
            return
        # Simplify function calls.
        format_author = partial(Chrome(self.env).format_author, req)
        if not content:
            args = []
            compact = None
            kw = {}
            top = 5
        else:
            args, kw = parse_args(content)
            compact = 'compact' in args and True
            top = as_int(kw.get('top'), 5, min=0)

        if name == 'LastVoted':
            lst = tag.ul()
            for i in self.get_votes(req, top=top):
                resource = Resource(i[0], i[1])
                # Anotate who and when.
                voted = ('by %s at %s'
                         % (format_author(i[3]),
                            format_datetime(to_datetime(i[4]))))
                lst(tag.li(tag.a(
                    get_resource_description(env, resource, compact and
                                             'compact' or 'default'),
                    href=get_resource_url(env, resource, formatter.href),
                    title=(compact and '%+i %s' % (i[2], voted) or None)),
                    (not compact and Markup(' %s %s' % (tag.b('%+i' % i[2]),
                                                        voted)) or '')))
            return lst

        elif name == 'TopVoted':
            realm = kw.get('realm')
            lst = tag.ul()
            for i in self.get_top_voted(req, realm=realm, top=top):
                if 'up-only' in args and i[2] < 1:
                    break
                resource = Resource(i[0], i[1])
                lst(tag.li(tag.a(
                    get_resource_description(env, resource, compact and
                                             'compact' or 'default'),
                    href=get_resource_url(env, resource, formatter.href),
                    title=(compact and '%+i' % i[2] or None)),
                    (not compact and ' (%+i)' % i[2] or '')))
            return lst

        elif name == 'VoteList':
            lst = tag.ul()
            resource = resource_from_path(env, req.path_info)
            for i in self.get_votes(req, resource, top=top):
                vote = ('at %s' % format_datetime(to_datetime(i[4])))
                lst(tag.li(
                    compact and format_author(i[3]) or
                    Markup(u'%s by %s %s' % (tag.b('%+i' % i[2]),
                                             tag(format_author(i[3])), vote)),
                    title=(compact and '%+i %s' % (i[2], vote) or None)))
            return lst
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:60,代码来源:__init__.py

示例2: filter_stream

 def filter_stream(self, req, method, filename, stream, data):
     if filename != 'report_view.html':
         return stream
     page_name = 'report:%s' % data['context'].resource.id
     page_label = data['title']
     page = WikiPage(self.env, page_name)
     if 'WIKI_MODIFY' not in req.perm(page.resource):
         return stream
     text = '= Snapshot of [%s %s]: =\n' % (page_name, page_label)
     text += '{{{#!QueryResults\n'
     cols = [header['col'] for header in data.get('header_groups', [[]])[0] if not header['hidden']]
     cols_work = [t for t in cols]  # copy
     if 'ticket' in cols_work:
         cols_work[cols_work.index('ticket')] = 'id'  # replace 'ticket' to 'id'
     text += '||= href =||= %s\n' % ' =||= '.join(cols_work)
     for  groupindex, row_group in data.get('row_groups', []):
         text += '|| group: %s\n' % groupindex
         for row in row_group:
             row = row['cell_groups'][0]
             ticket = {}
             for value in row:
                 ticket[value['header']['col']] = value['value']
             ticket['href'] = get_resource_url(self.env, Resource('ticket', ticket.get('ticket', 0)), self.env.href)
             text += '|| %s || %s\n' % (ticket['href'],
                 ' || '.join([self.formatter(col, ticket[col]) for col in cols]))
     text += '}}}'
     div = tag.div(tag.input(value='Save as wiki:', type='submit'),
                   tag.input(name='action', value='edit', type='hidden'),
                       tag.input(name='text', value=text, type='hidden'),
                   tag.input(name='page', value=page_name))
     return stream | Transformer('//div[@id="content"]/div[@class="buttons"]') \
         .append(tag.form(div, action=get_resource_url(self.env, Resource('wiki'), self.env.href)))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:32,代码来源:query.py

示例3: process_request

    def process_request(self, req):
        """Process the request."""

        id = int(req.args.get('id'))

        req.perm('ticket', id).require('TICKET_VIEW')

        if 'TICKET_REMINDER_MODIFY' not in req.perm and \
                'TICKET_ADMIN' not in req.perm:
            raise PermissionError('TICKET_REMINDER_MODIFY',
                                  req.perm._resource, self.env)

        ticket = Ticket(self.env, id)

        if 'cancel' in req.args:
            req.redirect(get_resource_url(self.env, ticket.resource, req.href))

        ticket_name = get_resource_name(self.env, ticket.resource)
        ticket_url = get_resource_url(self.env, ticket.resource, req.href)
        add_link(req, 'up', ticket_url, ticket_name)
        add_ctxtnav(req, _('Back to %(ticket)s', ticket=ticket_name),
                    ticket_url)

        add_stylesheet(req, 'ticketreminder/css/ticketreminder.css')

        if req.args['action'] == "addreminder":
            return self._process_add(req, ticket)
        elif req.args['action'] == "deletereminder":
            return self._process_delete(req, ticket)
        else:
            raise ValueError('Unknown action "%s"' % (req.args['action'],))
开发者ID:trac-hacks,项目名称:trac-ticketreminder,代码行数:31,代码来源:api.py

示例4: post_process_request

    def post_process_request(self, req, template, data, content_type):
        if req.path_info.startswith('/ticket/'):
            # In case of an invalid ticket, the data is invalid
            if not data:
                return template, data, content_type
            tkt = data['ticket']
            self.pm.check_component_enabled(self, pid=tkt.pid)
            links = TicketLinks(self.env, tkt)

            # Add link to depgraph if needed
            if links:
                add_ctxtnav(req, _('Depgraph'), req.href.depgraph(get_resource_url(self.env, tkt.resource)))

            for change in data.get('changes', {}):
                if not change.has_key('fields'):
                    continue
                for field, field_data in change['fields'].iteritems():
                    if field in self.fields:
                        vals = {}
                        for i in ('new', 'old'):
                            if isinstance(field_data[i], basestring):
                                val = field_data[i].strip()
                            else:
                                val = ''
                            if val:
                                vals[i] = set([int(n) for n in val.split(',')])
                            else:
                                vals[i] = set()
                        add = vals['new'] - vals['old']
                        sub = vals['old'] - vals['new']
                        elms = tag()
                        if add:
                            elms.append(
                                tag.em(u', '.join([unicode(n) for n in sorted(add)]))
                            )
                            elms.append(u' added')
                        if add and sub:
                            elms.append(u'; ')
                        if sub:
                            elms.append(
                                tag.em(u', '.join([unicode(n) for n in sorted(sub)]))
                            )
                            elms.append(u' removed')
                        field_data['rendered'] = elms

        #add a link to generate a dependency graph for all the tickets in the milestone
        if req.path_info.startswith('/milestone/'):
            if not data or not 'milestone' in data:
                return template, data, content_type
            milestone=data['milestone']
            self.pm.check_component_enabled(self, pid=milestone.pid)
            add_ctxtnav(req, _('Depgraph'), req.href.depgraph(get_resource_url(self.env, milestone.resource)))


        return template, data, content_type
开发者ID:lexqt,项目名称:EduTracMasterTickets,代码行数:55,代码来源:web_ui.py

示例5: test_resource_repository

    def test_resource_repository(self):
        res = Resource('repository', 'testrepo')
        self.assertEqual('Repository testrepo',
                         get_resource_description(self.env, res))
        self.assertEqual('/trac.cgi/browser/testrepo',
                         get_resource_url(self.env, res, self.env.href))

        res = Resource('repository', '')  # default repository
        self.assertEqual('Default repository',
                         get_resource_description(self.env, res))
        self.assertEqual('/trac.cgi/browser',
                         get_resource_url(self.env, res, self.env.href))
开发者ID:exocad,项目名称:exotrac,代码行数:12,代码来源:api.py

示例6: test_resource_changeset

    def test_resource_changeset(self):
        res = Resource('changeset', '42')
        self.assertEqual('Changeset 42', get_resource_description(self.env, res))
        self.assertEqual('/trac.cgi/changeset/42',
                         get_resource_url(self.env, res, self.env.href))

        repo = Resource('repository', 'repo')
        res = Resource('changeset', '42', parent=repo)
        self.assertEqual('Changeset 42 in repo',
                         get_resource_description(self.env, res))
        self.assertEqual('/trac.cgi/changeset/42/repo',
                         get_resource_url(self.env, res, self.env.href))
开发者ID:exocad,项目名称:exotrac,代码行数:12,代码来源:api.py

示例7: get_resource_url

 def get_resource_url(self, resource, href, form_realms=None, **kwargs):
     if self.wiki_page_link:
         page = WikiPage(self.env, resource.id)
         if page.exists:
             return get_resource_url(self.env, page.resource, href,
                                     **kwargs)
     return href.tags(unicode(resource.id), form_realms, **kwargs)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:7,代码来源:api.py

示例8: _get_absolute_url

    def _get_absolute_url(self, req, url):
        """ Generate an absolute url from the url with the special schemes
        {htdocs,chrome,ticket,wiki,source} simply return the url if given with
        {http,https,ftp} schemes.
        
        Examples:
            http://example.com/filename.ext
                ie. http://www.google.com/logo.jpg
            
            chrome://site/filename.ext
            htdocs://img/filename.ext
                note: `chrome` is an alias for `htdocs`
            
            ticket://number/attachment.pdf
                ie. ticket://123/specification.pdf
            
            wiki://WikiWord/attachment.jpg
            
            source://changeset/path/filename.ext
                ie. source://1024/trunk/docs/README
        """

        scheme, netloc, path, query, params, fragment = urlparse(url)

        if scheme in ('htdocs', 'chrome'):
            return req.abs_href.chrome(netloc + path)

        if scheme in ('source',):
            return req.abs_href.export(netloc + path)

        if scheme in ('wiki','ticket'):
            resource = Resource(scheme, netloc).child('attachment', path)
            return get_resource_url(self.env, resource, req.abs_href, format='raw')

        return url
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:35,代码来源:macro.py

示例9: outline_tree

def outline_tree(env, ol, outline, context, active, min_depth, max_depth):
    if min_depth > max_depth:
        min_depth, max_depth = max_depth, min_depth
    max_depth = min(6, max_depth)
    min_depth = max(1, min_depth)
    previous_depth = min_depth
    
    stack = [None] * (max_depth + 1)
    # stack of (<element for new sublists>, <element for new items>)
    stack[previous_depth] = (None, ol)
    
    for depth, anchor, heading in outline:
        if min_depth <= depth <= max_depth:
            for d in range(previous_depth, depth):
                li, ol = stack[d]
                if not li:
                    li = tag.li()
                    ol.append(li)
                    stack[d] = (li, ol)
                new_ol = tag.ol()
                li.append(new_ol)
                stack[d+1] = (None, new_ol)
            href = get_resource_url(env, context.resource, context.href)
            if href.endswith(context.req.path_info):
                href = ''
            href += '#' + anchor
            li, ol = stack[depth]
            li = tag.li(tag.a(Markup(heading), href=href),
                        class_=active and 'active' or None)
            ol.append(li)
            stack[depth] = (li, ol)
            previous_depth = depth
    return stack[min_depth][0]
开发者ID:naokits,项目名称:adminkun_viewer_old,代码行数:33,代码来源:macro.py

示例10: get_resource_description

 def get_resource_description(self, resource, format=None, **kwargs):
     env = self.env
     href = kwargs.get('href')
     if resource.parent is None:
         return _("Unparented form %(id)s", id=resource.id)
     parent_name = get_resource_name(env, resource.parent)
     parent_url = href and \
                  get_resource_url(env, resource.parent, href) or None
     parent = parent_url is not None and \
              tag.a(parent_name, href=parent_url) or parent_name
     # DEVEL: resource description not implemented yet
     #if format == 'summary':
     #    return Form(self.env, resource).description
     if resource.id:
         if format == 'compact':
             return _("Form %(form_id)s (%(parent)s)", form_id=resource.id,
                      parent=get_resource_shortname(env, resource.parent))
         # TRANSLATOR: Most verbose title, i.e. for form history page
         return tag_("Form %(form_id)s (in %(parent)s)",
                     form_id=resource.id, parent=parent)
     else:
         # TRANSLATOR: Title printed i.e. in form select page
         if format == 'compact':
             return tag_("Forms (%(parent)s)", parent=parent)
         return tag_("Forms in %(parent)s", parent=parent)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:25,代码来源:api.py

示例11: _format_tagged

 def _format_tagged(self, formatter, target, label):
     if label:
         href = formatter.context.href
         url = get_resource_url(self.env, Resource('tag', target), href)
         return tag.a(label, href=url)
     return render_resource_link(self.env, formatter.context,
                                 Resource('tag', target))
开发者ID:okamototk,项目名称:kanonconductor,代码行数:7,代码来源:wiki.py

示例12: _result

 def _result(doc):
     changed = doc.changed
     href = get_resource_url(self.env, doc.resource, req.href)
     title = doc.title or get_resource_shortname(self.env, doc.resource)
     author = ", ".join(doc.author or [])
     excerpt = doc.oneline or ""
     return (href, title, changed, author, excerpt)
开发者ID:CGI-define-and-primeportal,项目名称:trac-plugin-solr,代码行数:7,代码来源:fulltextsearch.py

示例13: _get_build_data

def _get_build_data(env, req, build, repos_name=None):
    chgset_url = ''
    if repos_name:
        chgset_resource = get_chgset_resource(env, repos_name, build.rev)
        chgset_url = get_resource_url(env, chgset_resource, req.href)
    platform = TargetPlatform.fetch(env, build.platform)
    data = {'id': build.id, 'name': build.slave, 'rev': build.rev,
            'status': _status_label[build.status],
            'platform': getattr(platform, 'name', 'unknown'),
            'cls': _status_label[build.status].replace(' ', '-'),
            'href': req.href.build(build.config, build.id),
            'chgset_href': chgset_url}
    if build.started:
        data['started'] = format_datetime(build.started)
        data['started_delta'] = pretty_timedelta(build.started)
        data['duration'] = pretty_timedelta(build.started)
    if build.stopped:
        data['stopped'] = format_datetime(build.stopped)
        data['stopped_delta'] = pretty_timedelta(build.stopped)
        data['duration'] = pretty_timedelta(build.stopped, build.started)
    data['slave'] = {
        'name': build.slave,
        'ipnr': build.slave_info.get(Build.IP_ADDRESS),
        'os_name': build.slave_info.get(Build.OS_NAME),
        'os_family': build.slave_info.get(Build.OS_FAMILY),
        'os_version': build.slave_info.get(Build.OS_VERSION),
        'machine': build.slave_info.get(Build.MACHINE),
        'processor': build.slave_info.get(Build.PROCESSOR)
    }
    return data
开发者ID:hefloryd,项目名称:bitten,代码行数:30,代码来源:web_ui.py

示例14: get_list_pages

def get_list_pages(request, dbp, obj, resource):
    require_permission(request.req, resource, dbp.env)

    artifact_id = request.req.args.get('artifact', None)
    if artifact_id is None:
        raise Exception("No artifact was specified.")
    dbp.load_artifact(artifact_id)
    artifact = dbp.pool.get_item(artifact_id)

    results = []
    for pagename, page_version_id, ref_count in dbp.get_wiki_page_ref_counts(artifact):
        page = WikiPage(dbp.env, pagename)

        results.append(
            {'href': get_resource_url(dbp.env, page.resource, request.req.href),
             'title': pagename,
             'date': user_time(request.req, format_datetime, page.time),
             'author': page.author,
             'excerpt': shorten_result(page.text)}
        )

    data = {
        'context': Context.from_request(request.req, resource),
        'artifact': artifact,
        'results': results,
    }
    return 'list_pages.html', data, None
开发者ID:filipefigcorreia,项目名称:TracAdaptiveSoftwareArtifacts,代码行数:27,代码来源:views.py

示例15: render_property_diff

    def render_property_diff(self, req, ticket, field, old, new,
                              resource_new=None):
        "Version for Trac 0.11"
        rendered = None
        # per type special rendering of diffs
        type_ = None
        for f in ticket.fields:
            if f['name'] == field:
                type_ = f['type']
                break
        if type_ == 'checkbox':
            rendered = new == '1' and "set" or "unset"
        elif type_ == 'textarea':
            if not resource_new:
                rendered = _('modified')
            else:
                href = get_resource_url(self.env, resource_new, req.href,
                                        action='diff')
                rendered = tag('modified (', tag.a('diff', href=href), ')')

        # per name special rendering of diffs
        old_list, new_list = None, None
        render_elt = lambda x: x
        sep = ', '
        if field == 'cc':
            chrome = Chrome(self.env)
            old_list, new_list = chrome.cc_list(old), chrome.cc_list(new)
            if not (Chrome(self.env).show_email_addresses or
                    'EMAIL_VIEW' in req.perm(resource_new or ticket.resource)):
                render_elt = obfuscate_email_address
        elif field == 'keywords':
            old_list, new_list = (old or '').split(), new.split()
            sep = ' '
        if (old_list, new_list) != (None, None):
            added = [tag.em(render_elt(x)) for x in new_list
                     if x not in old_list]
            remvd = [tag.em(render_elt(x)) for x in old_list
                     if x not in new_list]
            added = added and tag(separated(added, sep), " added")
            remvd = remvd and tag(separated(remvd, sep), " removed")
            if added or remvd:
                rendered = tag(added, added and remvd and '; ', remvd)
                return rendered
        if field in ('reporter', 'owner'):
            if not (Chrome(self.env).show_email_addresses or
                    'EMAIL_VIEW' in req.perm(resource_new or ticket.resource)):
                old = obfuscate_email_address(old)
                new = obfuscate_email_address(new)
        # Added by MS
        if field == 'attachment':
            rendered = tag(tag.em(new), " added")
        # changed 'if' to 'elif':
        elif old and not new:
            rendered = tag(tag.em(old), " deleted")
        elif new and not old:
            rendered = tag("set to ", tag.em(new))
        elif old and new:
            rendered = tag("changed from ", tag.em(old),
                            " to ", tag.em(new))
        return rendered
开发者ID:gaod,项目名称:trac-watchlistplugin,代码行数:60,代码来源:__init__.py


注:本文中的trac.resource.get_resource_url函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。