本文整理匯總了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()