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


Python Tag.get方法代码示例

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


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

示例1: post_update_post

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

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get [as 别名]
def tag_handler(tag_id):
    if request.method == 'GET':
        tag = Tag.get(tag_id)
        if tag is not None:
            return jsonify(tag=[tag.serialize])
        else:
            raise InvalidUsage('Not Found', status_code=404)
    if request.method == 'PUT':
        tag = Tag.get(tag_id)
        if tag is not None:
            name = request.args.get('name')
            description = request.args.get('description')
            updated_tag = tag.update(name, description)
            return jsonify(tag=[updated_tag.serialize])
        else:
            raise InvalidUsage('Not Found', status_code=404)
    if request.method == 'DELETE':
        tag = Tag.get(tag_id)
        if tag is not None:
            deleted = tag.delete()
            if deleted:
                return jsonify(status='OK')
            else:
                raise InvalidUsage('Unknown Error', status_code=520)
        else:
            raise InvalidUsage('Not Found', status_code=404)
开发者ID:jonanone,项目名称:favmapp-api,代码行数:28,代码来源:api.py

示例3: edit

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get [as 别名]
def edit(slug):
    entry = get_object_or_404(Entry, Entry.slug == slug)
    tags = ""
    for tag in entry.tags:
        tags = tags + " " + tag.tag
    if request.method == "POST":
        if request.form.get("title") and request.form.get("content"):
            try:
                entry.title = request.form["title"]
                entry.content = request.form["content"]
                entry.archived = request.form.get("archived") or False
                entry.lastedited = datetime.datetime.now()
                # convert the string of tags to a list
                tags = request.form["tags"].split()
                # present is a check to see if the tag exists
                present = 0
                # add or create tags
                for tag in tags:
                    for entrytag in entry.tags:
                        if tag == entrytag.tag:
                            present = 1
                    if present == 0:
                        try:
                            thistag = Tag.get(Tag.tag == tag)
                            entry.tags.add(thistag)
                        except:
                            tag_obj, was_created = Tag.create_or_get(tag=tag)
                            EntryTags.create(tag=tag_obj, entry=entry)
                    present = 0
                # remove tags
                for entrytag in entry.tags:
                    for tag in tags:
                        if entrytag.tag == tag:
                            present = 1
                    if present == 0:
                        thistag = Tag.get(Tag.tag == entrytag.tag)
                        entry.tags.remove(thistag)
                    present = 0
                entry.save()

                flash("Note updated successfully.", "success")
                return redirect(url_for("detail", slug=entry.slug))
            except:
                flash("Note title already exists", "danger")
                return render_template("create.html")
        else:
            flash("Title and Content are required.", "danger")

    return render_template("edit.html", entry=entry, tags=tags)
开发者ID:keybits,项目名称:permanote,代码行数:51,代码来源:views.py

示例4: tag_blogs

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get [as 别名]
def tag_blogs(tag_id):
    tag = Tag.get(tag_id)
    if not tag:
        raise notfound()
    blogs = get_blogs_from_tag(tag)
    blogs = render_blogs(blogs)
    user = ctx.request.user
    return dict(blogs=blogs,user=user)
开发者ID:lixiangbest,项目名称:jblog,代码行数:10,代码来源:urls.py

示例5: members

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get [as 别名]
def members():
    tag = Tag.get("001449249583583e39048657a1c4584960f34e4623e2dae000")
    if not tag:
        raise notfound()
    blogs = get_blogs_from_tag(tag)
    blogs = render_blogs(blogs)
    user = ctx.request.user
    return dict(blogs=blogs,user=user)
开发者ID:buaaoptflow,项目名称:buaaopt_web,代码行数:10,代码来源:urls.py

示例6: research

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get [as 别名]
def research():
    tag = Tag.get("001449249434796934306a1e38243e8b4fde9e013d286fe000")
    if not tag:
        raise notfound()
    blogs = get_blogs_from_tag(tag)
    blogs = render_blogs(blogs)
    user = ctx.request.user
    return dict(blogs=blogs,user=user)
开发者ID:buaaoptflow,项目名称:buaaopt_web,代码行数:10,代码来源:urls.py

示例7: remove_blogtag

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get [as 别名]
def remove_blogtag(blog,remove):
    if not remove:
        return
    remove_string = "','".join(remove)
    s='delete from blogtag where blogtag.blog_id="%s" and blogtag.tag_id in (\'%s\')' % (blog.id,remove_string)
    logging.info('#########')
    logging.info(s)
    db.update(s)
    for tag_id in remove:
        tag = Tag.get(tag_id)
        tag_count_min(tag)
开发者ID:lixiangbest,项目名称:jblog,代码行数:13,代码来源:urls.py

示例8: remove_blogtag

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get [as 别名]
def remove_blogtag(blog, remove):
    if not remove:
        return
    remove_string = "','".join(remove)
    s = "delete from blogtag where blogtag.blog_id=\"%s\" and blogtag.tag_id in ('%s')" % (blog.id, remove_string)
    logging.info("#########")
    logging.info(s)
    db.update(s)
    for tag_id in remove:
        tag = Tag.get(tag_id)
        tag_count_min(tag)
开发者ID:ZhQYuan,项目名称:jblog,代码行数:13,代码来源:urls.py

示例9: post

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

示例10: delete_entry

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get [as 别名]
def delete_entry(kind, entry, from_file=None):
    """Deletes a file name entry or tag entry from the catalog"""

    if kind == 'files':

        to_delete = File.get(File.file_name == entry)

        to_delete.delete_instance()

        print "'%s' deleted from catalog!" % entry

    elif kind == 'tag' and from_file:

        try:
            existing_file = File.get(File.file_name == from_file)

            if existing_file:
                try:
                    association = FileTag.get(FileTag.file_id == existing_file,
                                              FileTag.tag_id == Tag.get(Tag.tag_name == entry))
                    association.delete_instance()

                    print "Deleted '%s' from '%s'" % (entry, from_file)

                except:

                    print "'%s' no longer tagged to %s" % (entry, from_file)

        except:
            print "'%s' not in catalog" % from_file

    elif kind == 'tag':

        tag_item = Tag.get(Tag.tag_name == entry)

        tag_item.delete_instance()

        print "'%s' deleted from catalog" % entry

    else:
        pass
开发者ID:mosegontar,项目名称:ScratchTrack,代码行数:43,代码来源:catalog.py

示例11: _save_question

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get [as 别名]
def _save_question(question, fetch_index):

    # It seems that the the ID of the owner is missing from some records.
    # This little bit of logic checks to see if it's missing.
    owner_id = question['owner']['user_id']\
        if 'owner' in question and 'user_id' in question['owner']\
        else None

    # Dates are returned by the Stack Exchange API in Unix epoch time.
    # This inline method converts the timestamps to datetime objects that
    # can be stored in a Postgres database.  Note that the times will be
    # converted to _local times_ on this server rather than their original
    # UTC times.  I chose to do this as the date of creation of these records
    # will also be in local time.
    timestamp_to_datetime = lambda ts: datetime.datetime.fromtimestamp(ts)

    # Create a snapshot of this question
    snapshot = QuestionSnapshot.create(
        fetch_index=fetch_index,
        question_id=question['question_id'],
        owner_id=owner_id,
        comment_count=question['comment_count'],
        delete_vote_count=question['delete_vote_count'],
        reopen_vote_count=question['reopen_vote_count'],
        close_vote_count=question['close_vote_count'],
        is_answered=question['is_answered'],
        view_count=question['view_count'],
        favorite_count=question['favorite_count'],
        down_vote_count=question['down_vote_count'],
        up_vote_count=question['up_vote_count'],
        answer_count=question['answer_count'],
        score=question['score'],
        last_activity_date=timestamp_to_datetime(question['last_activity_date']),
        creation_date=timestamp_to_datetime(question['creation_date']),
        title=question['title'],
        body=question['body'],
    )

    # Link this snapshot to all tags related to it
    for tag_name in question['tags']:

        if tag_name in tag_cache:
            tag = tag_cache[tag_name]
        else:
            try:
                tag = Tag.get(tag_name=tag_name)
            except Tag.DoesNotExist:
                tag = None
            tag_cache[tag_name] = tag

        if tag is not None:
            QuestionSnapshotTag.create(question_snapshot_id=snapshot.id, tag_id=tag.id)
开发者ID:andrewhead,项目名称:Package-Qualifiers,代码行数:54,代码来源:stack_overflow_questions.py

示例12: add_tag

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get [as 别名]
def add_tag(tag):
    """Adds a tag to the catalog"""

    tag = tag.strip()

    new_tag = False

    try:
        current_tag = Tag(tag_name=tag)
        current_tag.save()
        new_tag = True

    except IntegrityError:
        current_tag = Tag.get(Tag.tag_name == tag)

    return current_tag, new_tag
开发者ID:mosegontar,项目名称:ScratchTrack,代码行数:18,代码来源:catalog.py

示例13: create

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get [as 别名]
def create():
    if request.method == "POST":
        if request.form.get("title") and request.form.get("content"):
            try:
                entry = Entry.create(
                    title=request.form["title"],
                    content=request.form["content"],
                    archived=request.form.get("archived") or False,
                )
                tags = request.form["tags"].split()
                # present is a check to see if the tag exists
                present = 0
                # add or create tags
                for tag in tags:
                    for entrytag in entry.tags:
                        if tag == entrytag.tag:
                            present = 1
                    if present == 0:
                        try:
                            thistag = Tag.get(Tag.tag == tag)
                            entry.tags.add(thistag)
                        except:
                            tag_obj, was_created = Tag.create_or_get(tag=tag)
                            EntryTags.create(tag=tag_obj, entry=entry)
                    present = 0
                flash("Entry created successfully.", "success")
                return redirect(url_for("detail", slug=entry.slug))
            except:
                flash("Note title already exists", "danger")
                return render_template("create.html")
        # TODO Refactor the below and above to make it more DRY or not
        # to need to display seconds (e.g. add some kind of suffix if entry
        # already exists)
        elif request.form.get("content"):
            entry = Entry.create(
                title="{:%a %d %b %Y at %H:%M:%S}".format(datetime.datetime.now()), content=request.form["content"]
            )
            flash("Note created successfully.", "success")
            return redirect(url_for("detail", slug=entry.slug))
        else:
            flash("Content is required.", "danger")
    return render_template("create.html")
开发者ID:keybits,项目名称:permanote,代码行数:44,代码来源:views.py

示例14: tag_a_file

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import get [as 别名]
def tag_a_file(file_name, tag, new_tag):
    """Associates a file name with a tag"""

    if not new_tag:
        files_with_tag = (File
                          .select()
                          .join(FileTag)
                          .join(Tag)
                          .where(FileTag.tag_id == Tag.get(Tag.tag_name == tag.tag_name)))

        for f in files_with_tag:
            if file_name.file_name == f.file_name:
                return

    try:
        ft = FileTag(file_id=file_name, tag_id=tag)
        ft.save()
    except IntegrityError:
        return

    print "'%s' added to %s tags!" % (tag.tag_name, file_name.file_name)
开发者ID:mosegontar,项目名称:ScratchTrack,代码行数:23,代码来源:catalog.py

示例15: bookmark_edit

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