本文整理汇总了Python中blog.models.Tag.strip方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.strip方法的具体用法?Python Tag.strip怎么用?Python Tag.strip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Tag
的用法示例。
在下文中一共展示了Tag.strip方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PostHandler
# 需要导入模块: from blog.models import Tag [as 别名]
# 或者: from blog.models.Tag import strip [as 别名]
def PostHandler(request,**args):
"""docstring for GetPost"""
if args["action"] =='get':
post=Post.objects.get(id=args["id"])
return render_to_response('desktop/post.html',{'post':post})
if request.user.is_authenticated():
if args["action"] =='del':
p=Post.objects.get(id=args["id"])
p.delete()
return HttpResponseRedirect("/home")
if args["action"] =='new':
pageinfo={'title':"New Post",'action':'/p/add','button':'Publish'}
return render_to_response('desktop/edit.html',{'pageinfo':pageinfo})
if args["action"] =='add':
if request.method == 'POST':
form=PostForm(request.POST)
if form.is_valid():
postform=form.cleaned_data
user=request.user
published=datetime.datetime.now()
post=Post(title=postform['title'],url=postform['url'],author=user,content=postform['content'],published=published)
post.save()
tags=postform['tags'].split(" ")
if tags:
for t in tags:
try:
tag=Tag.objects.get(name=t)
except Tag.DoesNotExist:
tag=Tag(name=t)
tag.save()
post.tags.add(tag)
return HttpResponseRedirect('/home')
if args["action"]=='edit':
pageinfo={'title':"Edit Post",'action':'/p/update/'+args["id"],'button':'Update'}
postform=Post.objects.get(id=args["id"])
# tags=[ t.tag.name for t in Post2Tag.objects.filter(post=args["id"])]
# tags=' '.join(tags)
tags=postform.tags.all()
return render_to_response('desktop/edit.html',{'pageinfo':pageinfo,'postform':postform,'tags':tags})
if args["action"]=='update':
if request.method=='POST':
form=PostForm(request.POST)
if form.is_valid():
postform=form.cleaned_data
user=request.user
post=Post.objects.get(id=args["id"])
post.title=postform['title']
post.url=postform['url']
post.content=postform['content']
post.save()
newtags=[tag.strip() for tag in postform['tags'].split()]
oldtags=[tag.name for tag in post.tags.all()]
for t in list(set(oldtags).difference(set(newtags))):
post.tags.remove(Tag.objects.get(name=t))
for t in list(set(newtags).difference(set(oldtags))):
try:
tag=Tag.objects.get(name=t)
except Tag.DoesNotExist:
tag=Tag(name=t)
tag.save()
post.tags.add(Tag.objects.get(name=t))
return HttpResponseRedirect('/home')
else:
return HttpResponseRedirect("/login")