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

Python thing.Thing类代码示例

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

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



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

示例1: __init__

    def __init__(self, ups = 0, downs = 0, date = None, deleted = False,
                 spam = False, id = None, descendant_karma = 0, **attrs):

        Thing.__init__(self, ups, downs, date, deleted, spam, id, **attrs)

        with self.safe_set_attr:
            self._descendant_karma = descendant_karma
开发者ID:LucasSloan,项目名称:lesswrong,代码行数:7,代码来源:link.py


示例2: _commit

    def _commit(self, *a, **kw):
        """Detect when we need to invalidate the sidebar recent posts.

        Whenever a post is created we need to invalidate.  Also invalidate when
        various post attributes are changed (such as moving to a different
        subreddit). If the post cache is invalidated the comment one is too.
        This is primarily for when a post is banned so that its comments
        dissapear from the sidebar too.
        """

        should_invalidate = (not self._created or
                             frozenset(('title', 'sr_id', '_deleted', '_spam')) & frozenset(self._dirties.keys()))

        Thing._commit(self, *a, **kw)

        if should_invalidate:
            g.rendercache.delete('side-posts' + '-' + c.site.name)
            g.rendercache.delete('side-comments' + '-' + c.site.name)
            tags = self.tag_names()
            if 'open_thread' in tags:
                g.rendercache.delete('side-open' + '-' + c.site.name)
            if 'quotes' in tags:
                g.rendercache.delete('side-quote' + '-' + c.site.name)
            if 'group_rationality_diary' in tags:
                g.rendercache.delete('side-diary' + '-' + c.site.name)
开发者ID:brendanlong,项目名称:lesswrong,代码行数:25,代码来源:link.py


示例3: _commit

    def _commit(self, *a, **kw):
        """Detect when we need to invalidate the sidebar recent comments.

        Whenever a comment is created we need to invalidate.  Also
        invalidate when various comment attributes are changed.
        """

        should_invalidate = (not self._created or
                             frozenset(('body', '_deleted', '_spam')) & frozenset(self._dirties.keys()))

        Thing._commit(self, *a, **kw)

        if should_invalidate:
            g.rendercache.delete('side-comments' + '-' + c.site.name)
开发者ID:Craigus,项目名称:lesswrong,代码行数:14,代码来源:link.py


示例4: _commit

    def _commit(self, *a, **kw):
        """Detect when we need to invalidate the sidebar recent posts.

        Whenever a post is created we need to invalidate.  Also
        invalidate when various post attributes are changed (such as
        moving to a different subreddit).
        """

        should_invalidate = (not self._created or
                             frozenset(('title', 'sr_id', '_deleted', '_spam')) & frozenset(self._dirties.keys()))

        Thing._commit(self, *a, **kw)

        if should_invalidate:
            g.rendercache.delete('side-posts')
开发者ID:Kakun1,项目名称:lesswrong,代码行数:15,代码来源:link.py


示例5: __getattr__

 def __getattr__(self, attr):
     val = Thing.__getattr__(self, attr)
     if attr in ('start_date', 'end_date'):
         val = to_datetime(val)
         if not val.tzinfo:
             val = val.replace(tzinfo=g.tz)
     return val
开发者ID:dinxx,项目名称:reddit,代码行数:7,代码来源:promo.py


示例6: _handle_vote

    def _handle_vote(msgs, chan):
        comments = []

        for msg in msgs:
            tag = msg.delivery_tag
            r = pickle.loads(msg.body)

            uid, tid, dir, ip, organic, cheater = r
            voter = Account._byID(uid, data=True)
            votee = Thing._by_fullname(tid, data = True)
            if isinstance(votee, Comment):
                comments.append(votee)

            if not isinstance(votee, (Link, Comment)):
                # I don't know how, but somebody is sneaking in votes
                # for subreddits
                continue

            print (voter, votee, dir, ip, organic, cheater)
            try:
                handle_vote(voter, votee, dir, ip, organic,
                            cheater=cheater, foreground=False)
            except Exception, e:
                print 'Rejecting %r:%r because of %r' % (msg.delivery_tag, r,e)
                chan.basic_reject(msg.delivery_tag, requeue=True)
开发者ID:rram,项目名称:reddit,代码行数:25,代码来源:queries.py


示例7: _handle_vote

    def _handle_vote(msg):
        r = pickle.loads(msg.body)

        uid, tid, dir, ip, organic, cheater = r
        voter = Account._byID(uid, data=True)
        votee = Thing._by_fullname(tid, data = True)

        print (voter, votee, dir, ip, organic, cheater)
        handle_vote(voter, votee, dir, ip, organic,
                    cheater = cheater)
开发者ID:XieConnect,项目名称:reddit,代码行数:10,代码来源:queries.py


示例8: _handle_vote

    def _handle_vote(msgs, chan):
        assert(len(msgs) == 1)
        msg = msgs[0]

        r = pickle.loads(msg.body)

        uid, tid, dir, ip, organic, cheater = r
        voter = Account._byID(uid, data=True)
        votee = Thing._by_fullname(tid, data = True)

        print (voter, votee, dir, ip, organic, cheater)
        handle_vote(voter, votee, dir, ip, organic,
                    cheater = cheater)
开发者ID:codetripping,项目名称:reddit,代码行数:13,代码来源:queries.py


示例9: _handle_vote

    def _handle_vote(msg):
        # assert(len(msgs) == 1)
        r = pickle.loads(msg.body)

        uid, tid, dir, ip, organic, cheater = r
        voter = Account._byID(uid, data=True)
        votee = Thing._by_fullname(tid, data=True)
        if isinstance(votee, Comment):
            update_comment_votes([votee])

        # I don't know how, but somebody is sneaking in votes
        # for subreddits
        if isinstance(votee, (Link, Comment)):
            print (voter, votee, dir, ip, organic, cheater)
            handle_vote(voter, votee, dir, ip, organic, cheater=cheater, foreground=True)
开发者ID:ap0rnnstar,项目名称:reddit,代码行数:15,代码来源:queries.py


示例10: _handle_vote

    def _handle_vote(msgs, chan):
        # assert(len(msgs) == 1)
        comments = []
        for msg in msgs:
            r = pickle.loads(msg.body)

            uid, tid, dir, ip, organic, cheater = r
            voter = Account._byID(uid, data=True)
            votee = Thing._by_fullname(tid, data=True)
            if isinstance(votee, Comment):
                comments.append(votee)

            print (voter, votee, dir, ip, organic, cheater)
            handle_vote(voter, votee, dir, ip, organic, cheater=cheater)

        update_comment_votes(comments)
开发者ID:rmasters,项目名称:reddit,代码行数:16,代码来源:queries.py


示例11: from_queue

    def from_queue(self, max_date, batch_limit = 50, kind = None):
        from r2.models import is_banned_IP, Account, Thing
        keep_trying = True
        min_id = None
        s = self.queue_table
        while keep_trying:
            where = [s.c.date < max_date]
            if min_id:
                where.append(s.c.uid > min_id)
            if kind:
                where.append(s.c.kind == kind)
                
            res = sa.select([s.c.to_addr, s.c.account_id,
                             s.c.from_name, s.c.fullname, s.c.body, 
                             s.c.kind, s.c.ip, s.c.date, s.c.uid,
                             s.c.msg_hash, s.c.fr_addr, s.c.reply_to],
                            sa.and_(*where),
                            order_by = s.c.uid, limit = batch_limit).execute()
            res = res.fetchall()

            if not res: break

            # batch load user accounts
            aids = [x[1] for x in res if x[1] > 0]
            accts = Account._byID(aids, data = True,
                                  return_dict = True) if aids else {}

            # batch load things
            tids = [x[3] for x in res if x[3]]
            things = Thing._by_fullname(tids, data = True,
                                        return_dict = True) if tids else {}

            # make sure no IPs have been banned in the mean time
            ips = set(x[6] for x in res)
            ips = dict((ip, is_banned_IP(ip)) for ip in ips)

            # get the lower bound date for next iteration
            min_id = max(x[8] for x in res)

            # did we not fetch them all?
            keep_trying = (len(res) == batch_limit)
        
            for (addr, acct, fname, fulln, body, kind, ip, date, uid, 
                 msg_hash, fr_addr, reply_to) in res:
                yield (accts.get(acct), things.get(fulln), addr,
                       fname, date, ip, ips[ip], kind, msg_hash, body,
                       fr_addr, reply_to)
开发者ID:3river,项目名称:reddit,代码行数:47,代码来源:mail_queue.py


示例12: _handle_votes

    def _handle_votes(msgs, chan):
        to_do = []
        uids = set()
        tids = set()
        for x in msgs:
            r = pickle.loads(x.body)
            uid, tid, dir, ip, organic, cheater = r

            print (uid, tid, dir, ip, organic, cheater)

            uids.add(uid)
            tids.add(tid)
            to_do.append((uid, tid, dir, ip, organic, cheater))

        users = Account._byID(uids, data=True, return_dict=True)
        things = Thing._by_fullname(tids, data=True, return_dict=True)

        for uid, tid, dir, ip, organic, cheater in to_do:
            handle_vote(users[uid], things[tid], dir, ip, organic, cheater=cheater)
开发者ID:denrobapps,项目名称:Reddit-VM,代码行数:19,代码来源:queries.py


示例13: quota_baskets

    def quota_baskets(self, kind):
        from r2.models.admintools import filter_quotas
        key = self.quota_key(kind)
        fnames = g.hardcache.get(key)

        if not fnames:
            return None

        unfiltered = Thing._by_fullname(fnames, data=True, return_dict=False)

        baskets, new_quotas = filter_quotas(unfiltered)

        if new_quotas is None:
            pass
        elif new_quotas == []:
            g.hardcache.delete(key)
        else:
            g.hardcache.set(key, new_quotas, 86400 * 30)

        return baskets
开发者ID:NkL4,项目名称:reddit,代码行数:20,代码来源:account.py


示例14: _handle_vote

    def _handle_vote(msg):
        timer = stats.get_timer("service_time." + qname)
        timer.start()

        # assert(len(msgs) == 1)
        r = pickle.loads(msg.body)

        uid, tid, dir, ip, organic, cheater = r
        voter = Account._byID(uid, data=True)
        votee = Thing._by_fullname(tid, data=True)
        timer.intermediate("preamble")

        if isinstance(votee, Comment):
            update_comment_votes([votee])
            timer.intermediate("update_comment_votes")

        # I don't know how, but somebody is sneaking in votes
        # for subreddits
        if isinstance(votee, (Link, Comment)):
            print (voter, votee, dir, ip, organic, cheater)
            handle_vote(voter, votee, dir, ip, organic, cheater=cheater, foreground=True, timer=timer)
开发者ID:huasanyelao,项目名称:reddit,代码行数:21,代码来源:queries.py


示例15: update_flairs

def update_flairs(msg):
    """Add non presser flair to posters/commenters in thebutton SR"""
    fullname = msg.body

    thing = Thing._by_fullname(fullname)
    if (not isinstance(thing, (Comment, Link)) or
            thing.sr_id != g.live_config["thebutton_srid"]):
        return

    author = thing.author_slow
    sr = thing.subreddit_slow

    if not author.flair_css_class(sr._id):
        if author._date < ACCOUNT_CREATION_CUTOFF:
            flair_class = g.live_config["thebutton_nopress_flair_class"]
            flair_text = g.live_config["thebutton_nopress_flair_text"]
        else:
            flair_class = g.live_config["thebutton_cantpress_flair_class"]
            flair_text = g.live_config["thebutton_cantpress_flair_text"]

        if flair_class:
            author.set_flair(sr, css_class=flair_class, text=flair_text)
开发者ID:imclab,项目名称:reddit-plugin-thebutton,代码行数:22,代码来源:flair.py


示例16: _commit

    def _commit(self, *a, **kw):

        Thing._commit(self, *a, **kw)
开发者ID:JoshuaDavid,项目名称:lesswrong-1,代码行数:3,代码来源:award.py


示例17: __init__

 def __init__(self, *a, **kw):
     Thing.__init__(self, *a, **kw)
开发者ID:Craigus,项目名称:lesswrong,代码行数:2,代码来源:link.py


示例18: __init__

 def __init__(self, config):
     Thing.__init__(self)
     Printable.__init__(self)
     self.config = config
     self.wikipage = WikiPageCached(config)
开发者ID:JoshuaDavid,项目名称:lesswrong-1,代码行数:5,代码来源:wikipagecached.py


示例19: add_props

    def add_props(cls, user, wrapped):

        from r2.lib.menus import NavButton
        from r2.lib.db.thing import Thing
        from r2.lib.pages import WrappedUser
        from r2.lib.filters import _force_unicode

        TITLE_MAX_WIDTH = 50

        request_path = request.path

        target_fullnames = [item.target_fullname for item in wrapped if hasattr(item, 'target_fullname')]
        targets = Thing._by_fullname(target_fullnames, data=True)
        authors = Account._byID([t.author_id for t in targets.values() if hasattr(t, 'author_id')], data=True)
        links = Link._byID([t.link_id for t in targets.values() if hasattr(t, 'link_id')], data=True)
        subreddits = Subreddit._byID([t.sr_id for t in targets.values() if hasattr(t, 'sr_id')])

        # Assemble target links
        target_links = {}
        target_accounts = {}
        for fullname, target in targets.iteritems():
            if isinstance(target, Link):
                author = authors[target.author_id]
                title = _force_unicode(target.title)
                if len(title) > TITLE_MAX_WIDTH:
                    short_title = title[:TITLE_MAX_WIDTH] + '...'
                else:
                    short_title = title
                text = '"%(title)s" %(by)s %(author)s' % {'title': short_title, 
                                                          'by': _('by'),
                                                          'author': author.name}
                path = target.make_permalink(subreddits[target.sr_id])
                target_links[fullname] = (text, path, title)
            elif isinstance(target, Comment):
                author = authors[target.author_id]
                link = links[target.link_id]
                title = _force_unicode(link.title)
                if len(title) > TITLE_MAX_WIDTH:
                    short_title = title[:TITLE_MAX_WIDTH] + '...'
                else:
                    short_title = title
                text = '%(by)s %(author)s %(on)s "%(title)s"' % {'by': _('by'),
                                                         'author': author.name,
                                                         'on': _('on'),
                                                         'title': short_title}
                path = target.make_permalink(link, subreddits[target.sr_id])
                target_links[fullname] = (text, path, title)
            elif isinstance(target, Account):
                target_accounts[fullname] = WrappedUser(target)

        for item in wrapped:
            # Can I move these buttons somewhere else? Not great to have request stuff in here
            css_class = 'modactions %s' % item.action
            item.button = NavButton('', item.action, opt='type', css_class=css_class)
            item.button.build(base_path=request_path)

            mod_name = item.author.name
            item.mod = NavButton(mod_name, mod_name, opt='mod')
            item.mod.build(base_path=request_path)
            item.text = ModAction._text.get(item.action, '')
            item.details = item.get_extra_text()

            if hasattr(item, 'target_fullname') and item.target_fullname:
                target = targets[item.target_fullname]
                if isinstance(target, Account):
                    item.target_wrapped_user = target_accounts[item.target_fullname]
                elif isinstance(target, Link) or isinstance(target, Comment):
                    item.target_text, item.target_path, item.target_title = target_links[item.target_fullname]

        Printable.add_props(user, wrapped)
开发者ID:Tailszefox,项目名称:reddit,代码行数:70,代码来源:modaction.py


示例20: add_props

    def add_props(cls, user, wrapped):

        from r2.lib.menus import NavButton
        from r2.lib.db.thing import Thing
        from r2.lib.pages import WrappedUser
        from r2.lib.filters import _force_unicode

        TITLE_MAX_WIDTH = 50

        request_path = request.path

        target_fullnames = [item.target_fullname for item in wrapped if hasattr(item, "target_fullname")]
        targets = Thing._by_fullname(target_fullnames, data=True)
        authors = Account._byID([t.author_id for t in targets.values() if hasattr(t, "author_id")], data=True)
        links = Link._byID([t.link_id for t in targets.values() if hasattr(t, "link_id")], data=True)
        subreddits = Subreddit._byID([item.sr_id for item in wrapped], data=True)

        # Assemble target links
        target_links = {}
        target_accounts = {}
        for fullname, target in targets.iteritems():
            if isinstance(target, Link):
                author = authors[target.author_id]
                title = _force_unicode(target.title)
                if len(title) > TITLE_MAX_WIDTH:
                    short_title = title[:TITLE_MAX_WIDTH] + "..."
                else:
                    short_title = title
                text = '%(link)s "%(title)s" %(by)s %(author)s' % {
                    "link": _("link"),
                    "title": short_title,
                    "by": _("by"),
                    "author": author.name,
                }
                path = target.make_permalink(subreddits[target.sr_id])
                target_links[fullname] = (text, path, title)
            elif isinstance(target, Comment):
                author = authors[target.author_id]
                link = links[target.link_id]
                title = _force_unicode(link.title)
                if len(title) > TITLE_MAX_WIDTH:
                    short_title = title[:TITLE_MAX_WIDTH] + "..."
                else:
                    short_title = title
                text = '%(comment)s %(by)s %(author)s %(on)s "%(title)s"' % {
                    "comment": _("comment"),
                    "by": _("by"),
                    "author": author.name,
                    "on": _("on"),
                    "title": short_title,
                }
                path = target.make_permalink(link, subreddits[link.sr_id])
                target_links[fullname] = (text, path, title)
            elif isinstance(target, Account):
                target_accounts[fullname] = WrappedUser(target)

        for item in wrapped:
            # Can I move these buttons somewhere else? Not great to have request stuff in here
            css_class = "modactions %s" % item.action
            item.button = NavButton("", item.action, opt="type", css_class=css_class)
            item.button.build(base_path=request_path)

            mod_name = item.author.name
            item.mod = NavButton(mod_name, mod_name, opt="mod")
            item.mod.build(base_path=request_path)
            item.text = ModAction._text.get(item.action, "")
            item.details = item.get_extra_text()

            if hasattr(item, "target_fullname") and item.target_fullname:
                target = targets[item.target_fullname]
                if isinstance(target, Account):
                    item.target_wrapped_user = target_accounts[item.target_fullname]
                elif isinstance(target, Link) or isinstance(target, Comment):
                    item.target_text, item.target_path, item.target_title = target_links[item.target_fullname]

            item.bgcolor = ModAction.get_rgb(item.sr_id)
            item.sr_name = subreddits[item.sr_id].name
            item.sr_path = subreddits[item.sr_id].path

        Printable.add_props(user, wrapped)
开发者ID:haiger,项目名称:reddit,代码行数:80,代码来源:modaction.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python emailer.accept_promo函数代码示例发布时间:2022-05-26
下一篇:
Python tdb_sql.make_metadata函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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