本文整理汇总了Python中tagging.utils.get_tag函数的典型用法代码示例。如果您正苦于以下问题:Python get_tag函数的具体用法?Python get_tag怎么用?Python get_tag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_tag函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: vote_tag
def vote_tag(request, tag):
tag_instance = get_tag(tag)
if tag_instance is None:
raise Http404(_('No Tag found matching "%s".') % tag)
extra_context = {'tag':tag_instance}
extra_context['tag_url'] = reverse('vote-tag',args=[tag_instance])
if 'member' in request.GET:
extra_context['member'] = get_object_or_404(Member, pk=request.GET['member'])
extra_context['member_url'] = reverse('member-detail',args=[extra_context['member'].id])
extra_context['title'] = ugettext_lazy('Votes tagged %(tag)s by %(member)s') % {'tag': tag, 'member':extra_context['member'].name}
qs = extra_context['member'].votes.all()
else: # only tag is given
extra_context['title'] = ugettext_lazy('Votes tagged %(tag)s') % {'tag': tag}
qs = Vote
queryset = TaggedItem.objects.get_by_model(qs, tag_instance)
vote_attendence = [v.votes.all() for v in TaggedItem.objects.get_by_model(Vote, tag_instance)]
d = {}
for vote in vote_attendence:
for v in vote:
d[v] = d.get(v,0)+1
# now d is a dict: MK -> number of votes in this tag
mks = d.keys()
for mk in mks:
mk.count = d[mk]
average = float(sum([mk.count for mk in mks]))/len(mks)
mks = [mk for mk in mks if mk.count>=average]
mks = tagging.utils.calculate_cloud(mks)
extra_context['members'] = mks
return object_list(request, queryset,
#return tagged_object_list(request, queryset_or_model=qs, tag=tag,
template_name='laws/vote_list_by_tag.html', extra_context=extra_context)
开发者ID:livni,项目名称:old-OK,代码行数:33,代码来源:views.py
示例17: bill_tag
def bill_tag(request, tag):
tag_instance = get_tag(tag)
if tag_instance is None:
raise Http404(_('No Tag found matching "%s".') % tag)
extra_context = {'tag':tag_instance}
extra_context['tag_url'] = reverse('bill-tag',args=[tag_instance])
if 'member' in request.GET:
try:
member_id = int(request.GET['member'])
except ValueError:
raise Http404(_('No Member found matching "%s".') % request.GET['member'])
extra_context['member'] = get_object_or_404(Member, pk=request.GET['member'])
extra_context['member_url'] = reverse('member-detail',args=[extra_context['member'].id])
extra_context['title'] = _('Bills tagged %(tag)s by %(member)s') % {'tag': tag, 'member':extra_context['member'].name}
qs = extra_context['member'].bills.all()
else: # only tag is given
extra_context['title'] = _('Bills tagged %(tag)s') % {'tag': tag}
qs = Bill
queryset = TaggedItem.objects.get_by_model(qs, tag_instance)
bill_proposers = [b.proposers.all() for b in TaggedItem.objects.get_by_model(Bill, tag_instance)]
d = {}
for bill in bill_proposers:
for p in bill:
d[p] = d.get(p,0)+1
# now d is a dict: MK -> number of proposals in this tag
mks = d.keys()
for mk in mks:
mk.count = d[mk]
mks = tagging.utils.calculate_cloud(mks)
extra_context['members'] = mks
return object_list(request, queryset,
#return tagged_object_list(request, queryset_or_model=qs, tag=tag,
template_name='laws/bill_list_by_tag.html', extra_context=extra_context)
开发者ID:itsadok,项目名称:Open-Knesset,代码行数:35,代码来源:views.py
示例18: filter_and_order
def filter_and_order(self, *args, **kwargs):
stage = kwargs.get('stage', None)
member = kwargs.get('member', None)
booklet = kwargs.get('booklet', None)
filter_kwargs = {}
if stage and stage != 'all':
if stage in BILL_AGRR_STAGES:
qs = self.filter(BILL_AGRR_STAGES[stage])
else:
filter_kwargs['stage__startswith'] = stage
qs = self.filter(**filter_kwargs)
else:
qs = self.all()
if kwargs.get('tagged', None):
if kwargs['tagged'] == 'false':
ct = ContentType.objects.get_for_model(Bill)
filter_tagged = TaggedItem.objects.filter(content_type=ct).distinct().values_list('object_id', flat=True)
qs = qs.exclude(id__in=filter_tagged)
elif kwargs['tagged'] != 'all':
qs = TaggedItem.objects.get_by_model(qs,get_tag(kwargs['tagged']))
if booklet:
kps = KnessetProposal.objects.filter(booklet_number=booklet).values_list('id',flat=True)
if kps:
qs = qs.filter(knesset_proposal__in=kps)
return qs
开发者ID:Yshayy,项目名称:Open-Knesset,代码行数:29,代码来源:models.py
示例19: get_queryset
def get_queryset(self):
try:
tag = self.kwargs['tag']
except KeyError:
raise AttributeError(_('tagged_object_list must be called with a tag.'))
tag_instance = get_tag(tag)
return TaggedItem.objects.get_by_model(Entry, tag_instance)
开发者ID:muratmeran,项目名称:596acres,代码行数:7,代码来源:views.py
示例20: get_queryset
def get_queryset(self, *args, **kwargs):
images = Image.objects.all()
tag_instance = get_tag('featured')
if tag_instance is None:
raise Http404(_('No Tag found matching "featured"'))
images = TaggedItem.objects.get_by_model(images, tag_instance)
return images
开发者ID:goldhand,项目名称:art-portfolio,代码行数:7,代码来源:views.py
注:本文中的tagging.utils.get_tag函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论