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


Python utils.get_tag函数代码示例

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


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

示例1: test_add_tag

    def test_add_tag(self):
        # start off in a known, mildly interesting state
        Tag.objects.update_tags(self.dead_parrot, 'foo bar baz')
        tags = Tag.objects.get_for_object(self.dead_parrot)
        self.assertEqual(len(tags), 3)
        self.assertTrue(get_tag('bar') in tags)
        self.assertTrue(get_tag('baz') in tags)
        self.assertTrue(get_tag('foo') in tags)

        # try to add a tag that already exists
        Tag.objects.add_tag(self.dead_parrot, 'foo')
        tags = Tag.objects.get_for_object(self.dead_parrot)
        self.assertEqual(len(tags), 3)
        self.assertTrue(get_tag('bar') in tags)
        self.assertTrue(get_tag('baz') in tags)
        self.assertTrue(get_tag('foo') in tags)

        # now add a tag that doesn't already exist
        Tag.objects.add_tag(self.dead_parrot, 'zip')
        tags = Tag.objects.get_for_object(self.dead_parrot)
        self.assertEqual(len(tags), 4)
        self.assertTrue(get_tag('zip') in tags)
        self.assertTrue(get_tag('bar') in tags)
        self.assertTrue(get_tag('baz') in tags)
        self.assertTrue(get_tag('foo') in tags)
开发者ID:crisish,项目名称:blog,代码行数:25,代码来源:tests.py

示例2: relate

 def relate(self, tags, relation_type='~', related_tags=[], force_create=False):
     '''
     Relates each tag in a list of tags with each tag in a list of related_tags
     with the given relation type. Tag lists can be Tag instances or strings.
     Relations are created symmetrically. If force_create = True, tags are 
     created from string if they do not already exist. If just a list of tags are 
     given, it calls relate_all() to relate them with each other using '~' relation.
     Updates existing relations if needed.
     '''
     #TODO: WTF
     tags = get_tag_list(tags)
     if related_tags == []:
         self.relate_all(tags)
     else:
         related_tags = get_tag_list(related_tags)
         for tag in tags:
             tag = get_tag(tag)
             if tag and tag.is_valid:
                     for related_tag in related_tags:
                         related_tag = get_tag(related_tag)
                         if related_tag and related_tag.is_valid:
                                 if tag != related_tag:
                                     rel, c = RelatedTag.objects.get_or_create(tag=tag, related_tag=related_tag,
                                                                               defaults={'relation_type': relation_type,
                                                                                         'count': 1})
                                     if not c:
                                         rel.count += 1
                                         # check if the existing relation is correct
                                         if rel.relation_type != relation_type:
                                             rel.relation_type = relation_type
                                         rel.save()
开发者ID:antonioceraso,项目名称:django-tagging,代码行数:31,代码来源:models.py

示例3: test_add_tag

 def test_add_tag(self):
     # start off in a known, mildly interesting state
     Tag.objects.update_tags(self.dead_parrot, 'foo bar baz')
     tags = Tag.objects.get_for_object(self.dead_parrot)
     ##TODO: for some reason this doesn't work
     #self.assertEquals(len(tags), 3)
     ## But this does!
     self.assertEquals(len(list(tags)), 3)
     self.failUnless(get_tag('bar') in tags)
     self.failUnless(get_tag('baz') in tags)
     self.failUnless(get_tag('foo') in tags)
     
     # try to add a tag that already exists
     Tag.objects.add_tag(self.dead_parrot, 'foo')
     tags = Tag.objects.get_for_object(self.dead_parrot)
     self.assertEquals(len(tags), 3)
     self.failUnless(get_tag('bar') in tags)
     self.failUnless(get_tag('baz') in tags)
     self.failUnless(get_tag('foo') in tags)
     
     # now add a tag that doesn't already exist
     Tag.objects.add_tag(self.dead_parrot, 'zip')
     tags = Tag.objects.get_for_object(self.dead_parrot)
     self.assertEquals(len(tags), 4)
     self.failUnless(get_tag('zip') in tags)
     self.failUnless(get_tag('bar') in tags)
     self.failUnless(get_tag('baz') in tags)
     self.failUnless(get_tag('foo') in tags)
开发者ID:stringfellow,项目名称:ias-ess,代码行数:28,代码来源:tests.py

示例4: test_add_tag

    def test_add_tag(self):
        # start off in a known, mildly interesting state
        Tag.objects.update_tags(self.dead_parrot, "foo bar baz")
        tags = Tag.objects.get_for_object(self.dead_parrot)
        self.assertEquals(len(tags), 3)
        self.failUnless(get_tag("bar") in tags)
        self.failUnless(get_tag("baz") in tags)
        self.failUnless(get_tag("foo") in tags)

        # try to add a tag that already exists
        Tag.objects.add_tag(self.dead_parrot, "foo")
        tags = Tag.objects.get_for_object(self.dead_parrot)
        self.assertEquals(len(tags), 3)
        self.failUnless(get_tag("bar") in tags)
        self.failUnless(get_tag("baz") in tags)
        self.failUnless(get_tag("foo") in tags)

        # now add a tag that doesn't already exist
        Tag.objects.add_tag(self.dead_parrot, "zip")
        tags = Tag.objects.get_for_object(self.dead_parrot)
        self.assertEquals(len(tags), 4)
        self.failUnless(get_tag("zip") in tags)
        self.failUnless(get_tag("bar") in tags)
        self.failUnless(get_tag("baz") in tags)
        self.failUnless(get_tag("foo") in tags)
开发者ID:cagerton,项目名称:django-tagging,代码行数:25,代码来源:tests.py

示例5: test_update_via_tags_field

 def test_update_via_tags_field(self):
     f1 = FormTest.objects.create(tags=u'test3 test2 test1')
     tags = Tag.objects.get_for_object(f1)
     test1_tag = get_tag('test1')
     test2_tag = get_tag('test2')
     test3_tag = get_tag('test3')
     self.failUnless(None not in (test1_tag, test2_tag, test3_tag))
     ##TODO: for some reason this doesn't work
     #self.assertEquals(len(tags), 3)
     ## But this does!
     self.assertEquals(len(list(tags)), 3)
     self.failUnless(test1_tag in tags)
     self.failUnless(test2_tag in tags)
     self.failUnless(test3_tag in tags)
     
     f1.tags = u'test4'
     f1.save()
     tags = Tag.objects.get_for_object(f1)
     test4_tag = get_tag('test4')
     self.assertEquals(len(tags), 1)
     self.assertEquals(tags[0], test4_tag)
     
     f1.tags = ''
     f1.save()
     tags = Tag.objects.get_for_object(f1)
     self.assertEquals(len(tags), 0)
开发者ID:stringfellow,项目名称:ias-ess,代码行数:26,代码来源:tests.py

示例6: test_create_with_tags_specified

 def test_create_with_tags_specified(self):
     f1 = FormTest.objects.create(tags=u'test3 test2 test1')
     tags = Tag.objects.get_for_object(f1)
     test1_tag = get_tag('test1')
     test2_tag = get_tag('test2')
     test3_tag = get_tag('test3')
     self.failUnless(None not in (test1_tag, test2_tag, test3_tag))
     self.assertEquals(len(tags), 3)
     self.failUnless(test1_tag in tags)
     self.failUnless(test2_tag in tags)
     self.failUnless(test3_tag in tags)
开发者ID:su-danny,项目名称:famdates,代码行数:11,代码来源:tests.py

示例7: test_create_with_tags_specified

 def test_create_with_tags_specified(self):
     f1 = FormTest.objects.create(tags="test3 test2 test1")
     tags = Tag.objects.get_for_object(f1)
     test1_tag = get_tag("test1")
     test2_tag = get_tag("test2")
     test3_tag = get_tag("test3")
     self.assertTrue(None not in (test1_tag, test2_tag, test3_tag))
     self.assertEqual(len(tags), 3)
     self.assertTrue(test1_tag in tags)
     self.assertTrue(test2_tag in tags)
     self.assertTrue(test3_tag in tags)
开发者ID:citadelgrad,项目名称:django-tagging,代码行数:11,代码来源:tests.py

示例8: test_update_tags_with_none

    def test_update_tags_with_none(self):
        # start off in a known, mildly interesting state
        Tag.objects.update_tags(self.dead_parrot, "foo bar baz")
        tags = Tag.objects.get_for_object(self.dead_parrot)
        self.assertEqual(len(tags), 3)
        self.assertTrue(get_tag("bar") in tags)
        self.assertTrue(get_tag("baz") in tags)
        self.assertTrue(get_tag("foo") in tags)

        Tag.objects.update_tags(self.dead_parrot, None)
        tags = Tag.objects.get_for_object(self.dead_parrot)
        self.assertEqual(len(tags), 0)
开发者ID:citadelgrad,项目名称:django-tagging,代码行数:12,代码来源:tests.py

示例9: testMergeTagsCreatesSynonyms

    def testMergeTagsCreatesSynonyms(self):
        first = TestItem(title = 'first', tags = 'one, two')
        first.save()
        second = TestItem(title = 'second', tags = 'second')
        second.save()

        self.assertEqual([], [s.name for s in get_tag('two').synonyms.all()])

        ctype = model_to_ctype(TestItem)
        merge('two', 'second', ctype)

        self.assertEqual(['second'], [s.name for s in get_tag('two').synonyms.all()])
开发者ID:Apocalepse,项目名称:django-tagging-ng,代码行数:12,代码来源:merge.py

示例10: test_update_tags_with_none

    def test_update_tags_with_none(self):
        # start off in a known, mildly interesting state
        Tag.objects.update_tags(self.dead_parrot, 'foo bar baz')
        tags = Tag.objects.get_for_object(self.dead_parrot)
        self.assertEquals(len(tags), 3)
        self.failUnless(get_tag('bar') in tags)
        self.failUnless(get_tag('baz') in tags)
        self.failUnless(get_tag('foo') in tags)

        Tag.objects.update_tags(self.dead_parrot, None)
        tags = Tag.objects.get_for_object(self.dead_parrot)
        self.assertEquals(len(tags), 0)
开发者ID:su-danny,项目名称:famdates,代码行数:12,代码来源:tests.py

示例11: test_add_tag_invalid_input_no_tags_specified

    def test_add_tag_invalid_input_no_tags_specified(self):
        # start off in a known, mildly interesting state
        Tag.objects.update_tags(self.dead_parrot, "foo bar baz")
        tags = Tag.objects.get_for_object(self.dead_parrot)
        self.assertEquals(len(tags), 3)
        self.failUnless(get_tag("bar") in tags)
        self.failUnless(get_tag("baz") in tags)
        self.failUnless(get_tag("foo") in tags)

        try:
            Tag.objects.add_tag(self.dead_parrot, "    ")
        except AttributeError, ae:
            self.assertEquals(str(ae), 'No tags were given: "    ".')
开发者ID:cagerton,项目名称:django-tagging,代码行数:13,代码来源:tests.py

示例12: test_add_tag_invalid_input_multiple_tags_specified

    def test_add_tag_invalid_input_multiple_tags_specified(self):
        # start off in a known, mildly interesting state
        Tag.objects.update_tags(self.dead_parrot, 'foo bar baz')
        tags = Tag.objects.get_for_object(self.dead_parrot)
        self.assertEquals(len(tags), 3)
        self.failUnless(get_tag('bar') in tags)
        self.failUnless(get_tag('baz') in tags)
        self.failUnless(get_tag('foo') in tags)

        try:
            Tag.objects.add_tag(self.dead_parrot, 'one two')
        except AttributeError, ae:
            self.assertEquals(str(ae), 'Multiple tags were given: "one two".')
开发者ID:su-danny,项目名称:famdates,代码行数:13,代码来源:tests.py

示例13: test_create_with_tags_specified

 def test_create_with_tags_specified(self):
     f1 = FormTest.objects.create(tags=u'test3 test2 test1')
     tags = Tag.objects.get_for_object(f1)
     test1_tag = get_tag('test1')
     test2_tag = get_tag('test2')
     test3_tag = get_tag('test3')
     self.failUnless(None not in (test1_tag, test2_tag, test3_tag))
     ##TODO: for some reason this doesn't work
     #self.assertEquals(len(tags), 3)
     ## But this does!
     self.assertEquals(len(list(tags)), 3)
     self.failUnless(test1_tag in tags)
     self.failUnless(test2_tag in tags)
     self.failUnless(test3_tag in tags)
开发者ID:stringfellow,项目名称:ias-ess,代码行数:14,代码来源:tests.py

示例14: testMergeTagsWhenSynonymAlreadyExists

    def testMergeTagsWhenSynonymAlreadyExists(self):
        first = TestItem(title = 'first', tags = 'one, two, blah')
        first.save()
        second = TestItem(title = 'second', tags = 'second')
        second.save()
        blah = get_tag('blah')
        blah.synonyms.create(name='second')

        self.assertEqual([], [s.name for s in get_tag('two').synonyms.all()])

        ctype = model_to_ctype(TestItem)
        merge('two', 'second', ctype)

        self.assertEqual([], [s.name for s in get_tag('two').synonyms.all()])
        self.assertEqual(['second'], [s.name for s in get_tag('blah').synonyms.all()])
开发者ID:Apocalepse,项目名称:django-tagging-ng,代码行数:15,代码来源:merge.py

示例15: test_update_tags_with_none

 def test_update_tags_with_none(self):
     # start off in a known, mildly interesting state
     Tag.objects.update_tags(self.dead_parrot, 'foo bar baz')
     tags = Tag.objects.get_for_object(self.dead_parrot)
     ##TODO: for some reason this doesn't work
     #self.assertEquals(len(tags), 3)
     ## But this does!
     self.assertEquals(len(list(tags)), 3)
     self.failUnless(get_tag('bar') in tags)
     self.failUnless(get_tag('baz') in tags)
     self.failUnless(get_tag('foo') in tags)
     
     Tag.objects.update_tags(self.dead_parrot, None)
     tags = Tag.objects.get_for_object(self.dead_parrot)
     self.assertEquals(len(tags), 0)
开发者ID:stringfellow,项目名称:ias-ess,代码行数:15,代码来源:tests.py


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