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


Python Share.by_sid方法代码示例

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


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

示例1: post

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
    def post(self):
        id = self.get_argument("id", None)
        tags = self.get_argument("tags", '')
        user_id = self.current_user["user_id"]
        res = {
            'title': self.get_argument("title"),
            'markdown': self.get_argument("markdown"),
            'sharetype': self.get_argument("type"),
            'slug': self.get_argument("slug", ''),
            'tags': tags,
            'updated': time.time(),
        }

        if id:
            share = Share.by_sid(id)
            if not share:
                self.redirect("/404")
            share.update(res)
            share.save()
        else:
            share = Share
            res['user_id'] = user_id
            share = share.new(res)
            user = User.by_sid(user_id)
            user.user_leaf += 10
            user.save()
        for i in tags.split(' '):
            Tag.new(i, share.id)
        self.redirect("/share/" + str(share.id))
开发者ID:facesun,项目名称:anwen,代码行数:31,代码来源:share.py

示例2: post

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
    def post(self):
        share_id = self.get_argument("share_id", None)
        tags = self.get_argument("tags", '')
        # user_id = self.current_user["user_id"]
        tags = tags.strip()
        if share_id:
            share = Share.by_sid(share_id)
            if share and tags not in share.tags:
                tags = share.tags + ' ' + tags
                res = {
                    'tags': tags,
                    'updated': time.time(),
                }

                share.update(res)
                share.save()

                tags = tags.split(' ')
                tags = list(set(tags))
                for i in tags:
                    doc = {
                        'name': i,
                        'share_ids': share.id
                    }
                    Tag.new(doc)
开发者ID:anwen,项目名称:anwen,代码行数:27,代码来源:api_tag.py

示例3: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
 def get(self):
     action = self.request.path[7:]
     share_res = Share.find()
     if 'add' in action:
         do, share_id, suggestscore = action.split('!')
         share = Share.by_sid(share_id)
         share.suggestscore = float(suggestscore)
         share.save()
     for share in share_res:
         share.score = 0.001 * share.hitnum + share.likenum - \
             share.dislikenum + 0.5 * share.commentnum - \
             share.status + share.suggestscore + 0.5 * share.id
         share.save()
     # self.write_json({'objs': list(Share.find().sort('score',
     # DESCENDING))})
     share_res = Share.find().sort('score', DESCENDING)
     display = ''
     display += '<p>score sugg hit like dis comment status title id</p>'
     for share in share_res:
         display += '<p>%s  %s  %s  %s  %s  %s  %s  %s  %s</p>' % (
             share.score,
             share.suggestscore,
             share.hitnum,
             share.likenum,
             share.dislikenum,
             share.commentnum,
             share.status,
             share.title,
             share.id)
     self.write(display)
开发者ID:randy-ran,项目名称:anwen,代码行数:32,代码来源:other.py

示例4: post

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
 def post(self):
     commentbody = self.get_argument("commentbody", None)
     share_id = self.get_argument("share_id", None)
     html = markdown2.markdown(commentbody)
     comment = Comment
     doc = {}
     doc['user_id'] = self.current_user["user_id"]
     doc['share_id'] = int(share_id)
     doc['commentbody'] = commentbody
     comment.new(doc)
     share = Share.by_sid(share_id)
     share.commentnum += 1
     share.save()
     name = tornado.escape.xhtml_escape(self.current_user["user_name"])
     gravatar = get_avatar(self.current_user["user_email"], 50)
     newcomment = ''.join([
         '<div class="comment">',
         '<div class="avatar">',
         '<img src="', gravatar,
         '</div>',
         '<div class="name">', name,
         '</div>',
         '<div class="date" title="at"></div>', html,
         '</div>',
     ])
     self.write(newcomment)
开发者ID:bowu8,项目名称:anwen,代码行数:28,代码来源:share.py

示例5: post

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
 def post(self, action):
     share_id = int(self.get_argument("share_id", None))
     user_id = self.current_user["user_id"]
     doc = {
         'user_id': user_id,
         'share_id': share_id
     }
     newlikes = None
     if action == 'addlike':
         Like.change_like(doc, 'likenum')
         share = Share.by_sid(share_id)
         share.likenum += 1
         share.save()
         user = User.by_sid(share.user_id)
         user.user_leaf += 4
         user.save()
         user = User.by_sid(user_id)
         user.user_leaf += 2
         user.save()
         newlikes = str(share.likenum)
     elif action == 'dellike':
         Like.change_like(doc, 'likenum')
         share = Share.by_sid(share_id)
         share.likenum -= 1
         share.save()
         user = User.by_sid(share.user_id)
         user.user_leaf -= 4
         user.save()
         user = User.by_sid(user_id)
         user.user_leaf -= 2
         user.save()
         newlikes = str(share.likenum)
     elif action == 'adddislike':
         Like.change_like(doc, 'dislikenum')
         share = Share.by_sid(share_id)
         share.dislikenum += 1
         share.save()
         newlikes = str(share.dislikenum)
     elif action == 'deldislike':
         Like.change_like(doc, 'dislikenum')
         share = Share.by_sid(share_id)
         share.dislikenum -= 1
         share.save()
         newlikes = str(share.dislikenum)
     self.write(newlikes)
开发者ID:randy-ran,项目名称:anwen,代码行数:47,代码来源:share.py

示例6: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
 def get(self):
     share_id = self.get_argument("id", None)
     share = None
     if share_id:
         share = Share.by_sid(share_id)
     editor = self.get_argument("editor", options.default_editor)
     if editor:
         self.render("share_wysiwyg.html", share=share)
     else:
         self.render("share.html", share=share)
开发者ID:vivekjishtu,项目名称:anwen,代码行数:12,代码来源:share.py

示例7: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
 def get(self, name):
     user = User.find_one({"user_domain": name})
     user.user_jointime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(user.user_jointime))
     like_res = Like.find({"user_id": user.id})
     likenum = like_res.count()
     likes = []
     for like in like_res:
         share = Share.by_sid(like.share_id)
         like.title = share.title
         like.id = share.id
         like.type = share.sharetype
         likes.append(like)
     user.gravatar = get_avatar(user.user_email, 100)
     self.render("userlike.html", user=user, likenum=likenum, likes=likes)
开发者ID:anwen,项目名称:anwen,代码行数:16,代码来源:user.py

示例8: post

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
    def post(self):
        # print self.request.arguments
        share_id = self.get_argument("id", None)
        title = self.get_argument("title", '')
        markdown = self.get_argument("markdown", '')
        content = self.get_argument("content", '')
        sharetype = self.get_argument("type", '')
        slug = self.get_argument("slug", '')
        status = 1 if self.get_argument("dosubmit", None) == u'保存草稿' else 0
        tags = self.get_argument("tags", '')
        upload_img = self.get_argument("uploadImg", '')
        post_img = self.get_argument("post_Img", '')
        post_img = '' if post_img == 'None' else post_img
        user_id = self.current_user["user_id"]
        res = {
            'title': title,
            'markdown': markdown,
            'content': content,
            'sharetype': sharetype,
            'slug': slug,
            'tags': tags,
            'status': status,
            'upload_img': upload_img,
            'post_img': post_img,
            'updated': time.time(),
        }

        if share_id:
            share = Share.by_sid(share_id)
            if not share:
                self.redirect("/404")
            share.update(res)
            share.save()
        else:
            share = Share
            res['user_id'] = user_id
            share = share.new(res)
            user = User.by_sid(user_id)
            user.user_leaf += 10
            user.save()
        for i in tags.split(' '):
            doc = {
                'name': i,
                'share_ids': share.id
            }
            Tag.new(doc)
        if status == 1:
            self.redirect("/share/?id=" + str(share.id))
        self.redirect("/share/" + str(share.id))
开发者ID:vivekjishtu,项目名称:anwen,代码行数:51,代码来源:share.py

示例9: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
 def get(self):
     share_id = self.get_argument("id", None)
     sharetype = self.get_argument("sharetype", None)
     editor = self.get_argument("editor", options.default_editor)
     share = None
     if share_id:
         share = Share.by_sid(share_id)
         sharetype = share.sharetype if share else None
     print(sharetype)
     if sharetype == 'goodlink':
         self.render("share_link.html", share=share)
     if editor:
         self.render("share_wysiwyg.html", share=share)
     else:
         self.render("share.html", share=share)
开发者ID:vipwp,项目名称:anwen,代码行数:17,代码来源:share.py

示例10: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
 def get(self, name=None):
     if not name:
         tags = Tag.find()
         self.render("tag.html", tags=tags)
     else:
         tag = Tag.find_one({'name': name})
         shares = []
         for i in tag.share_ids.split(' '):
             share = Share.by_sid(i)
             user = User.by_sid(share.user_id)
             share.name = user.user_name
             share.published = time.strftime(
                 '%Y-%m-%d %H:%M:%S', time.localtime(share.published))
             share.domain = user.user_domain
             share.markdown = filter_tags(
                 markdown2.markdown(share.markdown))[:100]
             shares.append(share)
         self.render("tage.html", name=name, shares=shares)
开发者ID:anwen,项目名称:anwen,代码行数:20,代码来源:index.py

示例11: post

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
    def post(self, action):
        entity_id = int(self.get_argument("entity_id", 0))
        entity_type = self.get_argument("entity_type", None)
        user_id = self.current_user["user_id"]
        assert action in 'addlike dellike adddislike deldislike'.split()
        assert entity_type in 'share comment viewpoint'.split()
        _action = action[3:] + 'num'
        doc = {
            'user_id': user_id,
            'entity_id': entity_id,
            'entity_type': entity_type,
        }
        is_changed = Like.change_like(doc, _action, action[:3])

        # 冗余储存 没有做成事件绑定,需要定期校验修复
        if entity_type == 'share':
            entity = Share.by_sid(entity_id)
            # 如果是管理员,需要将status + 1
            # 64=kp 65=kp email
            # 63=lb
            # 60=xie
            if is_changed and user_id in admin_ids:
                if action == 'addlike':
                    entity['status'] += 1
                elif action == 'adddislike':
                    entity['status'] -= 1
                elif action == 'deldislike':
                    entity['status'] += 1
                else:
                    entity['status'] -= 1
        elif entity_type == 'comment':
            entity = Comment.by_sid(entity_id)
        elif entity_type == 'viewpoint':
            entity = Viewpoint.by_sid(entity_id)
        if action[:3] == 'add':
            entity[_action] += 1
        else:
            entity[_action] -= 1
        entity.save()
        self.res = {
            'likenum': entity.likenum,
            'dislikenum': entity.dislikenum,
        }
        self.write_json()
开发者ID:anwen,项目名称:anwen,代码行数:46,代码来源:api_like.py

示例12: get_share_by_slug

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
def get_share_by_slug(slug):
    # 特殊id ramdom
    if slug == 'random':
        cond = {}
        cond['status'] = {'$gte': 1}
        # shares = Share.find(cond, {'_id': 0})
        shares = Share.find(cond)
        share = random.choice(list(shares))
    elif slug.isdigit():
        share = Share.by_sid(slug)
    else:
        share = Share.by_slug(slug)
    if share:
        share.hitnum += 1
        if isinstance(share.tags, str):
            share.tags = share.tags.split()
        share.save()
        share.pop('_id')
    return share
开发者ID:anwen,项目名称:anwen,代码行数:21,代码来源:api_share.py

示例13: post

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
 def post(self):
     commentbody = self.get_argument("commentbody", None)
     share_id = self.get_argument("share_id", None)
     comment = Comment
     doc = {}
     doc['user_id'] = self.current_user["user_id"]
     user = User.by_sid(self.current_user["user_id"])
     # user_name in current_user is not the newest
     doc['user_name'] = user["user_name"]
     doc['share_id'] = int(share_id)
     doc['commentbody'] = commentbody
     comment.new(doc)
     share = Share.by_sid(share_id)
     share.commentnum += 1
     share.save()
     # name = tornado.escape.xhtml_escape(self.current_user["user_name"])
     # gravatar = get_avatar(self.current_user["user_email"], 50)
     self.res = {
         'success': True,
     }
     self.write_json()
开发者ID:anwen,项目名称:anwen,代码行数:23,代码来源:api_comment.py

示例14: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import by_sid [as 别名]
    def get(self, slug):
        share = None
        if slug.isdigit():
            share = Share.by_sid(slug)
        else:
            share = Share.by_slug(slug)
        if share:
            share.hitnum += 1
            share.save()
            share.markdown = markdown2.markdown(share.markdown)
            user = User.by_sid(share.user_id)
            share.user_name = user.user_name
            share.user_domain = user.user_domain
            tags = ''

            if share.tags:
                tags += 'tags:'
                for i in share.tags.split(' '):
                    tags += '<a href="/tag/%s">%s</a>  ' % (i, i)
            share.tags = tags
            user_id = int(
                self.current_user["user_id"]) if self.current_user else None
            like = Like.find_one(
                {'share_id': share.id, 'user_id': user_id})
            share.is_liking = bool(like.likenum % 2) if like else None
            share.is_disliking = bool(like.dislikenum % 2) if like else None
            comments = []
            comment_res = Comment.find({'share_id': share.id})
            for comment in comment_res:
                user = User.by_sid(comment.user_id)
                comment.name = user.user_name
                comment.domain = user.user_domain
                comment.gravatar = get_avatar(user.user_email, 50)
                comments.append(comment)

            if user_id:
                hit = Hit.find(
                    {'share_id': share.id},
                    {'user_id': int(self.current_user["user_id"])},
                )
                if hit.count() == 0:
                    hit = Hit
                    hit['share_id'] = share.id
                    hit['user_id'] = int(self.current_user["user_id"])
                    hit.save()
            else:
                if not self.get_cookie(share.id):
                    self.set_cookie(str(share.id), "1")
            posts = Share.find()
            suggest = []
            for post in posts:
                post.score = 100 + post.id - post.user_id + post.commentnum * 3
                post.score += post.likenum * 4 + post.hitnum * 0.01
                post.score += randint(1, 999) * 0.001
                common_tags = [i for i in post.tags.split(
                    ' ') if i in share.tags.split(' ')]
                # list(set(b1) & set(b2))
                post.score += len(common_tags)
                if post.sharetype == share.sharetype:
                    post.score += 5
                if self.current_user:
                    is_hitted = Hit.find(
                        {'share_id': share._id},
                        {'user_id': int(self.current_user["user_id"])},
                    ).count() > 0
                else:
                    is_hitted = self.get_cookie(share.id)
                if is_hitted:
                    post.score -= 50
                suggest.append(post)
            suggest.sort(key=lambda obj: obj.get('score'))
            suggest = suggest[:5]
            self.render(
                "sharee.html", share=share, comments=comments,
                suggest=suggest)
        else:
            old = 'http://blog.anwensf.com/'
            for i in options.old_links:
                if slug in i:
                    self.redirect('%s%s' % (old, i), permanent=True)
                    break
                    return
            self.redirect("/404")
开发者ID:bowu8,项目名称:anwen,代码行数:85,代码来源:share.py


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