本文整理汇总了Python中models.Tag.create方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.create方法的具体用法?Python Tag.create怎么用?Python Tag.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tag
的用法示例。
在下文中一共展示了Tag.create方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_update_post
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import create [as 别名]
def post_update_post(id):
postid = request.forms.get('postid')
title = request.forms.get('title').decode('utf-8')
slug = request.forms.get('slug').decode('utf-8')
post = request.forms.get('post')
tags = request.forms.get('tags').decode('utf-8')
category = request.forms.get('category').decode('utf-8')
post_type = request.forms.get('postype')
if post_type == 'HTML':
is_html = 1
content = post.decode('utf-8')
markdown = u'html'
else:
is_html = 0
markdown = post.decode('utf-8')
content = to_markdown(markdown)
category = Category.get(name=category)
Post.update(title=title, slug=slug, content=content, markdown=markdown,
tags=tags, category=category,
is_html=is_html).where(id=postid).execute()
tag_list = set(tags.split(","))
for tag in tag_list:
try:
Tag.get(name=tag.strip(), post_id=postid)
except Post.DoesNotExist:
Tag.create(name=tag.strip(), post_id=postid)
redirect("/%s" % slug)
示例2: post_new_post
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import create [as 别名]
def post_new_post():
title = request.forms.get('title').decode('utf-8')
slug = request.forms.get('slug').decode('utf-8')
post = request.forms.get('post')
tags = request.forms.get('tags').decode('utf-8')
category = request.forms.get('category').decode('utf-8')
post_type = request.forms.get('postype')
set_time = request.forms.get('setime')
if set_time != '1':
t = [int(tt) for tt in set_time.split('-')]
d = datetime.datetime(*t)
published = d
else:
published = datetime.datetime.now()
if post_type == 'HTML':
is_html = 1
content = post.decode('utf-8')
markdown = u'html'
else:
is_html = 0
markdown = post.decode('utf-8')
content = to_markdown(markdown)
category = Category.get(name=category)
post = Post.create(title=title, slug=slug.strip(), content=content,
markdown=markdown, tags=tags, category=category,
is_html=is_html, published=published, comm_count=0)
for tag in post.tags_list():
Tag.create(name=tag.strip(), post_id=post.id)
redirect("/%s" % slug)
示例3: post
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import create [as 别名]
def post(self):
title = self.get_argument('title',None)
slug = self.get_argument('slug','')
category_id = self.get_argument('category',1)
content = self.get_argument('content','')
tag = self.get_argument('tag',None)
category = Category.get(id=int(category_id))
post = Post.create(title=title,category=category,slug=slug,content=content,tags=tag)
if tag:
for tag in post.taglist():
Tag.create(name=tag,post=post.id)
self.render('admin/post/add.html')
示例4: bookmark_add
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import create [as 别名]
def bookmark_add():
error = {}
bookmark = {}
user = auth.get_logged_in_user()
if request.method == 'POST':
if not request.form['url']:
error['url'] = u'书签的网址不能为空'
if not request.form['url'].startswith('http://') and not request.form['url'].startswith('https://'):
request.form['url'] = ''.join(['http://', request.form['url']])
if not error:
try:
bookmark = Bookmark.select().where(Bookmark.user == user,
Bookmark.url == request.form['url']
).get()
except Bookmark.DoesNotExist:
try:
db.database.set_autocommit(False)
bookmark = Bookmark.create(
user=user,
url=request.form['url'],
title=request.form['title']
)
bookmark.fetch_image()
bookmark.save()
tagnames = re.split('\s+', request.form['tags'].strip())
# marksure request.form['tags'] not a empty string
if tagnames[0]:
for tagname in tagnames:
if not Tag.select().where(Tag.user == user,
Tag.name == tagname
).exists():
tag = Tag.create(user=user, name=tagname)
tag.save()
relationship = Relationship.create(
user=user,
tag=tag,
bookmark=bookmark)
relationship.save()
except Exception as e:
db.database.rollback()
flash(u'对不起,服务器太累了,刚罢工了一会儿', 'error')
else:
try:
db.database.commit()
except Exception as e:
db.database.rollback()
flash(u'对不起,服务器太累了,刚罢工了一会儿', 'error')
finally:
db.database.set_autocommit(True)
if not get_flashed_messages():
flash(u'你已经成功添加一个书签', 'success')
return redirect(url_for('bookmark'))
else:
flash(Markup(u'书签已经存在,也许你想要<a href="' + url_for('bookmark_edit', id=bookmark.id) + u'">编辑</a>此书签'), 'info')
return render_template('bookmark_add.html', error=error, form=request.form, user=user, bookmark=bookmark)
示例5: post
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import create [as 别名]
def post(self, postid):
title = self.get_argument('title', None)
slug = self.get_argument('slug', '')
category_id = self.get_argument('category', 1)
content = self.get_argument('content', '')
tags = self.get_argument('tag', '')
category = Category.get(id=int(category_id))
Post.update(title=title, slug=slug,
category=category, content=content, tags=tags).where(Post.id == postid).execute()
tag_list = set(tags.split(","))
if tag_list:
for tag in tag_list:
try:
Tag.get(name=tag, post=postid)
except Tag.DoesNotExist:
Tag.create(name=tag, post=postid)
self.redirect('/admin/posts')
return
示例6: all_tags_handler
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import create [as 别名]
def all_tags_handler():
if request.method == 'GET':
tags = Tag.get_all()
return jsonify(tags=[
tag.serialize for tag in tags
])
if request.method == 'POST':
name = request.args.get('name')
description = request.args.get('description')
tag = Tag.create(name=name,
description=description)
return jsonify(tag=[tag.serialize]), 201
示例7: bookmark_edit
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import create [as 别名]
def bookmark_edit(id):
user = auth.get_logged_in_user()
bookmark = {}
try:
bookmark = Bookmark.get(Bookmark.id == id)
bookmark.tags = ' '.join([Tag.get(Tag.id == tagID).name for tagID in [tag.tag for tag in bookmark.Tags]])
except Bookmark.DoesNotExist:
flash(u'你要编辑的书签不存在', 'error')
return redirect(url_for('page_404'))
error = {}
if request.method == 'POST':
try:
bookmark = Bookmark.get(Bookmark.id == request.form['id'])
except Bookmark.DoesNotExist:
flash(u'你要编辑的书签不存在', 'error')
return redirect(url_for('page_404'))
if not request.form['url']:
error['url'] = u'书签的网址不能为空'
if not error:
try:
db.database.set_autocommit(False)
# before update image, should remove old version
if bookmark.url != request.form['url']:
bookmark.destory_image()
bookmark.url = request.form['url']
bookmark.fetch_image()
bookmark.title = request.form['title']
bookmark.save()
tagnames = re.split('\s+', request.form['tags'].strip())
# marksure request.form['tags'] not a empty string
if tagnames[0]:
for tagname in tagnames:
if not Tag.select().where(Tag.user == user,
Tag.name == tagname
).exists():
tag = Tag.create(user=user, name=tagname)
tag.save()
relationship = Relationship.create(
user=user,
tag=tag,
bookmark=bookmark)
relationship.save()
except Exception as e:
db.database.rollback()
flash(u'对不起,服务器太累了,刚罢工了一会儿', 'error')
else:
try:
db.database.commit()
except Exception as e:
db.database.rollback()
flash(u'对不起,服务器太累了,刚罢工了一会儿', 'error')
finally:
db.database.set_autocommit(True)
if not get_flashed_messages():
flash(u'你刚刚完成一个书签的编辑', 'success')
return redirect(url_for('bookmark'))
return render_template('bookmark_edit.html', error=error, form=request.form, bookmark=bookmark, user=user)