本文整理汇总了Python中blog.models.Category.description方法的典型用法代码示例。如果您正苦于以下问题:Python Category.description方法的具体用法?Python Category.description怎么用?Python Category.description使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Category
的用法示例。
在下文中一共展示了Category.description方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_all_post_feed
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [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)
示例2: test_edit_category
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [as 别名]
def test_edit_category(self):
# Create the category
category = Category()
category.name = 'python'
category.description = 'The Python programming language'
category.save()
# Log in
self.client.login(username='bobsmith', password="password")
# Edit the category
response = self.client.post('/admin/blogengine/category/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 category amended
all_categories = Category.objects.all()
self.assertEquals(len(all_categories), 1)
only_category = all_categories[0]
self.assertEquals(only_category.name, 'perl')
self.assertEquals(only_category.description, 'The Perl programming language')
示例3: test_create_post_without_tag
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [as 别名]
def test_create_post_without_tag(self):
# Create the category
category = Category()
category.name = 'python'
category.description = 'The Python programming language'
category.save()
# Log in
self.client.login(username='bobsmith', password="password")
# Check response code
response = self.client.get('/admin/blog/post/add/')
self.assertEquals(response.status_code, 200)
# Create the new post
response = self.client.post('/admin/blog/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'
},
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)
示例4: post
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [as 别名]
def post(self):
from .models import FontIcon,FontIconLibrary
iconclass = None
i = request.form.get('icon',None)
if i is not None:
lib,icon = i.split('-')[0],i.split('-')[1:]
iconclass = FontIcon.query.filter(FontIcon.name==''.join(map(str,icon)),FontIconLibrary.name==lib).first()
self._context['form_args'] = {'heading':self._form_heading}
self._form = self._form(request.form)
if self._form.validate():
from blog.models import Category
c = Category.query.filter(Category.name==self._form.name.data).first()
if c is None:
c = Category()
if iconclass is not None:
c.icon_id = iconclass.id
c.name = self._form.name.data
c.description = self._form.description.data
c.save()
self.flash('You added category: {}'.format(c.name))
if request.args.get('last_url'):
return self.redirect(request.args.get('last_url'),raw=True)
else:
self.flash('There is already a category by that name, try again')
return self.redirect('core.index')
示例5: test_edit_posts
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [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')
示例6: test_delete_post
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [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)
示例7: test_category_page
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [as 别名]
def test_category_page(self):
# Create the category
category = Category()
category.name = 'python'
category.description = 'The Python programming language'
category.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.category = category
post.save()
# 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 category URL
category_url = post.category.get_absolute_url()
# Fetch the category
response = self.client.get(category_url)
self.assertEquals(response.status_code, 200)
# Check the category name is in the response
self.assertTrue(post.category.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)
示例8: test_index
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [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)
示例9: post
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [as 别名]
def post(self):
self._context['form_args'] = {'heading':self._form_heading}
self._form = self._form(request.form)
if self._form.validate():
from blog.models import Category
c = Category.query.filter(Category.name==self._form.name.data).first()
if c is None:
c = Category()
c.name = self._form.name.data
c.description = self._form.description.data
c.save()
self.flash('You added category: {}'.format(c.name))
else:
self.flash('There is already a category by that name, try again')
return self.render()
示例10: test_create_category
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [as 别名]
def test_create_category(self):
category = Category()
category.name = 'python'
category.description = 'The python language'
category.slug = 'python'
category.save()
all_categories = Category.objects.all()
self.assertEquals(len(all_categories), 1)
only_category = all_categories[0]
self.assertEquals(only_category, category)
self.assertEquals(only_category.name, 'python')
self.assertEquals(only_category.description, 'The python language')
self.assertEquals(only_category.slug, 'python')
示例11: test_delete_post
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [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)
示例12: test_delete_category
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [as 别名]
def test_delete_category(self):
# Create the category
category = Category()
category.name = 'python'
category.description = 'The Python programming language'
category.save()
# Log in
self.client.login(username='bobsmith', password="password")
# Delete the category
response = self.client.post('/admin/blogengine/category/1/delete/', {
'post': 'yes'
}, follow=True)
self.assertEquals(response.status_code, 200)
# Check deleted successfully
self.assertTrue('deleted successfully' in response.content)
# Check category deleted
all_categories = Category.objects.all()
self.assertEquals(len(all_categories), 0)
示例13: test_create_post
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [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)
示例14: test_create_post
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [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()
# 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()
# Set the attributes
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)
# Check attributes
self.assertEquals(only_post.title, 'My first post')
self.assertEquals(only_post.text, 'This is my first blog post')
self.assertEquals(only_post.slug, 'my-first-post')
self.assertEquals(only_post.site.name, 'example.com')
self.assertEquals(only_post.site.domain, 'example.com')
self.assertEquals(only_post.pub_date.day, post.pub_date.day)
self.assertEquals(only_post.pub_date.month, post.pub_date.month)
self.assertEquals(only_post.pub_date.year, post.pub_date.year)
self.assertEquals(only_post.pub_date.hour, post.pub_date.hour)
self.assertEquals(only_post.pub_date.minute, post.pub_date.minute)
self.assertEquals(only_post.pub_date.second, post.pub_date.second)
self.assertEquals(only_post.author.username, 'testuser')
self.assertEquals(only_post.author.email, '[email protected]')
self.assertEquals(only_post.category.name, 'python')
self.assertEquals(only_post.category.description, 'The Python programming language')
# Check tags
post_tags = only_post.tags.all()
self.assertEquals(len(post_tags), 1)
only_post_tag = post_tags[0]
self.assertEquals(only_post_tag, tag)
self.assertEquals(only_post_tag.name, 'python')
self.assertEquals(only_post_tag.description, 'The Python programming language')
示例15: test_edit_post
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import description [as 别名]
def test_edit_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.author = author
post.site = site
post.save()
post.tags.add(tag)
post.save()
# Log in
self.client.login(username='bobsmith', password="password")
# Edit the post
response = self.client.post('/admin/blogengine/post/1/', {
'title': 'My second post',
'text': 'This is my second blog post',
'pub_date_0': '2013-12-28',
'pub_date_1': '22:00:04',
'slug': 'my-second-post',
'site': '1',
'category': '1',
'tags': '1'
},
follow=True
)
self.assertEquals(response.status_code, 200)
# Check changed successfully
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, 'My second post')
self.assertEquals(only_post.text, 'This is my second blog post')