本文整理汇总了Python中blog.models.Category.slug方法的典型用法代码示例。如果您正苦于以下问题:Python Category.slug方法的具体用法?Python Category.slug怎么用?Python Category.slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Category
的用法示例。
在下文中一共展示了Category.slug方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addCategory
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [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')
示例2: addCategory
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [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')
示例3: test_creating_a_new_comment_and_saving_it_to_the_database
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [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)
示例4: test_creating_a_new_post_and_saving_it_to_the_database
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [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: POST
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [as 别名]
def POST(self):
def check(cate):
parent=cate.parent_cat
skey=cate.key()
while parent:
if parent.key()==skey:
return False
parent=parent.parent_cat
return True
action=self.param("action")
name=self.param("name")
slug=self.param("slug")
parentkey=self.param('parentkey')
key=self.param('key')
vals={'action':action,'postback':True}
try:
if action=='add':
cat= Category(name=name,slug=slug)
if not (name and slug):
raise Exception(_('Please input name and slug.'))
if parentkey:
cat.parent_cat=Category.get(parentkey)
cat.put()
self.redirect('/admin/categories')
#vals.update({'result':True,'msg':_('Saved ok')})
#self.render2('views/admin/category.html',vals)
elif action=='edit':
cat=Category.get(key)
cat.name=name
cat.slug=slug
if not (name and slug):
raise Exception(_('Please input name and slug.'))
if parentkey:
cat.parent_cat=Category.get(parentkey)
if not check(cat):
raise Exception(_('A circle declaration found.'))
else:
cat.parent_cat=None
cat.put()
self.redirect('/admin/categories')
except Exception ,e :
if cat.is_saved():
cates=[c for c in Category.all() if c.key()!=cat.key()]
else:
cates= Category.all()
vals.update({'result':False,'msg':e.message,'category':cat,'key':key,'categories':cates})
self.render2('views/admin/category.html',vals)
示例6: test_create_category
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [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')
示例7: test_creating_a_new_category_and_saving_it_to_the_database
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [as 别名]
def test_creating_a_new_category_and_saving_it_to_the_database(self):
# start by createing a new Category object
category = Category()
category.name = "First"
category.slug = "first"
# check we can save it to the database
category.save()
# now check we can find it in the database again
all_category_in_database = Category.objects.all()
self.assertEquals(len(all_category_in_database), 1)
only_category_in_database = all_category_in_database[0]
self.assertEquals(only_category_in_database, category)
# and check that it's saved its two attributes: name and slug
self.assertEquals(only_category_in_database.name, category.name)
self.assertEquals(only_category_in_database.slug, category.slug)
示例8: test_unique_slug_generate
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import slug [as 别名]
def test_unique_slug_generate(self):
# start by create one Category
category = Category()
category.name = "First"
category.slug = "first"
category.save()
# create new posts
post1 = Post(category=category, title="First post", content="Content", visable=True)
post1.save()
post2 = Post(category=category, title="First post", content="Content", visable=True)
post2.save()
# check posts then it's the same title
self.assertEquals(post1.title, post2.title)
# and different slug
self.assertNotEquals(post1.slug, post2.slug)