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


Python Tag.select方法代码示例

本文整理汇总了Python中models.Tag.select方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.select方法的具体用法?Python Tag.select怎么用?Python Tag.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Tag的用法示例。


在下文中一共展示了Tag.select方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: clean_db

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import select [as 别名]
def clean_db():
    """Finds all tags in catalog and deletes if no file association exists"""

    all_tags = Tag.select()

    all_tags_list = []

    for tag in all_tags:
        all_tags_list.append(tag)

    tags_in_use = (Tag
                   .select(Tag)
                   .join(FileTag)
                   .join(File)
                   .group_by(Tag))

    # a list of all tags currently associated with file entries
    tags_in_use_list = []

    for tag in tags_in_use:
        tags_in_use_list.append(tag)

    for tag in all_tags_list:
        if tag not in tags_in_use_list:
            tag.delete_instance()
开发者ID:mosegontar,项目名称:ScratchTrack,代码行数:27,代码来源:catalog.py

示例2: get

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import select [as 别名]
 def get(self, tagname, page=1):
     tags = Tag.select().where(Tag.name == tagname)
     postids = [tag.post for tag in tags]
     pagination = Pagination(Post.select().where(
         Post.id << postids), int(page), per_page=8)
     self.render('archive.html', pagination=pagination,
                 name=tagname, obj_url='/tag/%s' % (tagname), flag='tag')
开发者ID:dengmin,项目名称:logpress-tornado,代码行数:9,代码来源:blog.py

示例3: bookmark_add

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import select [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

示例4: post

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import select [as 别名]
 def post(self):
     """Edit Artilce."""
     data = self.request.data(title='', tag='', category='', \
             raw_content='', old_tag='', created_at='')
     created_at = data.created_at
     title = data.title
     old_tag = data.old_tag
     tag = data.tag
     category = data.category
     raw_content = data.raw_content
     content = (markdown2.markdown(raw_content)).encode('utf-8')
     u_id = self.get_current_user()
     admin = User.get_by_primary_key(u_id)
     created_at_now = int(time.time())
     # new article
     if not created_at:
         article = Article(title=title,content=content,\
                 raw_content=raw_content,category=category, \
                 author=admin.name, created_at=created_at_now)
         article.insert()
         new_article = Article.select_one('created_at=?', created_at_now)
         article_id = new_article.id
         # tag
         tag_d = Tag.select_one('tag_name=?', tag)
         # tag doesn't exists
         if not tag_d:
             new_tag = Tag(tag_name=tag)
             new_tag.insert()
             get_tag = Tag.select_one('tag_name=?', tag)
             tag_id = get_tag.id
         # tag exists
         else:
             tag_id = tag_d.id
         article_tag = ArticleTag(article_id=article_id, tag_id=tag_id)
         article_tag.insert()
     # update old article
     else:
         article = Article(title=title, content=content, \
                 raw_content=raw_content, author=admin.name, \
                 category=category, created_at=created_at_now)
         article.update('created_at=?', created_at)
         new_article = Article.select_one('created_at=?', created_at_now)
         article_id = new_article.id
         old_tag = Tag.select_one('tag_name=?', old_tag)
         new_tag = Tag(tag_name=tag)
         other_article_tag = ArticleTag.select_all('tag_id=?', old_tag.id)
         # other article doesn't have this article
         if len(other_article_tag) >= 1:
             tag_id = old_tag.id
             new_tag.update('id=?', tag_id)
         # other article has this tag
         else:
             new_tag.insert()
             get_tag = Tag.select('tag_name=?', tag)
             tag_id = get_tag.id
         article_tag = ArticleTag(tag_id=tag_id)
         article_tag.update('article_id=?', article_id)
     self.redirect('/admin/articles')
开发者ID:damnever,项目名称:LTsite,代码行数:60,代码来源:urls.py

示例5: tag_archive

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import select [as 别名]
def tag_archive(tag):
    tag = tag.decode('utf-8').strip()
    try:
        tags = Tag.select().where(name=tag)
    except Tag.DoesNotExist:
        abort(404)
    postids = [_tag.post_id for _tag in tags]
    posts = Post.select().where(id__in=postids)
    count = posts.count()
    return template('archive.html', posts=posts, name=tag,
                    type="tag", count=count)
开发者ID:iTriumph,项目名称:MiniAkio,代码行数:13,代码来源:blog.py

示例6: admin_index

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import select [as 别名]
def admin_index():
    post_count = Post.select().count()
    comm_count = Comment.select().count()
    tag_count = Tag.select().count()
    cate_count = Category.select().count()
    author = Author.get(id=1)
    posts = Post.select().paginate(1, 5)
    comments = Comment.select().order_by(('published', 'desc')).paginate(1, 5)
    return template('admin/index.html', posts=posts, comments=comments,
                    post_count=post_count, comm_count=comm_count,
                    tag_count=tag_count, cate_count=cate_count, author=author)
开发者ID:iTriumph,项目名称:MiniAkio,代码行数:13,代码来源:admin.py

示例7: taglist

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import select [as 别名]
def taglist():
    count = fn.COUNT(EntryTags.id)
    tags_with_counts = (
        Tag.select(Tag, count.alias("entry_count"))
        .join(EntryTags)
        .join(Entry)
        .where(Entry.archived == False)
        .group_by(Tag)
        .order_by(count.desc(), Tag.tag)
    )
    return object_list("taglist.html", tags_with_counts, check_bounds=False)
开发者ID:keybits,项目名称:permanote,代码行数:13,代码来源:views.py

示例8: main

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import select [as 别名]
def main(show_progress, *args, **kwargs):

    # Set up progress bar.
    if show_progress:
        progress_bar = ProgressBar(
            maxval=len(PACKAGES),
            widgets=[
                "Progress: ",
                Percentage(),
                " ",
                Bar(marker=RotatingMarker()),
                " ",
                ETA(),
                " Fetched posts for ",
                Counter(),
                " / " + str(len(PACKAGES)) + " packages.",
            ],
        )
        progress_bar.start()

    # Fetch statistics for posts related to each tag
    for package_count, package in enumerate(PACKAGES, start=1):

        records = (
            Tag.select()
            .join(PostTag, on=(Tag.id == PostTag.tag_id))
            .join(Post, on=(Post.id == PostTag.post_id))
            .where(Tag.tag_name == package)
            .select(
                Tag.tag_name,
                Post.title,
                Post.creation_date,
                Post.answer_count,
                Post.comment_count,
                Post.favorite_count,
                Post.score,
                Post.view_count,
            )
            .dicts()
        )
        yield records

        if show_progress:
            progress_bar.update(package_count)

    if show_progress:
        progress_bar.finish()

    raise StopIteration
开发者ID:andrewhead,项目名称:Package-Qualifiers,代码行数:51,代码来源:node_post_stats.py

示例9: get

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import select [as 别名]
 def get(self):
     nav = self.request.url_params
     if nav == 'index' or not nav:
         articles = Article.select_all(None)
     elif nav in ['coding', 'wiki', 'bushit']:
         articles = Article.select_all('category=?', nav)
     elif nav == 'about':
         comments = Comment.select_all('article_id=?', 222222222)
         return self.render('about.html', comments=comments)
     else:  # according to tag
         tag_id = Tag.select_one('tag_name=?', nav)
         article_tags = ArticleTag.select_all('tag_id=?', tag_id.id)
         conditions = ' or '.join(['id=?' for a in article_tags])
         args = [a.article_id for a in article_tags]
         articles = Article.select_all(conditions, *args)
     # all tags
     d_tags = Tag.select('select tag_name from tags')
     if d_tags:
         tags = [tag for d in d_tags for tag in d.itervalues()]
     else:
         tags = None
     return self.render('toc.html', tags=tags, articles=articles)
开发者ID:damnever,项目名称:LTsite,代码行数:24,代码来源:urls.py

示例10: get_tagcloud

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import select [as 别名]
	def get_tagcloud(self):
		return Tag.select(Tag,fn.count(Tag.name).alias('count')).group_by(Tag.name)
开发者ID:940825,项目名称:logpress-tornado,代码行数:4,代码来源:blog.py

示例11: bookmark_edit

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import select [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.select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。