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


Python Tag.get_by_key_name方法代码示例

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


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

示例1: test_suggestion_tag_reverse

# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import get_by_key_name [as 别名]
 def test_suggestion_tag_reverse(self):
     # Create a suggestion and tags but with a missing reverse reference.
     Reminder(key_name='a-b', title='a b', tags='a b'.split()).put()
     Reminder(key_name='b-c', title='b c', tags='b'.split()).put()
     Tag(key_name='a', suggestions='a-b'.split(), count=0).put()
     Tag(key_name='b', suggestions='b-c'.split(), count=0).put()
     self.assertEqual(Reminder.all().count(), 2)
     self.assertEqual(Tag.all().count(), 2)
     self.assertEqual(len(Tag.get_by_key_name('b').suggestions), 1)
     # Check that the missing tag-reminder reference is detected.
     response = self.client.get('/consistency/')
     self.assertTrue('suggestion_tag_reverse'
                     in response.context['problems'])
     self.assertTrue("Suggestion a-b references b but not reverse."
                     in response.content)
     # Simulate button click to fix this problem.
     response = self.client.post('/consistency/', {
             'suggestion_tag_reverse': "Create reverse references"})
     self.assertRedirects(response, '/consistency/')
     # Check that the tags are now existing.
     self.assertEqual(Reminder.all().count(), 2)
     self.assertEqual(Tag.all().count(), 2)
     self.assertEqual(len(Tag.get_by_key_name('b').suggestions), 2)
     response = self.client.get('/consistency/')
     self.assertFalse('suggestion_tag_reverse'
                      in response.context['problems'])
开发者ID:jcrocholl,项目名称:minderbot,代码行数:28,代码来源:tests.py

示例2: test_tag_suggestion_missing

# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import get_by_key_name [as 别名]
 def test_tag_suggestion_missing(self):
     self.assertEqual(Tag.all().count(), 0)
     # Create tags but not all suggestions.
     Reminder(key_name='a-b', title='a b', tags='a b'.split()).put()
     Tag(key_name='a', count=2, suggestions='a-b a-c'.split()).put()
     Tag(key_name='b', count=2, suggestions='b-c'.split()).put()
     self.assertEqual(Tag.all().count(), 2)
     # Check that the missing suggestions are detected.
     response = self.client.get('/consistency/')
     self.assertTrue('tag_suggestion_missing'
                     in response.context['problems'])
     self.assertTrue("Tag a references missing suggestion a-c."
                     in response.content)
     self.assertTrue("Tag b references missing suggestion b-c."
                     in response.content)
     # Simulate button click to fix this problem.
     response = self.client.post('/consistency/', {
             'tag_suggestion_missing': "Create missing"})
     self.assertRedirects(response, '/consistency/')
     # Check that the references are now gone.
     self.assertEqual(Tag.all().count(), 1)
     self.assertEqual(Tag.get_by_key_name('a').count, 1)
     self.assertEqual(len(Tag.get_by_key_name('a').suggestions), 1)
     response = self.client.get('/consistency/')
     self.assertFalse('tag_suggestion_missing'
                      in response.context['problems'])
开发者ID:jcrocholl,项目名称:minderbot,代码行数:28,代码来源:tests.py

示例3: submit_suggestion

# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import get_by_key_name [as 别名]
def submit_suggestion(request, suggestion_form):
    """
    Save a new suggestion in the database.
    """
    slug = suggestion_form.cleaned_data['slug']
    tag_list = suggestion_form.cleaned_data['tags'].split()
    for tag_name in tag_list:
        tag = Tag.get_by_key_name(tag_name)
        if tag is None:
            tag = Tag(key_name=tag_name, count=0)
        tag.suggestions.append(slug)
        tag.count += 1
        tag.put()
    suggestion = Reminder(
        key_name=slug,
        title=suggestion_form.cleaned_data['title'],
        days=suggestion_form.cleaned_data['days'],
        months=suggestion_form.cleaned_data['months'],
        years=suggestion_form.cleaned_data['years'],
        miles=suggestion_form.cleaned_data['miles'],
        kilometers=suggestion_form.cleaned_data['kilometers'],
        tags=tag_list)
    logging.debug(suggestion)
    suggestion.put()
    return HttpResponseRedirect(suggestion.get_absolute_url())
开发者ID:jcrocholl,项目名称:minderbot,代码行数:27,代码来源:views.py

示例4: test_tag_created_none

# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import get_by_key_name [as 别名]
 def test_tag_created_none(self):
     # Create a tag with missing timestamp.
     Reminder(key_name='a-b', title='a b', tags='a b'.split()).put()
     Tag(key_name='a', suggestions=['a-b'], count=1, created=None).put()
     # Check that the missing timestamp is detected.
     response = self.client.get('/consistency/')
     self.assertTrue('tag_created_none' in response.context['problems'])
     self.assertTrue("Tag a is missing a timestamp." in response.content)
     # Simulate button click to fix this problem.
     response = self.client.post('/consistency/',
                                 {'tag_created_none': "Adjust timestamps"})
     self.assertRedirects(response, '/consistency/')
     # Check that the timestamps are now correct.
     self.assertEqual(Reminder.get_by_key_name('a-b').created,
                      Tag.get_by_key_name('a').created)
     response = self.client.get('/consistency/')
     self.assertFalse('tag_created_none' in response.context['problems'])
开发者ID:jcrocholl,项目名称:minderbot,代码行数:19,代码来源:tests.py


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