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


Python User.by_sid方法代码示例

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


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

示例1: post

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import by_sid [as 别名]
 def post(self):
     oldpass = self.get_argument("oldpass", "")
     newpass = self.get_argument("newpass", "")
     newpass = hashlib.md5(newpass).hexdigest()
     user = User.by_sid(self.current_user["user_id"])
     if user.user_pass == hashlib.md5(oldpass).hexdigest():
         user = User.by_sid(self.current_user["user_id"])
         user["user_pass"] = newpass
         user.save()
         self.redirect("/setting")
     else:
         self.redirect("/setting")  # self.write('Wrong password')
开发者ID:anwen,项目名称:anwen,代码行数:14,代码来源:user.py

示例2: get

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import by_sid [as 别名]
 def get(self, node='home'):
     page = self.get_argument("page", 1)
     # share_res = Share.find({'status': 0}).sort(
     #     'score', DESCENDING).limit(11).skip((int(page) - 1) * 11)
     share_res = Share.find({'status': {'$gte': 1}}).sort(
         '_id', DESCENDING).limit(11).skip((int(page) - 1) * 11)
     pagesum = (share_res.count() + 10) / 11
     shares = []
     for share in share_res:
         if share.id in (48, 47):
             continue
         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 = cutter(
             markdown2.markdown(share.markdown))
         share.title = share.title.split('_')[0]
         shares.append(share)
     self.render(
         "node.html",
         shares=shares,
         pagesum=pagesum, page=page, node=node,
     )
开发者ID:anwen,项目名称:anwen,代码行数:27,代码来源:index.py

示例3: get

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import by_sid [as 别名]
    def get(self, node):
        page = self.get_argument("page", 1)
        share_res = Share.find({'sharetype': node}).sort(
            '_id', DESCENDING).limit(10).skip((int(page) - 1) * 10)
        pagesum = (share_res.count() + 9) / 10

        shares = []
        for share in share_res:
            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]
            share.gravatar = get_avatar(user.user_email, 16)
            shares.append(share)
        members = User.find().sort('_id', DESCENDING).limit(20)
        members_dict = []
        for member in members:
            member.gravatar = get_avatar(member.user_email, 25)
            members_dict.append(member)
        node_about = options.node_about[node]
        self.render(
            "node.html", shares=shares, members=members_dict,
            pagesum=pagesum, page=page, node=node, node_about=node_about)
开发者ID:facesun,项目名称:anwen,代码行数:28,代码来源:index.py

示例4: post

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

示例5: post

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import by_sid [as 别名]
 def post(self):
     user = User.by_sid(self.current_user['user_id'])
     user['user_name'] = self.get_argument('name', None)
     user['user_city'] = self.get_argument('city', None)
     user['user_say'] = self.get_argument('say', None)
     user.save()
     self.redirect('/setting')
开发者ID:vivekjishtu,项目名称:anwen,代码行数:9,代码来源:user.py

示例6: post

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

示例7: get

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import by_sid [as 别名]
    def get(self):
        share_res = Share.find()
        shares = []
        for share in share_res:
            user = User.by_sid(share.user_id)
            share.name = user.user_name
            share.published = datetime.datetime.fromtimestamp(share.published)
            share.updated = datetime.datetime.fromtimestamp(share.updated)
            share.domain = user.user_domain
            share.content = markdown2.markdown(share.markdown)
            shares.append(share)

        self.set_header("Content-Type", "application/atom+xml")
        self.render("feed.xml", shares=shares)
开发者ID:vivekjishtu,项目名称:anwen,代码行数:16,代码来源:share.py

示例8: post

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User 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 User [as 别名]
# 或者: from db.User import by_sid [as 别名]
    def get(self, node):
        page = self.get_argument("page", 1)
        share_res = Share.find({"sharetype": node}).sort("_id", DESCENDING).limit(11).skip((int(page) - 1) * 11)
        pagesum = (share_res.count() + 10) / 11

        shares = []
        for share in share_res:
            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))[:400]
            share.gravatar = get_avatar(user.user_email, 16)
            shares.append(share)

        node_about = options.node_about[node]
        self.render("node.html", shares=shares, pagesum=pagesum, page=page, node=node, node_about=node_about)
开发者ID:bowu8,项目名称:anwen,代码行数:19,代码来源:index.py

示例10: get

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import by_sid [as 别名]
 def get(self):
     sharetype = self.get_argument("sharetype", "goodlink")
     link = self.get_argument("link", '')
     user_id = self.current_user["user_id"]
     assert link
     url = link
     doc = Webcache.find_one({'url': url}, {'_id': 0})
     if not doc:
         sessions = requests.session()
         sessions.headers[
             'User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36'
         response = sessions.get(url)
         # response.encoding = 'utf-8'  # TODO
         response.encoding = get_charset(response)
         logger.info('response.encoding {}'.format(response.encoding))
         doc = Document(response.text)
         doc_title = doc.title()
         summary = doc.summary()
         _markdown = html2text.html2text(summary)
         _markdown = _markdown.replace('-\n', '-').strip()
         res_webcache = {}
         res_webcache['url'] = url
         res_webcache['title'] = doc_title
         res_webcache['markdown'] = _markdown
         if _markdown:
             webcache = Webcache
             webcache.new(res_webcache)
     else:
         logger.info('already')
         doc_title = doc.title
     res = {
         'title': doc_title,
         'sharetype': sharetype,
         'link': link,
     }
     share = Share
     res['user_id'] = user_id
     share = share.new(res)
     user = User.by_sid(user_id)
     user.user_leaf += 10
     user.save()
     self.redirect("/share/" + str(share.id))
开发者ID:anwen,项目名称:anwen,代码行数:44,代码来源:share_by_get.py

示例11: post

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

示例12: get

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import by_sid [as 别名]
    def get(self, node):
        page = self.get_argument("page", 1)
        share_res = Share.find({'sharetype': node}).sort(
            '_id', DESCENDING).limit(11).skip((int(page) - 1) * 11)
        pagesum = (share_res.count() + 10) / 11

        shares = []
        for share in share_res:
            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 = cutter(
                markdown2.markdown(share.markdown))
            shares.append(share)

        node_info = options.node_about[node]
        self.render(
            "node.html", shares=shares,
            pagesum=pagesum, page=page, node=node, node_info=node_info)
开发者ID:randy-ran,项目名称:anwen,代码行数:23,代码来源:index.py

示例13: get

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import by_sid [as 别名]
    def get(self, node='home'):
        page = self.get_argument("page", 1)
        share_res = Share.find({'status': 0}).sort(
            'score', DESCENDING).limit(11).skip((int(page) - 1) * 11)

        pagesum = (share_res.count() + 10) / 11
        shares = []
        for share in share_res:
            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))[:400]
            share.gravatar = get_avatar(user.user_email, 16)
            shares.append(share)

        self.render(
            "node.html", shares=shares,
            pagesum=pagesum, page=page, node=node,
        )
开发者ID:vivekjishtu,项目名称:anwen,代码行数:24,代码来源:index.py

示例14: get

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

示例15: get

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import by_sid [as 别名]
 def get(self):
     user = User.by_sid(self.current_user['user_id'])
     user.user_jointime = time.strftime(
         '%Y-%m-%d %H:%M:%S', time.localtime(user.user_jointime))
     user.gravatar = get_avatar(user.user_email.encode('u8'), 100)
     self.render('setting.html', user=user)
开发者ID:anwen,项目名称:anwen,代码行数:8,代码来源:user_setting.py


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