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


Python TagSystem.get_tags方法代码示例

本文整理汇总了Python中tractags.api.TagSystem.get_tags方法的典型用法代码示例。如果您正苦于以下问题:Python TagSystem.get_tags方法的具体用法?Python TagSystem.get_tags怎么用?Python TagSystem.get_tags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tractags.api.TagSystem的用法示例。


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

示例1: _page_tags

# 需要导入模块: from tractags.api import TagSystem [as 别名]
# 或者: from tractags.api.TagSystem import get_tags [as 别名]
    def _page_tags(self, req):
        pagename = req.args.get('page', 'WikiStart')

        tag_system = TagSystem(self.env)
        resource = Resource('wiki', pagename)
        tags = sorted(tag_system.get_tags(req, resource))
        return tags
开发者ID:okamototk,项目名称:kanonconductor,代码行数:9,代码来源:wiki.py

示例2: _update_tags

# 需要导入模块: from tractags.api import TagSystem [as 别名]
# 或者: from tractags.api.TagSystem import get_tags [as 别名]
    def _update_tags(self, req, page):
        tag_system = TagSystem(self.env)
        newtags = tag_system.split_into_tags(req.args.get('tags', ''))
        oldtags = tag_system.get_tags(req, page.resource)

        if oldtags != newtags:
            tag_system.set_tags(req, page.resource, newtags)
            return True
        return False
开发者ID:okamototk,项目名称:kanonconductor,代码行数:11,代码来源:wiki.py

示例3: post_process_request

# 需要导入模块: from tractags.api import TagSystem [as 别名]
# 或者: from tractags.api.TagSystem import get_tags [as 别名]
    def post_process_request(self, req, template, data, content_type):
        if data and req.path_info == '/timeline' and \
                'TAGS_VIEW' in req.perm(Resource('tags')):

            def realm_handler(_, node, context):
                return query.match(node, [context.realm])

            query_str = req.args.get(self.key)
            if query_str is None and req.args.get('format') != 'rss':
                query_str = req.session.get('timeline.%s' % self.key)
            else:
                query_str = (query_str or '').strip()
                # Record tag query expression between visits.
                req.session['timeline.%s' % self.key] = query_str

            if data.get('events') and query_str:
                tag_system = TagSystem(self.env)
                try:
                    query = Query(query_str,
                                  attribute_handlers=dict(realm=realm_handler)
                            )
                except InvalidQuery, e:
                    add_warning(req, _("Tag query syntax error: %s"
                                       % to_unicode(e)))
                else:
                    all_realms = tag_system.get_taggable_realms(req.perm)
                    query_realms = set()
                    for m in REALM_RE.finditer(query.as_string()):
                        query_realms.add(m.group(1))
                    # Don't care about resources from non-taggable realms.
                    realms = not query_realms and all_realms or \
                             query_realms.intersection(all_realms)
                    events = []
                    self.log.debug("Filtering timeline events by tags '%s'",
                                   query_str)
                    for event in data['events']:
                        resource = event['data'][0]
                        if resource.realm in realms:
                            # Shortcut view permission checks here.
                            tags = tag_system.get_tags(None, resource)
                            if query(tags, context=resource):
                                events.append(event)
                    # Overwrite with filtered list.
                    data['events'] = events
            if query_str:
                # Add current value for next form rendering.
                data[self.key] = query_str
            elif self.key in req.session:
                del req.session[self.key]
开发者ID:kzhamaji,项目名称:TracTagsPlugin,代码行数:51,代码来源:web_ui.py

示例4: post_process_request

# 需要导入模块: from tractags.api import TagSystem [as 别名]
# 或者: from tractags.api.TagSystem import get_tags [as 别名]
 def post_process_request(self, req, template, data, content_type):
     if req.method == 'GET' and req.path_info.startswith('/wiki/') and \
             req.args.get('action') == 'edit' and \
             req.args.get('template') and 'tags' not in req.args:
         # Retrieve template resource to be queried for tags.
         template_page = WikiPage(self.env,''.join(
                                  [WikiModule.PAGE_TEMPLATES_PREFIX,
                                   req.args.get('template')]))
         if template_page and template_page.exists and \
                 'TAGS_VIEW' in req.perm(template_page.resource):
             ts = TagSystem(self.env)
             tags = sorted(ts.get_tags(req, template_page.resource))
             # Prepare tags as content for the editor field.
             tags_str = ' '.join(tags)
             self.env.log.debug("Tags retrieved from template: '%s'" \
                                % unicode(tags_str).encode('utf-8'))
             # DEVEL: More arguments need to be propagated here?
             req.redirect(req.href(req.path_info,
                                   action='edit', tags=tags_str,
                                   template=req.args.get('template')))
     return (template, data, content_type)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:23,代码来源:wiki.py

示例5: _get_stored_tags

# 需要导入模块: from tractags.api import TagSystem [as 别名]
# 或者: from tractags.api.TagSystem import get_tags [as 别名]
 def _get_stored_tags(self, req, resource):
     # Return tags associated to resource.
     tag_system = TagSystem(self.env)
     tags = tag_system.get_tags(req, resource)
     return sorted(tags)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:7,代码来源:tags.py

示例6: _get_stored_tags

# 需要导入模块: from tractags.api import TagSystem [as 别名]
# 或者: from tractags.api.TagSystem import get_tags [as 别名]
 def _get_stored_tags(self, req, download_id):
     tag_system = TagSystem(self.env)
     resource = Resource('downloads', download_id)
     tags = tag_system.get_tags(req, resource)
     return sorted(tags)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:7,代码来源:tags.py

示例7: WikiTagInterface

# 需要导入模块: from tractags.api import TagSystem [as 别名]
# 或者: from tractags.api.TagSystem import get_tags [as 别名]

#.........这里部分代码省略.........
        if req:
            self._update_tags(req, page, page.time)

    def wiki_page_changed(self, page, version, t, comment, author, ipnr):
        req = requests.get()
        if req:
            self._update_tags(req, page, page.time)

    def wiki_page_renamed(self, page, old_name):
        """Called when a page has been renamed (since Trac 0.12)."""
        self.log.debug("Moving wiki page tags from %s to %s",
                       old_name, page.name)
        req = MockReq()
        self.tag_system.reparent_tags(req, Resource('wiki', page.name),
                                      old_name)

    def wiki_page_deleted(self, page):
        # Page gone, so remove all records on it.
        delete_tags(self.env, page.resource, purge=True)

    def wiki_page_version_deleted(self, page):
        pass

    # Internal methods
    def _page_tags(self, req):
        pagename = req.args.get('page', 'WikiStart')
        version = req.args.get('version')
        tags_version = req.args.get('tags_version')

        page = WikiPage(self.env, pagename, version=version)
        resource = page.resource
        if version and not tags_version:
            tags_version = page.time
        tags = sorted(self.tag_system.get_tags(req, resource,
                                               when=tags_version))
        return tags

    def _redirect_listener(self, req, url, permanent):
        requests.reset()

    def _post_process_request_edit(self, req):
        # Retrieve template resource to be queried for tags.
        template_pagename = ''.join([WikiModule.PAGE_TEMPLATES_PREFIX,
                                     req.args.get('template')])
        template_page = WikiPage(self.env, template_pagename)
        if template_page.exists and \
                'TAGS_VIEW' in req.perm(template_page.resource):
            tags = sorted(self.tag_system.get_tags(req,
                                                   template_page.resource))
            # Prepare tags as content for the editor field.
            tags_str = ' '.join(tags)
            self.env.log.debug("Tags retrieved from template: '%s'",
                               unicode(tags_str).encode('utf-8'))
            # DEVEL: More arguments need to be propagated here?
            req.redirect(req.href(req.path_info,
                                  action='edit', tags=tags_str,
                                  template=req.args.get('template')))

    def _post_process_request_history(self, req, data):
        history = []
        page_histories = data.get('history', [])
        resource = data['resource']
        tags_histories = tag_changes(self.env, resource)

        for page_history in page_histories:
            while tags_histories and \
开发者ID:t-kenji,项目名称:trac-tags-plugin,代码行数:70,代码来源:wiki.py

示例8: _get_stored_tags

# 需要导入模块: from tractags.api import TagSystem [as 别名]
# 或者: from tractags.api.TagSystem import get_tags [as 别名]
 def _get_stored_tags(self, req, screenshot_id):
     tag_system = TagSystem(self.env)
     resource = Resource('screenshots', to_unicode(screenshot_id))
     tags = tag_system.get_tags(req, resource)
     return sorted(tags)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:7,代码来源:tags.py

示例9: HacksCache

# 需要导入模块: from tractags.api import TagSystem [as 别名]
# 或者: from tractags.api.TagSystem import get_tags [as 别名]
class HacksCache(Borg):
    _lock = threading.RLock()
    _initialized = False

    _hacks = dict()
    _types = dict()
    _releases = dict()

    def __init__(self, env):
        if self._initialized:
            self._log('already initialized')
            return
        else:
            env.log.debug('HacksCache %x: initializing' % id(self.__dict__))

        self._lock.acquire()

        self._env = env
        self._tag_system = TagSystem(env)
        self._req = FakeRequest(env)
        self.id = id(self.__dict__)

        self._rebuild_cache()

        self._initialized = True
        self._lock.release()
        self._log('initialization finished')

    def __del__(self):
        self._log('Aiiieeeee')

    def _rebuild_cache(self):
        """ Rebuild the cache. Caller MUST hold the lock! """
        self._log('rebuilding cache (initialized=%s)' % self._initialized)
        self._hacks = dict()
        self._types = dict()
        self._releases = dict()

        self._update_types()
        self._update_releases()

        query  = 'realm:wiki (%s) (%s)' % \
            (' or '.join(self._types), ' or '.join(self._releases))
        for h in self._query_tags(query):
            self._update_hack(h, False, False)

    def _log(self, message):
        self._env.log.debug('HacksCache %x: %s' % (self.id, message))

    def _query_tags(self, query):
        """ Helper to perform queries on cached tags system """
        return [ r.id for r, _ in self._tag_system.query(self._req, query) ]

    def _update_types(self):
        """ Get/update list of hack types """
        types = self._query_tags('realm:wiki type')
        keys = self._types.keys()

        # add types that have been added since last update
        for t in types:
            if t not in keys:
                self._types[t] = Tag(t, self._env, self._req, self._tag_system)

        # remove types that no longer exist
        for k in keys:
            if k not in types:
                del self._types[k]

    def _update_releases(self):
        """ Get/update list of Trac releases """
        releases = self._query_tags('realm:wiki release')
        keys = self._releases.keys()

        # add releases that have been added since last update
        for r in releases:
            if r not in keys:
                self._releases[r] = Tag(r, self._env, self._req, self._tag_system)

        # remove releases that no longer exist
        for k in keys:
            if k not in releases:
                del self._releases[k]

    def _update_hack(self, name, full_update = True, check_delete = True):
        """ Get/update/delete hack properties """
        if full_update:
            self._update_types()
            self._update_releases()

        delete = False
        if check_delete:
            page = WikiPage(self._env, name)
            if page.exists:
                tags = set(self._tag_system.get_tags(self._req, page.resource))
                if not (tags.intersection(self._types) and tags.intersection(self._releases)):
                    delete = True
            else:
                delete = True

        if delete:
#.........这里部分代码省略.........
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:103,代码来源:cache.py

示例10: _get_stored_tags

# 需要导入模块: from tractags.api import TagSystem [as 别名]
# 或者: from tractags.api.TagSystem import get_tags [as 别名]
 def _get_stored_tags(self, context, download_id):
     tag_system = TagSystem(self.env)
     resource = Resource(self.realm, download_id)
     tags = tag_system.get_tags(context.req, resource)
     return sorted(tags)
开发者ID:nagyistoce,项目名称:trac-downloads,代码行数:7,代码来源:tags.py


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