本文整理汇总了Python中blog.models.Tag.put方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.put方法的具体用法?Python Tag.put怎么用?Python Tag.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Tag
的用法示例。
在下文中一共展示了Tag.put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: admin_edit_post
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import put [as 别名]
def admin_edit_post(request, post_id):
if users.is_current_user_admin():
post = Post.get_by_id(int(post_id))
if not post:
raise Http404
if request.method == 'GET':
tp = Tag_Post.all().filter('post', post)
tags = ''
# Get all tags
for tag in tp:
tags += tag.tag.title + ','
form = PostForm({'title':post.title, 'category':post.category.key(), 'content':post.content, 'tags':tags})
elif request.method == 'POST':
form = PostForm(request.POST)
if form.is_valid():
# delete related tag_post
for tp in post.tags:
tp.delete()
p = form.save(commit=False)
post.author = users.get_current_user()
post.category = p.category
post.content = p.content
post.put()
# add tag_post
tagText = request.POST['tags']
if tagText:
tags = tagText.split(',')
for tag in tags:
if tag:
tag = string.lower(string.strip(tag))
t = Tag.all().filter("title = ", unicode(tag, "utf-8")).get()
if not t:
t = Tag(title=unicode(tag, "utf-8"))
t.put()
Tag_Post(tag=t, post=post).put()
return HttpResponseRedirect('/admin')
return render_to_response('admin/edit.html',
dictionary={ 'form':form,
'type': 'Edit Post',
},
context_instance=RequestContext(request)
)
else:
return HttpResponseRedirect('/')
示例2: admin_add_post
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import put [as 别名]
def admin_add_post(request):
if users.is_current_user_admin():
if request.method == 'GET':
form = PostForm()
elif request.method == 'POST':
form = PostForm(request.POST)
if form.is_valid():
post = form.save(commit=False)
post.author = users.get_current_user()
post.put()
tagText = request.POST['tags']
tags = tagText.split(',')
for tag in tags:
if tag:
tag = string.lower(string.strip(tag))
t = Tag.all().filter("title = ", unicode(tag, "utf-8")).get()
if not t:
t = Tag(title=unicode(tag, "utf-8"))
t.put()
Tag_Post(tag=t, post=post).put()
return HttpResponseRedirect('/admin')
return render_to_response('admin/edit.html',
dictionary={ 'form':form ,
'type': 'Add Post',
},
context_instance=RequestContext(request)
)
else:
return HttpResponseRedirect('/')
示例3: create
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import put [as 别名]
def create(self, form):
tag = Tag(
parent=Service.to_key(form.category.data),
tag=form.tag.data,
slug=Service.slugify(form.tag.data))
return tag.put()