本文整理汇总了Python中blog.models.Tag.name方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.name方法的具体用法?Python Tag.name怎么用?Python Tag.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Tag
的用法示例。
在下文中一共展示了Tag.name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def handle(self, *args, **options):
user = \
get_user_model().objects.get_or_create(email='[email protected]', username='测试用户',
password='[email protected]#eTYU')[0]
pcategory = Category.objects.get_or_create(name='我是父类目', parent_category=None)[0]
category = Category.objects.get_or_create(name='子类目', parent_category=pcategory)[0]
category.save()
basetag = Tag()
basetag.name = "标签"
basetag.save()
for i in range(1, 20):
article = Article.objects.get_or_create(category=category,
title='nice title ' + str(i),
body='nice content ' + str(i),
author=user
)[0]
tag = Tag()
tag.name = "标签" + str(i)
tag.save()
article.tags.add(tag)
article.tags.add(basetag)
article.save()
from DjangoBlog.utils import cache
cache.clear()
self.stdout.write(self.style.SUCCESS('created test datas \n'))
示例2: blog_entry_add_view
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def blog_entry_add_view(request):
"""
lets superusers add a blog entry
:param request:
:return:
"""
options = blogAttributes()
entryForm = EntryForm()
options['form'] = entryForm
options['tags'] = Tag.objects.all()
if request.POST and request.method == 'POST':
entryForm = EntryForm(request.POST)
if entryForm.is_unique(request):
entry = entryForm.customSave(request.user)
# loop through the tags
if len(entry.tags) > 0:
tags = entry.tags.split(',')
for tag in tags:
# if the tag doesn't exist
if not Tag.objects.filter(name=tag).exists():
# save the tag
t = Tag()
t.name = tag
t.save()
messages.add_message(request, messages.SUCCESS, 'The Entry has been saved')
return redirect(blog_view)
else:
messages.add_message(request, messages.ERROR, 'An Entry with this Title already exists')
return render_to_response('entryForm.html', options, context_instance=RequestContext(request))
示例3: test_edit_tag
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def test_edit_tag(self):
# Create the tag
tag = Tag()
tag.name = 'python'
tag.description = 'The Python programming language'
tag.save()
# Log in
self.client.login(username='bobsmith', password="password")
# Edit the tag
response = self.client.post('/admin/blogengine/tag/1/', {
'name': 'perl',
'description': 'The Perl programming language'
}, follow=True)
self.assertEquals(response.status_code, 200)
# Check changed successfully
self.assertTrue('changed successfully' in response.content)
# Check tag amended
all_tags = Tag.objects.all()
self.assertEquals(len(all_tags), 1)
only_tag = all_tags[0]
self.assertEquals(only_tag.name, 'perl')
self.assertEquals(only_tag.description, 'The Perl programming language')
示例4: test_all_post_feed
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def test_all_post_feed(self):
# Create the category
category = Category()
category.name = 'python'
category.description = 'The Python programming language'
category.save()
# Create the tag
tag = Tag()
tag.name = 'python'
tag.description = 'The Python programming language'
tag.save()
# Create the author
author = User.objects.create_user('testuser', '[email protected]', 'password')
author.save()
# Create the site
site = Site()
site.name = 'example.com'
site.domain = 'example.com'
site.save()
# Create a post
post = Post()
post.title = 'My first post'
post.text = 'This is my first blog post'
post.slug = 'my-first-post'
post.pub_date = timezone.now()
post.author = author
post.site = site
post.category = category
# Save it
post.save()
# Add the tag
post.tags.add(tag)
post.save()
# Check we can find it
all_posts = Post.objects.all()
self.assertEquals(len(all_posts), 1)
only_post = all_posts[0]
self.assertEquals(only_post, post)
# Fetch the feed
response = self.client.get('/feeds/posts/')
self.assertEquals(response.status_code, 200)
# Parse the feed
feed = feedparser.parse(response.content)
# Check length
self.assertEquals(len(feed.entries), 1)
# Check post retrieved is the correct one
feed_post = feed.entries[0]
self.assertEquals(feed_post.title, post.title)
self.assertEquals(feed_post.description, post.text)
示例5: blog_entry_edit_view
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def blog_entry_edit_view(request, eID):
"""
lets superusers edit a blog entry
:param request:
:return:
"""
options = blogAttributes()
entry = get_object_or_404(Entry, id=eID)
options['entry'] = entry
options['form'] = EntryForm(instance=entry)
if request.POST and request.method == 'POST':
entryForm = EntryForm(request.POST, instance=get_object_or_404(Entry, id=eID))
if entryForm.is_unique(request, entry):
if entryForm.has_changed():
entry = entryForm.customSave(request.user)
# loop through the tags
if len(entry.tags) > 0:
tags = entry.tags.split(',')
for tag in tags:
# if the tag doesn't exist
if not Tag.objects.filter(name=tag).exists():
# save the tag
t = Tag()
t.name = tag
t.save()
messages.add_message(request, messages.SUCCESS, 'The Entry has been updated')
return redirect(blog_entry_view, titleSlug=entry.title_slug)
else:
messages.add_message(request, messages.INFO, 'No changes have been made')
else:
messages.add_message(request, messages.ERROR, 'An Entry with this Title already exists')
return render_to_response('entryForm.html', options, context_instance=RequestContext(request))
示例6: test_edit_posts
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def test_edit_posts(self):
category = Category()
category.name = 'python'
category.description = 'The python language'
category.save()
# Create the tag
tag = Tag()
tag.name = 'python'
tag.description = 'The Python programming language'
tag.save()
author = User.objects.create_user('testuser', '[email protected]', 'password')
author.save()
# site = Site()
# site.name = 'nunfuxgvn.com'
# site.domain = 'nunfuxgvn.com'
# site.save()
post = Post()
post.title = 'First Post'
post.content = 'My first post -yay'
post.slug = 'first-post'
post.pub_date = timezone.now()
post.author = author
# post.site = site
post.save()
post.tags.add(tag)
post.save()
self.client.login(username='bobsmith', password='password')
response = self.client.post('/admin/blog/post/1/', {
'title': 'Second Post',
'text': 'This is my second post',
'pub_date_0': '2014-07-17',
'pub_date_1': '11:49:24',
'slug': 'second-post',
# 'site': '1',
'category': '1',
'tags': '1'
},
follow=True
)
self.assertEquals(response.status_code, 200)
# Check post successfully changed
self.assertTrue('changed successfully' in response.content)
# Check post amended
all_posts = Post.objects.all()
self.assertEquals(len(all_posts), 1)
only_post = all_posts[0]
self.assertEquals(only_post.title, 'Second Post')
self.assertEquals(only_post.content, 'This is my second post')
示例7: test_delete_post
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def test_delete_post(self):
# Create the category
category = Category()
category.name = 'python'
category.description = 'The Python programming language'
category.save()
# Create the tag
tag = Tag()
tag.name = 'python'
tag.description = 'The Python programming language'
tag.save()
# Create the author
author = User.objects.create_user('testuser', '[email protected]', 'password')
author.save()
# Create the site
site = Site()
site.name = 'example.com'
site.domain = 'example.com'
site.save()
# Create the post
post = Post()
post.title = 'My first post'
post.text = 'This is my first blog post'
post.slug = 'my-first-post'
post.pub_date = timezone.now()
post.site = site
post.author = author
post.category = category
post.save()
post.tags.add(tag)
post.save()
# Check new post saved
all_posts = Post.objects.all()
self.assertEquals(len(all_posts), 1)
# Log in
self.client.login(username='bobsmith', password="password")
# Delete the post
response = self.client.post('/admin/blogengine/post/1/delete/', {
'post': 'yes'
}, follow=True)
self.assertEquals(response.status_code, 200)
# Check deleted successfully
self.assertTrue('deleted successfully' in response.content)
# Check post deleted
all_posts = Post.objects.all()
self.assertEquals(len(all_posts), 0)
示例8: test_tag_page
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def test_tag_page(self):
# Create the tag
tag = Tag()
tag.name = 'python'
tag.description = 'The Python programming language'
tag.save()
# Create the author
author = User.objects.create_user('testuser', '[email protected]', 'password')
author.save()
# Create the site
site = Site()
site.name = 'example.com'
site.domain = 'example.com'
site.save()
# Create the post
post = Post()
post.title = 'My first post'
post.text = 'This is [my first blog post](http://127.0.0.1:8000/)'
post.slug = 'my-first-post'
post.pub_date = timezone.now()
post.author = author
post.site = site
post.save()
post.tags.add(tag)
# Check new post saved
all_posts = Post.objects.all()
self.assertEquals(len(all_posts), 1)
only_post = all_posts[0]
self.assertEquals(only_post, post)
# Get the tag URL
tag_url = post.tags.all()[0].get_absolute_url()
# Fetch the tag
response = self.client.get(tag_url)
self.assertEquals(response.status_code, 200)
# Check the tag name is in the response
self.assertTrue(post.tags.all()[0].name in response.content)
# Check the post text is in the response
self.assertTrue(markdown.markdown(post.text) in response.content)
# Check the post date is in the response
self.assertTrue(str(post.pub_date.year) in response.content)
self.assertTrue(post.pub_date.strftime('%b') in response.content)
self.assertTrue(str(post.pub_date.day) in response.content)
# Check the link is marked up properly
self.assertTrue('<a href="http://127.0.0.1:8000/">my first blog post</a>' in response.content)
示例9: test_index
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def test_index(self):
category = Category()
category.name = 'python'
category.description = 'The python language'
category.save()
# Create the tag
tag = Tag()
tag.name = 'perl'
tag.description = 'The Perl programming language'
tag.save()
author = User.objects.create_user('testuser', '[email protected]', 'password')
author.save()
# site = Site()
# site.name = 'nunfuxgvn.com'
# site.domain = 'nunfuxgvn.com'
# site.save()
post = Post()
post.title = 'First Post'
post.content = 'My [first post](http://127.0.0.1:8000/) -yay'
post.slug = 'first-post'
post.pub_date = timezone.now()
post.author = author
# post.site = site
post.category = category
post.save()
post.tags.add(tag)
all_posts = Post.objects.all()
self.assertEquals(len(all_posts), 1)
# Fetch test_index
response = self.client.get('/')
self.assertEquals(response.status_code, 200)
self.assertTrue(post.title in response.content)
self.assertTrue(markdown.markdown(post.content) in response.content)
self.assertTrue(post.category.name in response.content)
post_tag = all_posts[0].tags.all()[0]
self.assertTrue(post_tag.name in response.content)
self.assertTrue(str(post.pub_date.year) in response.content)
self.assertTrue(post.pub_date.strftime('%b') in response.content)
self.assertTrue(str(post.pub_date.day) in response.content)
self.assertTrue('<a href="http://127.0.0.1:8000/">first post</a>' in response.content)
示例10: test_delete_post
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def test_delete_post(self):
category = Category()
category.name = 'python'
category.description = 'The python language'
category.save()
# Create the tag
tag = Tag()
tag.name = 'python'
tag.description = 'The Python programming language'
tag.save()
author = User.objects.create_user('testuser', '[email protected]', 'password')
author.save()
# site = Site()
# site.name = 'nunfuxgvn.com'
# site.domain = 'nunfuxgvn.com'
# site.save()
post = Post()
post.title = 'First Post'
post.test = 'My first post'
post.slug = 'first-post'
post.pub_date = timezone.now()
post.author = author
# post.site = site
post.save()
post.tags.add(tag)
post.save()
all_posts = Post.objects.all()
self.assertEquals(len(all_posts), 1)
self.client.login(username='bobsmith', password='password')
response = self.client.post('/admin/blog/post/1/delete/', {
'post': 'yes'
}, follow=True)
self.assertEquals(response.status_code, 200)
self.assertTrue('deleted successfully' in response.content)
all_posts = Post.objects.all()
self.assertEquals(len(all_posts), 0)
示例11: test_create_post
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def test_create_post(self):
# Create the category
category = Category()
category.name = 'python'
category.description = 'The Python programming language'
category.save()
# Create the tag
tag = Tag()
tag.name = 'python'
tag.description = 'The Python programming language'
tag.save()
# Log in
self.client.login(username='bobsmith', password="password")
# Check response code
response = self.client.get('/admin/blogengine/post/add/')
self.assertEquals(response.status_code, 200)
# Create the new post
response = self.client.post('/admin/blogengine/post/add/', {
'title': 'My first post',
'text': 'This is my first post',
'pub_date_0': '2013-12-28',
'pub_date_1': '22:00:04',
'slug': 'my-first-post',
'site': '1',
'category': '1',
'tags': '1'
},
follow=True
)
self.assertEquals(response.status_code, 200)
# Check added successfully
self.assertTrue('added successfully' in response.content)
# Check new post now in database
all_posts = Post.objects.all()
self.assertEquals(len(all_posts), 1)
示例12: test_create_tag
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def test_create_tag(self):
# Create the tag
tag = Tag()
# Add attributes
tag.name = 'python'
tag.description = 'The Python programming language'
tag.slug = 'python'
# Save it
tag.save()
# Check we can find it
all_tags = Tag.objects.all()
self.assertEquals(len(all_tags), 1)
only_tag = all_tags[0]
self.assertEquals(only_tag, tag)
# Check attributes
self.assertEquals(only_tag.name, 'python')
self.assertEquals(only_tag.description, 'The Python programming language')
self.assertEquals(only_tag.slug, 'python')
示例13: test_delete_tag
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def test_delete_tag(self):
# Create the tag
tag = Tag()
tag.name = 'python'
tag.description = 'The Python programming language'
tag.save()
# Log in
self.client.login(username='bobsmith', password="password")
# Delete the tag
response = self.client.post('/admin/blogengine/tag/1/delete/', {
'post': 'yes'
}, follow=True)
self.assertEquals(response.status_code, 200)
# Check deleted successfully
self.assertTrue('deleted successfully' in response.content)
# Check tag deleted
all_tags = Tag.objects.all()
self.assertEquals(len(all_tags), 0)
示例14: test_create_post
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def test_create_post(self):
category = Category()
category.name = 'python'
category.description = 'The python language'
category.save()
# Create the tag
tag = Tag()
tag.name = 'python'
tag.description = 'The Python programming language'
tag.save()
self.client.login(username='bobsmith', password='password')
response = self.client.get('/admin/blog/post/add/')
self.assertEquals(response.status_code, 200)
response = self.client.post('/admin/blog/post/add/', {
'title': 'First Post',
'text': 'My first post -yay',
'pub_date_0': '2014-07-17',
'pub_date_1': '11:41:03',
'slug': 'first-post',
# 'site': '1',
'category': '1',
'tags': '1'
},
follow=True
)
self.assertEquals(response.status_code, 200)
self.assertTrue('added successfully' in response.content)
# Check the new post is in the database
all_posts = Post.objects.all()
self.assertEquals(len(all_posts), 1)
示例15: test_validate_article
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import name [as 别名]
def test_validate_article(self):
site = Site.objects.get_current().domain
user = BlogUser.objects.get_or_create(email="[email protected]", username="liangliangyy")[0]
user.set_password("liangliangyy")
user.is_staff = True
user.is_superuser = True
user.save()
response = self.client.get(user.get_absolute_url())
self.assertEqual(response.status_code, 200)
s = SideBar()
s.sequence = 1
s.name = 'test'
s.content = 'test content'
s.is_enable = True
s.save()
category = Category()
category.name = "category"
category.created_time = datetime.datetime.now()
category.last_mod_time = datetime.datetime.now()
category.save()
tag = Tag()
tag.name = "nicetag"
tag.save()
article = Article()
article.title = "nicetitle"
article.body = "nicecontent"
article.author = user
article.category = category
article.type = 'a'
article.status = 'p'
article.save()
self.assertEqual(0, article.tags.count())
article.tags.add(tag)
article.save()
self.assertEqual(1, article.tags.count())
for i in range(20):
article = Article()
article.title = "nicetitle" + str(i)
article.body = "nicetitle" + str(i)
article.author = user
article.category = category
article.type = 'a'
article.status = 'p'
article.save()
article.tags.add(tag)
article.save()
response = self.client.get(article.get_absolute_url())
self.assertEqual(response.status_code, 200)
from DjangoBlog.spider_notify import SpiderNotify
SpiderNotify.notify(article.get_absolute_url())
response = self.client.get(tag.get_absolute_url())
self.assertEqual(response.status_code, 200)
response = self.client.get(category.get_absolute_url())
self.assertEqual(response.status_code, 200)
response = self.client.get('/search', {'q': 'django'})
self.assertEqual(response.status_code, 200)
s = load_articletags(article)
self.assertIsNotNone(s)
rsp = self.client.get('/refresh')
self.assertEqual(rsp.status_code, 302)
self.client.login(username='liangliangyy', password='liangliangyy')
rsp = self.client.get('/refresh')
self.assertEqual(rsp.status_code, 200)
response = self.client.get(reverse('blog:archives'))
self.assertEqual(response.status_code, 200)
p = Paginator(Article.objects.all(), 2)
self.__check_pagination__(p, '', '')
p = Paginator(Article.objects.filter(tags=tag), 2)
self.__check_pagination__(p, '分类标签归档', tag.slug)
p = Paginator(Article.objects.filter(author__username='liangliangyy'), 2)
self.__check_pagination__(p, '作者文章归档', 'liangliangyy')
p = Paginator(Article.objects.filter(category=category), 2)
self.__check_pagination__(p, '分类目录归档', category.slug)
f = BlogSearchForm()
f.search()
self.client.login(username='liangliangyy', password='liangliangyy')
from DjangoBlog.spider_notify import SpiderNotify
SpiderNotify.baidu_notify([article.get_full_url()])
from blog.templatetags.blog_tags import gravatar_url, gravatar
u = gravatar_url('[email protected]')
u = gravatar('[email protected]')