• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.Tags类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: api_modify_blog

def api_modify_blog(blog_id):
    check_admin()
    blog = Blogs.get(blog_id)
    if not blog:
        raise APIValueError(blog_id, 'blog is not exist.')
    i= ctx.request.input(title='', tags='', content='')
    title = i['title'].strip()
    tags = i['tags'].strip()
    content = i['content'].strip()
    if not title:
        raise APIValueError('title', 'title can not be empty.')
    if not content:
        raise APIValueError('content', 'content can not be empty.')
    summary = _get_summary(content)
    blog.title = title
    blog.summary = summary
    blog.content = content
    blog.tags = tags
    blog.update()
    db.execute('delete from `tags` where `blog`=?', blog_id)
    if tags:
        for tag in tags.split(','):
            tag = Tags(tag=tag, blog=blog_id)
            tag.insert()
    return dict(id=blog_id)
开发者ID:1007650105,项目名称:blog,代码行数:25,代码来源:urls.py


示例2: edit_post

def edit_post(id):

    form = PostForm()
    if users.is_current_user_admin() and form.validate_on_submit():

        tags = Tags()

        categories = Categories()

        updating_post = BlogPost.get(int(id))

        title = request.json['title']
        body = request.json['body']
        raw_category = request.json['category']
        editing_tags = request.json['tags']
        raw_summary = request.json['summary']

        tags_keys = tags.update(editing_tags, updating_post)

        category_key = categories.update(raw_category, updating_post.category)

        updating_post.edit(title, body, datetime.now(), tags_keys,
                           category_key, raw_summary, raw_answers=request.json['answers'])

        return jsonify(updating_post.to_json())  # dangerous
开发者ID:aarsakian,项目名称:blog,代码行数:25,代码来源:views.py


示例3: next

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,代码行数:54,代码来源:app.py


示例4: _blog_fetch_callback

    def _blog_fetch_callback(self, rpc):

        content = rpc.get_result().content
        d = feedparser.parse(StringIO(content))
        s = Signatures.get_single()
        signatures_and_times = dict(zip(s.hashes, s.times))
        posts = []

        tags_entity = Tags.get_single()
        tags = set(tags_entity.available)

        for entry in d['entries']:
            blog_post = BlogPost.blog_post_from_feed_entry(entry)
            signature_time = signatures_and_times.get(blog_post.signature)
            if signature_time:
                signature_time = datetime.datetime.fromtimestamp(signature_time).strftime('%m/%d/%Y %H:%M')
            posts.append((blog_post, signature_time))

            for tag in blog_post.tags:
                tags.add(tag.lower())

        template_values = {"posts":posts}

        tags_entity.available = list(tags)
        tags_entity.save()

        template = jinja_environment.get_template('moderate.html')
        self.response.out.write(template.render(template_values))
开发者ID:darvin,项目名称:moderated-feed-gae-server,代码行数:28,代码来源:admin.py


示例5: request_json

def request_json(**kwargs):
    if request.json:
        global r
        r = Resource()
        for k, v in kwargs.iteritems():
            r.rid = v  # Now automatically updated
        r.title = request.json['title']
        r.link = str(request.json['link'])
        # Insert Tags to Tags Object
        r.tags = []
        for item in request.json['tags']:
            t = Tags()
            t.tag_name = item['tag_name']
            r.tags.append(t)
        r.description = request.json['description']
        r.save(upsert=True)
开发者ID:CuriousLearner,项目名称:TrackMyLinks,代码行数:16,代码来源:views.py


示例6: tags_cloud

def tags_cloud():
    '''Get dict of tags, numbers.'''
    tags = Tags.all()
    tags_dict = []
    for tag in tags:
        tags_dict.append({'name': tag.name, 'size': tag.count * 10})
    return tags_dict
开发者ID:greggy,项目名称:gae-blog,代码行数:7,代码来源:utils.py


示例7: get_tag_synonyms

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,代码行数:7,代码来源:app.py


示例8: next

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,代码行数:47,代码来源:app.py


示例9: insert

def insert(request):
    status=None
    if request.method == 'POST':
       # save new post
       Usr_Name = request.POST.get('name','')
       Usr_Mobile = request.POST.get('mobile','')
       Usr_Remark = request.POST.get('remark','')
       tags = request.POST.get('tags','')
       pre_id = request.POST.get('pre_id','')
       p_uuid = uuid.uuid1()
       p = People(Usr_Name = Usr_Name,Usr_Mobile = Usr_Mobile,Usr_Remark=Usr_Remark,active = 0,isdel = 0,uuid = p_uuid,)
       p.save()

       for tag in tags.replace(u',',',').split(','):
           try:
               t = Tags.objects.get(tag = tag)
           except Tags.DoesNotExist:
               newtag = Tags(tag=tag)
               newtag.save()
               p.tags.add(newtag)
               p.save()
           else:
               p.tags.add(t)
               p.save()
       if request.user.is_superuser:
           status="ok"
           p.Cluster_id = 0
           p.save()
           return render_to_response('usernet/index.html', {'status':status,},
                              context_instance=RequestContext(request))
       if pre_id =='':
           pre_id = request.user
       if pre_id != '':
           try:
               pre = People.objects.filter(Usr_Mobile = pre_id,active = 1)
           except People.DoesNotExist:
               print "error"
           else:
               p.Prev_Usr=pre[0]
               p.Cluster_id = pre[0].Cluster_id
               p.save()
       status="ok"
    # Get all posts from DB
    return render_to_response('usernet/index.html', {'status':status,},
                              context_instance=RequestContext(request))
开发者ID:qiankai,项目名称:cms,代码行数:45,代码来源:views.py


示例10: get

    def get(self):

        tags = Tags.get_single()

        template_values = {"tags_enabled":tags.enabled,
                           "tags_available":tags.available}

        template = jinja_environment.get_template('tags.html')
        self.response.out.write(template.render(template_values))
开发者ID:darvin,项目名称:moderated-feed-gae-server,代码行数:9,代码来源:admin.py


示例11: api_create_blog

def api_create_blog():
    check_admin()
    i= ctx.request.input(title='', tags='', content='')
    title = i['title'].strip()
    tags = i['tags'].strip()
    content = i['content'].strip()
    if not title:
        raise APIValueError('title', 'title can not be empty.')
    if not content:
        raise APIValueError('content', 'content can not be empty.')
    summary = _get_summary(content)
    blog = Blogs(title=title, tags=tags, summary=summary, content=content)
    id = blog.insert_id()
    if tags:
        for tag in tags.split(','):
            tag = Tags(tag=tag, blog=id)
            tag.insert()
    return dict(id=id)
开发者ID:1007650105,项目名称:blog,代码行数:18,代码来源:urls.py


示例12: delete_post

def delete_post(id):

    if users.is_current_user_admin():
        posts = Posts()

        tags = Tags()

        categories = Categories()

        updating_post = BlogPost.get(int(id))

        categories.delete(updating_post.category)

        posts.delete(updating_post.key)

        tags.update(updating_post.get_tag_names())

    return jsonify(msg="OK")
开发者ID:aarsakian,项目名称:blog,代码行数:18,代码来源:views.py


示例13: get

 def get(self):
     bm = Bookmarks.get_by_id(int(self.request.get('bm')))
     tag = Tags.get_by_id(int(self.request.get('tag')))
     # if users.get_current_user() == bm.user:
     bm.tags.remove(tag.key)
     bm.put()
     template = jinja_environment.get_template('tags.html')
     values = {'bm': bm} 
     tags = template.render(values)
     self.response.write(tags)
开发者ID:antiface,项目名称:gae.icio.us,代码行数:10,代码来源:ajax.py


示例14: import_tags

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,代码行数:20,代码来源:load_to_mongo.py


示例15: rpc_get_indexes_for_tag

    def rpc_get_indexes_for_tag(self, tag):
        """
        Get search strings for the specified tag.

        @argument tag
        @returns 
        """
        indexes = Tags.get_indexes(tag)
        if not indexes:
            return {}
        return indexes
开发者ID:ciju,项目名称:yql_hash,代码行数:11,代码来源:yql_hash.py


示例16: update

def update(request):
    if request.method == 'GET':
        pid = request.GET.get('id')
        p = People.objects.get(id = pid)
        tags = p.tags.all()
        tag=[]
        ta = ''
        for i in tags:
            tag.append(i.tag)
            ta = ta+ i.tag+','
        return render_to_response('usernet/update.html',{'person':p ,'tags':tag,'ta':ta,},
                              context_instance=RequestContext(request))
    if request.method == 'POST':
        pid = request.POST.get('id')
        Usr_Name = request.POST.get('name','')
        Usr_Mobile = request.POST.get('mobile','')
        Usr_Remark = request.POST.get('remark','')
        tags = request.POST.get('tags','')
        pre_id = request.POST.get('pre_id','')


        p = People.objects.get(id = pid)
        p.Usr_Name =Usr_Name
        p.Usr_Mobile = Usr_Mobile
        p.Usr_Remark = Usr_Remark
        for tag in tags.replace(u',',',').split(','):
           try:
               t = Tags.objects.get(tag = tag)
           except Tags.DoesNotExist:
               newtag = Tags(tag=tag)
               newtag.save()
               p.tags.add(newtag)
               p.save()
           else:
               p.tags.add(t)
               p.save()

        status = "Update " + p.Usr_Name  + " successfully!"
        status_code = 1
        return render_to_response('usernet/message.html',{'status':status,'status_code':status_code,},
                              context_instance=RequestContext(request))
开发者ID:qiankai,项目名称:cms,代码行数:41,代码来源:views.py


示例17: shred

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,代码行数:41,代码来源:app.py


示例18: post

def post(request, slug):
    try:
        db_blog = Posts.objects.get(slug=slug)
    except:
        db_blog = None
    if db_blog:
        db_blog.tag_set.all().delete()
    form = PostsForm(request.POST, instance=db_blog)
    ##print( "content %s" % request.POST.get("content"))
    if form.is_valid():
        blog_post = form.save(commit=False)
        blog_post.mark_down = blogContentRender(blog_post.content)
        tags = blog_post.tags.split(',')
        blog_post.save()
        for tag in tags:
            t = Tags()
            t.post = Posts.objects.get(slug=blog_post.slug)
            t.name = tag.strip()
            t.save()
        form.save_m2m()
        return HttpResponseRedirect("/")
    c = {"form": form, "slug": slug}
    c.update(csrf(request))
    t = get_template("publish.html")
    return HttpResponse(t.render(Context(c)))
开发者ID:linlihai,项目名称:pyblog,代码行数:25,代码来源:views.py


示例19: main

def main():

    if users.is_current_user_admin():
        if request.method=='GET':  #all entitites
            posts = Posts()

            return jsonify(posts.to_json())

        elif request.method == "POST":

            form = PostForm()
            if form.validate_on_submit():  #new entity
                posts = Posts()
                categories = Categories()
                tags = Tags()

                raw_post = request.get_json()
                raw_category = raw_post["category"]
                editing_tags = raw_post["tags"]
                raw_summary = raw_post["summary"]


                tag_keys = tags.update(editing_tags)
                category_key = categories.update(raw_category)

                post_id = posts.add(raw_title=raw_post["title"],
                            raw_body=raw_post["body"],
                            category_key=category_key,
                            tags_ids=tag_keys,
                            summary=raw_summary,
                            answers=raw_post["answers"]).id()
                post = BlogPost.get(post_id)
                return jsonify(post.to_json()) #  Needs check
            else:
                return jsonify(msg="missing token")
    else:
        return jsonify({})
开发者ID:aarsakian,项目名称:blog,代码行数:37,代码来源:views.py


示例20: test_has_some_tasks

    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,代码行数:15,代码来源:tagging.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Task类代码示例发布时间:2022-05-27
下一篇:
Python models.Tag类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap