本文整理汇总了Python中blog.models.Category.save方法的典型用法代码示例。如果您正苦于以下问题:Python Category.save方法的具体用法?Python Category.save怎么用?Python Category.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Category
的用法示例。
在下文中一共展示了Category.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_creating_a_new_comment_and_saving_it_to_the_database
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [as 别名]
def test_creating_a_new_comment_and_saving_it_to_the_database(self):
# start by create one Category and one post
category = Category()
category.name = "First"
category.slug = "first"
category.save()
# create new post
post = Post()
post.category = category
post.title = "First post"
post.content = "Content"
post.visable = True
post.save()
# create one comment
comment = Comment()
comment.name = "John"
comment.content = "This is cool"
comment.post = post
# check save
comment.save()
# now check we can find it in the database
all_comment_in_database = Comment.objects.all()
self.assertEquals(len(all_comment_in_database), 1)
only_comment_in_database = all_comment_in_database[0]
self.assertEquals(only_comment_in_database, comment)
# and check that it's saved its two attributes: name and content
self.assertEquals(only_comment_in_database.name, comment.name)
self.assertEquals(only_comment_in_database.content, comment.content)
示例2: test_all_post_feed
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [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)
示例3: handle
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [as 别名]
def handle(self, *args, **options):
with open('upload-temp') as f:
sep = '\n' + ('-' * 70) + '\n'
fields = f.read().split(sep)
if options['edit']:
try:
p = Post.objects.get(slug=fields[1])
p.edited = datetime.now()
except Post.DoesNotExist:
raise CommandError('no post with slug "%s" exists'
% fields[1])
else:
p = Post()
p.created = datetime.now()
p.edited = None
p.title = fields[0]
p.slug = fields[1]
p.preview = fields[3]
p.content = fields[4]
p.save()
p.categories.clear()
for cat in fields[2].split(', '):
try:
c = Category.objects.get(name=cat)
except Category.DoesNotExist:
c = Category(name=cat, slug=slugify(cat))
c.save()
p.categories.add(c)
p.save()
示例4: test_creating_a_new_post_and_saving_it_to_the_database
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [as 别名]
def test_creating_a_new_post_and_saving_it_to_the_database(self):
# start by create one Category
category = Category()
category.name = "First"
category.slug = "first"
category.save()
# create new post
post = Post()
post.category = category
post.title = "First post"
post.content = "Content"
post.visable = True
# check we can save it
post.save()
# check slug
self.assertEquals(post.slug, "first-post")
# now check we can find it in the database
all_post_in_database = Post.objects.all()
self.assertEquals(len(all_post_in_database), 1)
only_post_in_database = all_post_in_database[0]
self.assertEquals(only_post_in_database, post)
# check that it's saved all attributes: category, title, content, visable and generate slug
self.assertEquals(only_post_in_database.category, category)
self.assertEquals(only_post_in_database.title, post.title)
self.assertEquals(only_post_in_database.content, post.content)
self.assertEquals(only_post_in_database.visable, post.visable)
self.assertEquals(only_post_in_database.slug, post.slug)
示例5: test_create_post_without_tag
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [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)
示例6: async_add_category
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [as 别名]
def async_add_category(request):
if not request.POST:
raise Http404
data = {}
name = request.POST.get('name', False)
slug = request.POST.get('slug', False)
if name == False or slug == False:
data.update({"status": False, "message": "Invalid data."})
elif len(name) == 0 or len(slug) == 0:
data.update({"status": False, "message": "Neither field can be blank."})
else:
try:
cat = Category(name=slug,label=name) # Stupid naming of the model. Don't feel like fixing all references..
cat.save()
data.update({"status": True, "message": "Category successfully added.",
"slug": cat.name, "name": cat.label})
except:
data.update({"status": False, "message": "An unknown error occured. Please reload the page."})
return HttpResponse(simplejson.dumps(data), mimetype="application/javascript")
### END AJAX VIEWS ###
示例7: test_validate_account
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [as 别名]
def test_validate_account(self):
site = Site.objects.get_current().domain
user = BlogUser.objects.create_superuser(email="[email protected]",
username="liangliangyy1", password="liangliangyy1")
self.client.login(username='liangliangyy1', password='liangliangyy1')
response = self.client.get('/admin/')
self.assertEqual(response.status_code, 200)
category = Category()
category.name = "categoryaaa"
category.created_time = datetime.datetime.now()
category.last_mod_time = datetime.datetime.now()
category.save()
article = Article()
article.title = "nicetitleaaa"
article.body = "nicecontentaaa"
article.author = user
article.category = category
article.type = 'a'
article.status = 'p'
article.save()
response = self.client.get(article.get_admin_url())
self.assertEqual(response.status_code, 200)
示例8: addCategory
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [as 别名]
def addCategory(request):
name = request.POST['name']
slug = request.POST['slug']
desc = request.POST['desc']
type = request.POST['type']
pid = request.POST['category_parent']
if pid == '0':
pid = None
if type and type == 'add':
try:
cats=Category.objects.filter(name=name)
if cats.count() >= 1:
messages.add_message(request,messages.INFO,'categry [%s] already exits!'%(name))
else:
cat = Category(name=name,slug=slug,desc=desc,parent_id=pid)
cat.save()
messages.add_message(request,messages.INFO,'categry [%s] save ok!'%(name))
except Exception as e:
print 'exception:',e
elif type and type == 'edit':
id = request.POST.get('id','')
cat = Category.objects.get(id=id)
cat.name=name
cat.slug=slug
cat.desc=desc
cat.parent_id = pid
cat.save()
return HttpResponseRedirect('/admin/categories')
示例9: addCategory
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [as 别名]
def addCategory(request):
if request.method=='POST':
name = request.POST['name']
slug = request.POST['slug']
desc = request.POST['desc']
type = request.POST['type']
if type and type == 'add':
try:
cats=Category.objects.filter(name=name)
if cats.count() >= 1:
messages.add_message(request,messages.INFO,'categry [%s] already exits!'%(name))
else:
cat = Category(name=name,slug=slug,desc=desc)
cat.save()
messages.add_message(request,messages.INFO,'categry [%s] save ok!'%(name))
except:
pass
elif type and type == 'edit':
id = request.POST.get('id','')
cat = Category.objects.get(id=id)
cat.name=name
cat.slug=slug
cat.desc=desc
cat.save()
return HttpResponseRedirect('/admin/categories')
示例10: test_edit_category
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [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')
示例11: post
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [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')
示例12: test_validate_comment
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [as 别名]
def test_validate_comment(self):
site = Site.objects.get_current().domain
user = BlogUser.objects.create_superuser(email="[email protected]",
username="liangliangyy1", password="liangliangyy1")
self.client.login(username='liangliangyy1', password='liangliangyy1')
c = Category()
c.name = "categoryccc"
c.created_time = datetime.datetime.now()
c.last_mod_time = datetime.datetime.now()
c.save()
article = Article()
article.title = "nicetitleccc"
article.body = "nicecontentccc"
article.author = user
article.category = c
article.type = 'a'
article.status = 'p'
article.save()
s = TextMessage([])
s.content = "nicetitleccc"
rsp = search(s, None)
self.assertTrue(rsp != '没有找到相关文章。')
rsp = category(None, None)
self.assertIsNotNone(rsp)
rsp = recents(None, None)
self.assertTrue(rsp != '暂时还没有文章')
cmd = commands()
cmd.title = "test"
cmd.command = "ls"
cmd.describe = "test"
cmd.save()
cmdhandler = CommandHandler()
rsp = cmdhandler.run('test')
self.assertIsNotNone(rsp)
s.source = 'u'
s.content = 'test'
msghandler = MessageHandler(s, {})
#msghandler.userinfo.isPasswordSet = True
#msghandler.userinfo.isAdmin = True
msghandler.handler()
s.content = 'y'
msghandler.handler()
s.content='idcard:12321233'
msghandler.handler()
s.content='weather:上海'
msghandler.handler()
s.content='admin'
msghandler.handler()
s.content='123'
msghandler.handler()
s.content = 'exit'
msghandler.handler()
示例13: __create_category
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [as 别名]
def __create_category(self, lang, title, desc):
cat = Category(lang=lang, title=title, desc=desc)
cat.save()
print(
"Created category : {} | {} | {} | ".format(lang, title, desc))
return cat
示例14: test_edit_posts
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [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')
示例15: add_category
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import save [as 别名]
def add_category(request):
try:
req = convertRequest(request)
category_name = req['category_name']
category = Category(category_name=category_name)
category.save()
return HttpResponse(response_json.success())
except Exception, e:
return HttpResponse(response_json.fail(traceback.format_exc()))