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


Python TagEngine.get_tags方法代码示例

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


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

示例1: render_listtags

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import get_tags [as 别名]
    def render_listtags(self, req, *tags, **kwargs):
        """ List tags. For backwards compatibility, can accept a list of tags.
            This will simply call ListTagged. Optional keyword arguments are
            tagspace=wiki, tagspaces=(wiki, ticket, ...) and shownames=true. """
        if tags:
            # Backwards compatibility
            return self.render_listtagged(req, *tags, **kwargs)

        page = self._current_page(req)
        engine = TagEngine(self.env)

        showpages = kwargs.get('showpages', None) or kwargs.get('shownames', 'false')

        if 'tagspace' in kwargs:
            tagspaces = [kwargs['tagspace']]
        else:
            tagspaces = kwargs.get('tagspaces', []) or \
                        list(TagEngine(self.env).tagspaces)

        out = StringIO()
        out.write('<ul class="listtags">\n')
        tag_details = {}
        for tag, names in sorted(engine.get_tags(tagspaces=tagspaces, detailed=True).iteritems()):
            href, title = engine.get_tag_link(tag)
            htitle = wiki_to_oneliner(title, self.env)
            out.write('<li><a href="%s" title="%s">%s</a> %s <span class="tagcount">(%i)</span>' % (href, title, tag, htitle, len(names)))
            if showpages == 'true':
                out.write('\n')
                out.write(self.render_listtagged(req, tag, tagspaces=tagspaces))
                out.write('</li>\n')

        out.write('</ul>\n')

        return out.getvalue()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:36,代码来源:macros.py

示例2: _update_tags

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import get_tags [as 别名]
    def _update_tags(self, req, page):
        newtags = set([t.strip() for t in
                      _tag_split.split(req.args.get('tags')) if t.strip()])
        wikitags = TagEngine(self.env).tagspace.wiki
        oldtags = wikitags.get_tags([page.name])

        if oldtags != newtags:
            wikitags.replace_tags(req, page.name, newtags)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:10,代码来源:web_ui.py

示例3: render_tagcloud

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import get_tags [as 别名]
    def render_tagcloud(self, req, smallest=10, biggest=20, tagspace=None, tagspaces=[]):
        """ Display a summary of all tags, with the font size reflecting the
            number of pages the tag applies to. Font size ranges from 10 to 22
            pixels, but this can be overridden by the smallest=n and biggest=n
            macro parameters. By default, all tagspaces are displayed, but this
            can be overridden with tagspaces=(wiki, ticket) or tagspace=wiki."""
        smallest = int(smallest)
        biggest = int(biggest)
        engine = TagEngine(self.env)
        # Get wiki tagspace
        if tagspace:
            tagspaces = [tagspace]
        else:
            tagspaces = tagspaces or engine.tagspaces
        cloud = {}

        for tag, names in engine.get_tags(tagspaces=tagspaces, detailed=True).iteritems():
            cloud[tag] = len(names)

        tags = cloud.keys()

        # No tags?
        if not tags: return ''

        # by_count maps tag counts to an index in the set of counts
        by_count = list(set(cloud.values()))
        by_count.sort()
        by_count = dict([(c, float(i)) for i, c in enumerate(by_count)])

        taginfo = self._tag_details({}, tags)
        tags.sort()
        rlen = float(biggest - smallest)
        tlen = float(len(by_count))
        scale = 1.0
        if tlen:
            scale = rlen / tlen
        out = StringIO()
        out.write('<ul class="tagcloud">\n')
        last = tags[-1]
        for tag in tags:
            if tag == last:
                cls = ' class="last"'
            else:
                cls = ''
            out.write('<li%s><a rel="tag" title="%s" style="font-size: %ipx" href="%s">%s</a> <span class="tagcount">(%i)</span></li>\n' % (
                       cls,
                       taginfo[tag][1],
                       smallest + int(by_count[cloud[tag]] * scale),
                       taginfo[tag][0],
                       tag,
                       cloud[tag]))
        out.write('</ul>\n')
        return out.getvalue()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:55,代码来源:macros.py

示例4: getDetails

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import get_tags [as 别名]
    def getDetails(self, req, hack):
        """ Fetch hack details. Returns dict with name, dependencies and
            description. """
        from tractags.api import TagEngine

        wikitags = TagEngine(self.env).tagspace.wiki
        tags = wikitags.get_tags(hack)
        types = self.getTypes()
        hacks = wikitags.get_tagged_names(types)

        dependencies = hacks.intersection(tags)
        href, htmllink, description = wikitags.name_details(hack)
        return {"name": hack, "dependencies": tuple(dependencies), "description": description}
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:15,代码来源:trachacks.py

示例5: _do_save

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import get_tags [as 别名]
    def _do_save(self, req, db, page):
        # This method is overridden so the user doesn't get "Page not modified"
        # exceptions when updating tags but not wiki content.
        from tractags.api import TagEngine
        if 'tags' in req.args:
            newtags = set([t.strip() for t in
                          _tag_split.split(req.args.get('tags')) if t.strip()])
            wikitags = TagEngine(self.env).tagspace.wiki
            oldtags = wikitags.get_tags([page.name])

            if oldtags != newtags:
                wikitags.replace_tags(req, page.name, newtags)
                # No changes, just redirect
                if req.args.get('text') == page.text:
                    req.redirect(self.env.href.wiki(page.name))
                    return
        return WikiModule._do_save(self, req, db, page)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:19,代码来源:web_ui.py

示例6: render_listtags

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import get_tags [as 别名]
    def render_listtags(self, req, *tags, **kwargs):
        """ List all tags.

            ||'''Argument'''||'''Description'''||
            ||`tagspace=<tagspace>`||Specify the tagspace the macro should operate on.||
            ||`tagspaces=(<tagspace>,...)`||Specify a set of tagspaces the macro should operate on.||
            ||`shownames=true|false`||Whether to show the objects that tags appear on ''(long)''.||
            """

        if tags:
            # Backwards compatibility
            return self.render_listtagged(req, *tags, **kwargs)

        page = self._current_page(req)
        engine = TagEngine(self.env)

        showpages = kwargs.get('showpages', None) or kwargs.get('shownames', 'false')

        if 'tagspace' in kwargs:
            tagspaces = [kwargs['tagspace']]
        else:
            tagspaces = kwargs.get('tagspaces', []) or \
                        list(TagEngine(self.env).tagspaces)

        out = StringIO()
        out.write('<ul class="listtags">\n')
        tag_details = {}
        for tag, names in sorted(engine.get_tags(tagspaces=tagspaces, detailed=True).iteritems()):
            href, title = engine.get_tag_link(tag)
            htitle = wiki_to_oneliner(title, self.env)
            out.write('<li><a href="%s" title="%s">%s</a> %s <span class="tagcount">(%i)</span>' % (href, title, tag, htitle, len(names)))
            if showpages == 'true':
                out.write('\n')
                out.write(self.render_listtagged(req, tag, tagspaces=tagspaces))
                out.write('</li>\n')

        out.write('</ul>\n')

        return out.getvalue()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:41,代码来源:macros.py

示例7: render_tagcloud

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import get_tags [as 别名]
    def render_tagcloud(self, req, smallest=10, biggest=20, showcount=True, tagspace=None, mincount=1, tagspaces=[]):
        """ This macro displays a [http://en.wikipedia.org/wiki/Tag_cloud tag cloud] (weighted list)
            of all tags.

            ||'''Argument'''||'''Description'''||
            ||`tagspace=<tagspace>`||Specify the tagspace the macro should operate on.||
            ||`tagspaces=(<tagspace>,...)`||Specify a set of tagspaces the macro should operate on.||
            ||`smallest=<n>`||The lower bound of the font size for the tag cloud.||
            ||`biggest=<n>`||The upper bound of the font size for the tag cloud.||
            ||`showcount=true|false`||Show the count of objects for each tag?||
            ||`mincount=<n>`||Hide tags with a count less than `<n>`.||
            """

        smallest = int(smallest)
        biggest = int(biggest)
        mincount = int(mincount)

        engine = TagEngine(self.env)
        # Get wiki tagspace
        if tagspace:
            tagspaces = [tagspace]
        else:
            tagspaces = tagspaces or engine.tagspaces
        cloud = {}

        for tag, names in engine.get_tags(tagspaces=tagspaces, detailed=True).iteritems():
            count = len(names)
            if count >= mincount:
                cloud[tag] = len(names)

        tags = cloud.keys()

        # No tags?
        if not tags: return ''

        # by_count maps tag counts to an index in the set of counts
        by_count = list(set(cloud.values()))
        by_count.sort()
        by_count = dict([(c, float(i)) for i, c in enumerate(by_count)])

        taginfo = self._tag_details({}, tags)
        tags.sort()
        rlen = float(biggest - smallest)
        tlen = float(len(by_count))
        scale = 1.0
        if tlen:
            scale = rlen / tlen
        out = StringIO()
        out.write('<ul class="tagcloud">\n')
        last = tags[-1]
        for tag in tags:
            if tag == last:
                cls = ' class="last"'
            else:
                cls = ''
            if showcount != 'false':
                count = ' <span class="tagcount">(%i)</span>' % cloud[tag]
            else:
                count = ''
            out.write('<li%s><a rel="tag" title="%s" style="font-size: %ipx" href="%s">%s</a>%s</li>\n' % (
                       cls,
                       taginfo[tag][1] + ' (%i)' % cloud[tag],
                       smallest + int(by_count[cloud[tag]] * scale),
                       taginfo[tag][0],
                       tag,
                       count))
        out.write('</ul>\n')
        return out.getvalue()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:70,代码来源:macros.py

示例8: TagApiTestCase

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import get_tags [as 别名]
class TagApiTestCase(unittest.TestCase):
    test_data = (('wiki', 'WikiStart', ('foo', 'bar')),
                 ('wiki', 'SandBox', ('bar', 'war')),
                 ('ticket', 1, ('war', 'death')),
                 ('ticket', 2, ('death', 'destruction')),
                 ('ticket', 3, ('foo', 'bar', 'destruction'))
                 )

    req = Mock(perm=Mock(assert_permission=lambda x: True),
               authname='anonymous')

    def _populate_tags(self, ts):
        for tagspace, target, tags in self.test_data:
            tagspace = ts.tagspace(tagspace)
            tagspace.add_tags(self.req, target, tags)
            yield tagspace, target, tags

    def setUp(self):
        self.env = EnvironmentStub(default_data=True)
        self.env.path = '/'
        self.tag_engine = TagEngine(self.env)
        self.tag_engine.upgrade_environment(self.env.get_db_cnx())
        # Insert some test tickets
        from trac.ticket.model import Ticket
        for id in (1, 2, 3):
            ticket = Ticket(self.env)
            ticket['summary'] = 'Test ticket %i' % id
            ticket['description'] = 'Test ticket %i description' % id
            ticket.insert()

    def test_tagspaces(self):
        tagspaces = set(self.tag_engine.tagspaces)
        self.assertEqual(tagspaces, set(('ticket', 'wiki')))

    def test_insert(self):
        ts = self.tag_engine.tagspace
        for tagspace, target, tags in self._populate_tags(ts):
            found_tags = tagspace.get_tags([target])
            self.assertEqual(found_tags, set(tags))

    def test_remove(self):
        ts = self.tag_engine.tagspace
        for tagspace, target, tags in self._populate_tags(ts):
            target_tags = tagspace.get_name_tags(target)
            tag = iter(target_tags).next()
            tagspace.remove_tags(self.req, target, (tag,))
            target_tags.discard(tag)
            self.assertEqual(tagspace.get_name_tags(target), target_tags)

    def test_remove_all(self):
        ts = self.tag_engine.tagspace
        for tagspace, target, tags in self._populate_tags(ts):
            tagspace.remove_all_tags(self.req, target)

    def test_replace(self):
        ts = self.tag_engine.tagspace
        test_set = set(('foozle', 'stick'))
        for tagspace, target, tags in self._populate_tags(ts):
            found_tags = tagspace.get_tags([target])
            tagspace.replace_tags(self.req, target, test_set)
            self.assertEqual(test_set, tagspace.get_name_tags(target))

    def test_add(self):
        ts = self.tag_engine.tagspace
        test_set = set(('foozle', 'stick'))
        for tagspace, target, tags in self._populate_tags(ts):
            found_tags = tagspace.get_tags([target])
            tagspace.add_tags(self.req, target, test_set)
            self.assertEqual(test_set.union(found_tags), tagspace.get_name_tags(target))

    def test_walk(self):
        engine = self.tag_engine
        compare_data = {}
        for tagspace, target, tags in self._populate_tags(engine.tagspace):
            compare_data.setdefault(tagspace.tagspace, {})[target] = set(tags)
        tag_data = {}
        for tagspace, name, tags in engine.walk_tagged_names():
            tag_data.setdefault(tagspace, {})[name] = tags
        self.assertEqual(compare_data, tag_data)

    def test_get_tagged_union(self):
        ts = self.tag_engine.tagspace
        for tagspace, target, tags in self._populate_tags(ts): pass
        self.assertEqual(self.tag_engine.get_tagged_names(tags=('foo', 'bar'), operation='union'),
                         {'wiki': set([u'WikiStart', u'SandBox']), 'ticket': set([3])})

    def test_get_tagged_intersection(self):
        ts = self.tag_engine.tagspace
        for tagspace, target, tags in self._populate_tags(ts): pass
        self.assertEqual(self.tag_engine.get_tagged_names(tags=('foo', 'bar'), operation='intersection'),
                         {'wiki': set(['WikiStart']), 'ticket': set([3])})

    def test_get_tags_union(self):
        ts = self.tag_engine.tagspace
        for tagspace, target, tags in self._populate_tags(ts): pass
        self.assertEqual(self.tag_engine.get_tags(names=('WikiStart', 1), operation='union'),
                         set(['death', 'bar', 'war', 'foo']))

    def test_get_tags_intersection(self):
        ts = self.tag_engine.tagspace
#.........这里部分代码省略.........
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:103,代码来源:test.py


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