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


Python Tags.objects方法代码示例

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


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

示例1: next

# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import objects [as 别名]
def next():
    if request.method == "POST":
        # TODO: helper
        tags = set(map(unicode.lower, request.form.getlist("tags")))

        Cluster.objects(pk=request.form["_id"]).update_one(
            push__tags=ShredTags(
                user=g.user.id,
                tags=list(tags),
                recognizable_chars=request.form.get("recognizable_chars", ""),
                angle=int(request.form.get("angle", 0))),
            inc__users_count=1,
            add_to_set__users_processed=g.user.id)

        User.objects(pk=g.user.id).update_one(
            inc__processed=1, inc__tags_count=len(tags),
            add_to_set__tags=list(tags))

        session["processed"] = session.get("processed", 0) + 1

        for tag in tags:
            Tags.objects(pk=tag).update_one(
                set_on_insert__is_base=False,
                set_on_insert__created_by=g.user.id,
                set_on_insert__created_at=Tags().created_at,
                inc__usages=1,
                add_to_set__shreds=request.form["_id"],
                upsert=True)

        start = datetime.strptime(request.form["tagging_start"],
                                  '%Y-%m-%d %H:%M:%S.%f')
        end = datetime.utcnow()
        TaggingSpeed.objects.create(
            user=g.user.id,
            cluster=request.form["_id"],
            tags_count=len(tags),
            msec=(end - start).total_seconds() * 1000)

    cluster = Cluster.next_for_user(g.user, app.config['USERS_PER_SHRED'])

    auto_tags = cluster and cluster.get_auto_tags() or []
    return render_template(
        "_shred.html",
        cluster=cluster,
        auto_tags=auto_tags,
        all_tags=get_tags(),
        tagging_start=datetime.utcnow(),

        # TODO: move to context processor
        processed_per_session=session.get("processed", 0),
        processed_total=User.objects(id=g.user.id).first()["processed"],
        rating=list(User.objects.order_by(
            "-processed").values_list("id")).index(g.user.id) + 1
    )
开发者ID:kostyll,项目名称:unshred-tag,代码行数:56,代码来源:app.py

示例2: get_tag_synonyms

# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import objects [as 别名]
def get_tag_synonyms():
    mapping = {}
    for t in Tags.objects(synonyms__exists=True):
        for s in t["synonyms"]:
            mapping[s] = t["title"]

    return mapping
开发者ID:yatagan,项目名称:unshred-tag,代码行数:9,代码来源:app.py

示例3: next

# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import objects [as 别名]
def next():
    if request.method == "POST":
        tags = set(map(unicode.lower, request.form.getlist("tags")))
        Shreds.objects(pk=request.form["_id"]).update_one(
            push__tags=ShredTags(user=g.user.id, tags=list(tags),
                                 recognizable_chars=request.form
                                 .get("recognizable_chars", "")),
            inc__users_count=1,
            add_to_set__summarized_tags=list(tags),
            add_to_set__users_processed=g.user.id)

        User.objects(pk=g.user.id).update_one(
            inc__processed=1, inc__tags_count=len(tags),
            add_to_set__tags=list(tags))

        session["processed"] = session.get("processed", 0) + 1

        for tag in tags:
            Tags.objects(pk=tag.capitalize()).update_one(
                set_on_insert__is_base=False,
                set_on_insert__created_by=g.user.id,
                set_on_insert__created_at=Tags().created_at,
                inc__usages=1,
                add_to_set__shreds=request.form["_id"],
                upsert=True)

        start = datetime.strptime(request.form["tagging_start"],
                                  '%Y-%m-%d %H:%M:%S.%f')
        end = datetime.utcnow()
        TaggingSpeed.objects.create(
            user=g.user.id,
            shred=request.form["_id"],
            tags_count=len(tags),
            msec=(end - start).total_seconds() * 1000)

    shred = get_next_shred()
    return render_template("shred.html",
                           shred=shred,
                           auto_tags=get_auto_tags(shred),
                           all_tags=get_tags(),
                           tagging_start=datetime.utcnow(),
                           processed_per_session=session.get("processed", 0),
                           processed_total=User.objects(id=g.user.id)\
                                .first()["processed"],
                           rating=list(User.objects.order_by("-processed")\
                                .values_list("id")).index(g.user.id) + 1
                           )
开发者ID:walltex,项目名称:unshred-tag,代码行数:49,代码来源:app.py

示例4: import_tags

# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import objects [as 别名]
def import_tags(drop=False):
    if drop:
        Tags.objects(is_base=True).delete()

    added = 0
    updated = 0

    with open("fixtures/base_tags.json", "r") as f:
        tags = json.load(f)
        for tag in tags:
            _, created = Tags.objects.get_or_create(
                title=tag["title"], defaults=tag)
            if created:
                added += 1
            else:
                updated += 1

    Tags.ensure_index(["is_base", "usages", "category"])

    return added, updated
开发者ID:dchaplinsky,项目名称:unshred-tag,代码行数:22,代码来源:load_to_mongo.py

示例5: shred

# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import objects [as 别名]
def shred(cluster_id):
    cluster = Cluster.objects.get(id=cluster_id)
    if not cluster:
        abort(404)

    if request.method == "POST":
        # TODO: helper
        tags = set(map(unicode.lower, request.form.getlist("tags")))

        user_tags = cluster.get_user_tags(g.user)
        if not user_tags:
            abort(404)

        user_tags.tags = list(tags)
        user_tags.recognizable_chars = request.form.get(
            "recognizable_chars", "")
        user_tags.angle = int(request.form.get("angle", 0))
        cluster.save()

        User.objects(pk=g.user.id).update_one(
            add_to_set__tags=list(tags))

        for tag in tags:
            Tags.objects(pk=tag).update_one(
                set_on_insert__is_base=False,
                set_on_insert__created_by=g.user.id,
                set_on_insert__created_at=Tags().created_at,
                inc__usages=1,
                add_to_set__shreds=request.form["_id"],
                upsert=True)

        return render_template("_shred_snippet.html", cluster=cluster)
    else:
        return render_template(
            "_shred.html",
            cluster=cluster,
            auto_tags=cluster.get_auto_tags(),
            all_tags=get_tags(),
            user_data=cluster.get_user_tags(g.user),
            edit=True,
        )
开发者ID:kostyll,项目名称:unshred-tag,代码行数:43,代码来源:app.py

示例6: test_has_some_tasks

# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import objects [as 别名]
    def test_has_some_tasks(self):
        self.create_user_and_login("user")

        self.client.post(url_for("fixtures.create_shreds"))

        res = self.client.get(url_for("next"))
        self.assert200(res)
        body = res.get_data(as_text=True)

        self.assertTrue("shred_id" in body)
        self.assertTrue(url_for("next") in body)

        for tag in Tags.objects(is_base=True):
            self.assertTrue(
                tag.title.capitalize().encode('unicode-escape') in body)
开发者ID:alexMoreau,项目名称:unshred-tag,代码行数:17,代码来源:tagging.py

示例7: test_index_logged

# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import objects [as 别名]
    def test_index_logged(self):
        self.create_user_and_login("user")

        res = self.client.get(url_for("index"))

        self.assert200(res)
        body = res.get_data(as_text=True)

        self.assertFalse("warm-welcome" in body)
        self.assertFalse(url_for("social.auth", backend="facebook") in body)
        self.assertFalse(url_for("social.auth", backend="twitter") in body)
        self.assertFalse(
            url_for("social.auth", backend="google-oauth2") in body)
        self.assertFalse(
            url_for("social.auth", backend="vk-oauth2") in body)

        for tag in Tags.objects(is_base=True):
            self.assertTrue(tag.title.lower() in body.lower())
            self.assertTrue(tag.category.lower() in body.lower())
            if tag.hotkey:
                self.assertTrue(tag.hotkey in body.lower())
开发者ID:alexMoreau,项目名称:unshred-tag,代码行数:23,代码来源:tagging.py

示例8: test_user_tags_in_task

# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import objects [as 别名]
    def test_user_tags_in_task(self):
        self.create_user_and_login("user")

        self.client.post(url_for("fixtures.create_shreds"))

        user = User.objects.get(username="user")
        admin = User.objects.get(username="admin")
        user_tag = "foobar"
        another_user_tag = "barfoo"

        Tags.objects.create(title=user_tag, is_base=False,
                            created_by=user)
        Tags.objects.create(title=another_user_tag, is_base=False,
                            created_by=admin)

        user.tags = [user_tag]
        admin.tags = [another_user_tag]
        user.save()
        admin.save()

        res = self.client.get(url_for("next"))
        self.assert200(res)
        body = res.get_data(as_text=True)

        self.assertTrue(
            user_tag.capitalize().encode('unicode-escape') in body)
        pos = body.index(user_tag.capitalize().encode('unicode-escape'))

        self.assertFalse(
            another_user_tag.capitalize().encode('unicode-escape') in body)

        for tag in Tags.objects(is_base=True):
            tag = tag.title.capitalize().encode('unicode-escape')
            self.assertTrue(tag in body)

            self.assertTrue(body.index(tag) < pos)
开发者ID:alexMoreau,项目名称:unshred-tag,代码行数:38,代码来源:tagging.py

示例9: get_tags

# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import objects [as 别名]
def get_tags():
    return set([unicode(t["title"]).lower()
                for t in Tags.objects(is_base=True).order_by("-usages")] +
               map(lambda x: unicode(x).lower(), g.user.tags))
开发者ID:yatagan,项目名称:unshred-tag,代码行数:6,代码来源:app.py


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