当前位置: 首页>>代码示例>>Python>>正文


Python Tag.create方法代码示例

本文整理汇总了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)
开发者ID:iTriumph,项目名称:MiniAkio,代码行数:29,代码来源:blog.py

示例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)
开发者ID:iTriumph,项目名称:MiniAkio,代码行数:32,代码来源:blog.py

示例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')
开发者ID:940825,项目名称:logpress-tornado,代码行数:16,代码来源:admin.py

示例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)
开发者ID:wikty,项目名称:bookmark,代码行数:62,代码来源:views.py

示例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
开发者ID:dengmin,项目名称:logpress-tornado,代码行数:22,代码来源:admin.py

示例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
开发者ID:jonanone,项目名称:favmapp-api,代码行数:14,代码来源:api.py

示例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)
开发者ID:wikty,项目名称:bookmark,代码行数:66,代码来源:views.py


注:本文中的models.Tag.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。