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


Python Account._byID方法代码示例

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


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

示例1: _new

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def _new(cls, author, link, parent, body, ip):
        from r2.lib.db.queries import changed

        c = Comment(_ups=1, body=body, link_id=link._id, sr_id=link.sr_id, author_id=author._id, ip=ip)

        c._spam = author._spam

        # these props aren't relations
        if parent:
            c.parent_id = parent._id

        link._incr("num_comments", 1)

        to = None
        name = "inbox"
        if parent:
            to = Account._byID(parent.author_id, True)
        elif link.is_self and not link.noselfreply:
            to = Account._byID(link.author_id, True)
            name = "selfreply"

        c._commit()

        changed(link, True)  # only the number of comments has changed

        inbox_rel = None
        # only global admins can be message spammed.
        if to and (not c._spam or to.name in g.admins):
            inbox_rel = Inbox._add(to, c, name)

        return (c, inbox_rel)
开发者ID:ketralnis,项目名称:reddit,代码行数:33,代码来源:link.py

示例2: _new

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def _new(cls, author, link, parent, body, ip):
        c = Comment(body = body,
                    link_id = link._id,
                    sr_id = link.sr_id,
                    author_id = author._id,
                    ip = ip)

        c._spam = author._spam

        #these props aren't relations
        if parent:
            c.parent_id = parent._id

        c._commit()

        link._incr('num_comments', 1)

        to = None
        if parent:
            to = Account._byID(parent.author_id)
        elif link.is_self:
            to = Account._byID(link.author_id)

        inbox_rel = None
        # only global admins can be message spammed.
        if to and (not c._spam or to.name in g.admins):
            inbox_rel = Inbox._add(to, c, 'inbox')

        return (c, inbox_rel)
开发者ID:DFectuoso,项目名称:culter,代码行数:31,代码来源:link.py

示例3: _new

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def _new(cls, author, link, parent, body, ip,criticism=False):
        from r2.lib.db.queries import changed

        #We're turing it off for now...
        criticism = False
        c = Comment(_ups = 1,
                    body = body,
                    link_id = link._id,
                    sr_id = link.sr_id,
                    author_id = author._id,
                    ip = ip)

        c._spam = author._spam
	c.criticism=criticism

        #these props aren't relations
        if parent:
            c.parent_id = parent._id

	#should increment based on crit flag
	#Each should contain the root author and its id, problem is the id isn't created yet if we're the root so have to be clever
	if criticism:
		link._incr("num_criticisms",1)
		if parent:
			c.rootauthor=parent.rootauthor
			if parent.rootid:
				c.rootid=parent.rootid
			else:
				c.rootid=parent._id
		else:
			c.rootauthor=author._id
			c.rootid=False
	else:
        	link._incr('num_comments', 1)

        to = None
        name = 'inbox'
        if parent:
            to = Account._byID(parent.author_id, True)
        elif link.is_self and not link.noselfreply:
            to = Account._byID(link.author_id, True)
            name = 'selfreply'

        c._commit()

        changed(link, True)  # link's number of comments changed

        inbox_rel = None
        # only global admins can be message spammed.
        # Don't send the message if the recipient has blocked
        # the author
        if to and ((not c._spam and author._id not in to.enemies)
            or to.name in g.admins):
            # When replying to your own comment, record the inbox
            # relation, but don't give yourself an orangered
            orangered = (to.name != author.name)
            inbox_rel = Inbox._add(to, c, name, orangered=orangered)

        return (c, inbox_rel)
开发者ID:constantAmateur,项目名称:sciteit,代码行数:61,代码来源:link.py

示例4: get_important_friends

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def get_important_friends(cls, user_id, max_lookup=500, limit=100):
        a = Account._byID(user_id, data=True)
        # friends are returned chronologically by date, so pick the end of the list
        # for the most recent additions
        friends = Account._byID(a.friends[-max_lookup:], return_dict=False, data=True)

        # if we don't have a last visit for your friends, we don't care about them
        friends = [x for x in friends if hasattr(x, "last_visit")]

        # sort friends by most recent interactions
        friends.sort(key=lambda x: getattr(x, "last_visit"), reverse=True)
        return [x._id for x in friends[:limit]]
开发者ID:eerock,项目名称:reddit,代码行数:14,代码来源:subreddit.py

示例5: _new

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def _new(cls, author, link, parent, body, ip, spam = False):
        c = Comment(body = body,
                    link_id = link._id,
                    sr_id = link.sr_id,
                    author_id = author._id,
                    ip = ip)

        c._spam = spam

        #these props aren't relations
        if parent:
            c.parent_id = parent._id

        c._commit()

        link._incr('num_comments', 1)

        inbox_rel = None
        if parent:
            to = Account._byID(parent.author_id)
            # only global admins can be message spammed.
            if not c._spam or to.name in g.admins:
                inbox_rel = Inbox._add(to, c, 'inbox')

        #clear that chache
        clear_memo('builder.link_comments2', link._id)

        return (c, inbox_rel)
开发者ID:EmileKroeger,项目名称:lesswrong,代码行数:30,代码来源:link.py

示例6: _new

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def _new(cls, author, link, parent, body, ip, spam = False):
        c = Comment(body = body,
                    link_id = link._id,
                    sr_id = link.sr_id,
                    author_id = author._id,
                    ip = ip)

        c._spam = spam

        #these props aren't relations
        if parent:
            c.parent_id = parent._id

        c._commit()

        link._incr('num_comments', 1)

        if parent:
            to = Account._byID(parent.author_id)
            i = Inbox._add(to, c, 'inbox')

        #clear that chache
        clear_memo('builder.link_comments2', link._id)
        from admintools import admintools
        utils.worker.do(lambda: admintools.add_thing(c))

        return c
开发者ID:cmak,项目名称:reddit,代码行数:29,代码来源:link.py

示例7: get_links

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def get_links(self, sort, time):
        from r2.lib.db import queries
        from r2.models import Link
        from r2.controllers.errors import UserRequiredException

        if not c.user_is_loggedin:
            raise UserRequiredException

        friends = self.get_important_friends(c.user._id)

        if not friends:
            return []

        if g.use_query_cache:
            # with the precomputer enabled, this Subreddit only supports
            # being sorted by 'new'. it would be nice to have a
            # cleaner UI than just blatantly ignoring their sort,
            # though
            sort = 'new'
            time = 'all'

            friends = Account._byID(friends, return_dict=False)

            crs = [queries.get_submitted(friend, sort, time)
                   for friend in friends]
            return queries.MergedCachedResults(crs)

        else:
            q = Link._query(Link.c.author_id == friends,
                            sort = queries.db_sort(sort),
                            data = True)
            if time != 'all':
                q._filter(queries.db_times[time])
            return q
开发者ID:barneyfoxuk,项目名称:reddit,代码行数:36,代码来源:subreddit.py

示例8: accept

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def accept(cls, r, correct = True):
        ''' sets the various reporting fields, but does nothing to
        the corresponding spam fields (handled by unreport)'''
        amount = 1 if correct else -1
        oldamount = int(r._name)

        # do nothing if nothing has changed
        if amount == oldamount: return

        up_change, down_change = score_changes(amount, oldamount)
        
        # update the user who made the report
        r._thing1._incr('report_correct', up_change)
        r._thing1._incr('report_ignored', down_change)

        # update the amount
        cls.set_amount(r, amount)

        # update the thing's number of reports only if we made no
        # decision prior to this
        if oldamount == 0:
            # update the author and thing field
            if getattr(r._thing2, Report._field) > 0:
                r._thing2._incr(Report._field, -1)
            aid = r._thing2.author_id
            author = Account._byID(aid)
            if getattr(author, Report._field) > 0:
                author._incr(Report._field, -1)

            admintools.report(r._thing2, -1)
开发者ID:cmak,项目名称:reddit,代码行数:32,代码来源:report.py

示例9: add_props

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def add_props(cls, user, wrapped):
        Link.add_props(user, wrapped)

        try:
            if c.user_is_sponsor:
                promoted_by_ids = set(x.promoted_by
                                      for x in wrapped
                                      if hasattr(x,'promoted_by'))
                promoted_by_accounts = Account._byID(promoted_by_ids,
                                                     data=True)
            else:
                promoted_by_accounts = {}

        except NotFound:
            # since this is just cosmetic, we can skip it altogether
            # if one isn't found or is broken
            promoted_by_accounts = {}

        for item in wrapped:
            # these are potentially paid for placement
            item.nofollow = True
            if item.promoted_by in promoted_by_accounts:
                item.promoted_by_name = promoted_by_accounts[item.promoted_by].name
            else:
                # keep the template from trying to read it
                item.promoted_by = None
开发者ID:Craigus,项目名称:lesswrong,代码行数:28,代码来源:link.py

示例10: add_props

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def add_props(cls, user, wrapped):
        #fetch parent links
        links = Link._byID(set(l.link_id for l in wrapped), True)
        

        #get srs for comments that don't have them (old comments)
        for cm in wrapped:
            if not hasattr(cm, 'sr_id'):
                cm.sr_id = links[cm.link_id].sr_id
        
        subreddits = Subreddit._byID(set(cm.sr_id for cm in wrapped),
                                     data=True,return_dict=False)
        can_reply_srs = set(s._id for s in subreddits if s.can_comment(user))

        min_score = c.user.pref_min_comment_score

        cids = dict((w._id, w) for w in wrapped)

        for item in wrapped:
            item.link = links.get(item.link_id)
            if not hasattr(item, 'subreddit'):
                item.subreddit = item.subreddit_slow
            if hasattr(item, 'parent_id'):
                parent = Comment._byID(item.parent_id, data=True)
                parent_author = Account._byID(parent.author_id, data=True)
                item.parent_author = parent_author

                if not c.full_comment_listing and cids.has_key(item.parent_id):
                    item.parent_permalink = '#' + utils.to36(item.parent_id)
                else:
                    item.parent_permalink = parent.make_anchored_permalink(item.link, item.subreddit)
            else:
                item.parent_permalink = None
                item.parent_author = None

            item.can_reply = (item.sr_id in can_reply_srs)

            # Don't allow users to vote on their own comments
            item.votable = bool(c.user != item.author)

            # not deleted on profile pages,
            # deleted if spam and not author or admin
            item.deleted = (not c.profilepage and
                           (item._deleted or
                            (item._spam and
                             item.author != c.user and
                             not item.show_spam)))

            # don't collapse for admins, on profile pages, or if deleted
            item.collapsed = ((item.score < min_score) and
                             not (c.profilepage or
                                  item.deleted or
                                  c.user_is_admin))
                
            if not hasattr(item,'editted'):
                item.editted = False
            #will get updated in builder
            item.num_children = 0
            item.score_fmt = Score.points
            item.permalink = item.make_permalink(item.link, item.subreddit)
开发者ID:Kakun1,项目名称:lesswrong,代码行数:62,代码来源:link.py

示例11: get_all_comments

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def get_all_comments(self):
        from r2.lib.db import queries
        from r2.models import Comment
        from r2.controllers.errors import UserRequiredException

        if not c.user_is_loggedin:
            raise UserRequiredException

        friends = self.get_important_friends(c.user._id)

        if not friends:
            return []

        if g.use_query_cache:
            # with the precomputer enabled, this Subreddit only supports
            # being sorted by 'new'. it would be nice to have a
            # cleaner UI than just blatantly ignoring their sort,
            # though
            sort = "new"
            time = "all"

            friends = Account._byID(friends, return_dict=False)

            crs = [queries.get_comments(friend, sort, time) for friend in friends]
            return queries.MergedCachedResults(crs)

        else:
            q = Comment._query(Comment.c.author_id == friends, sort=desc("_date"), data=True)
            return q
开发者ID:nborwankar,项目名称:reddit,代码行数:31,代码来源:subreddit.py

示例12: _send_post_notifications

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def _send_post_notifications(self, link, comment, parent):
        if parent:
            to = Account._byID(parent.author_id)
        else:
            if not link.notify_on_comment:
                return None
            elif comment.author_id != link.author_id:
                # Send notification if the comment wasn't by the link author
                to = Account._byID(link.author_id)
            else:
                return None

        # only global admins can be message spammed.
        if self._spam and to.name not in g.admins:
            return None

        return Inbox._add(to, self, 'inbox')
开发者ID:MichaelBlume,项目名称:lesswrong,代码行数:19,代码来源:link.py

示例13: _new

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def _new(cls, author, link, parent, body, ip):
        from r2.lib.db.queries import changed

        c = Comment(_ups=1,
                    body=body,
                    link_id=link._id,
                    sr_id=link.sr_id,
                    author_id=author._id,
                    ip=ip)

        c._spam = author._spam

        if author._spam:
            g.stats.simple_event('spam.autoremove.comment')

        #these props aren't relations
        if parent:
            c.parent_id = parent._id

        link._incr('num_comments', 1)

        to = None
        name = 'inbox'
        if parent:
            to = Account._byID(parent.author_id, True)
        elif link.is_self and not link.noselfreply:
            to = Account._byID(link.author_id, True)
            name = 'selfreply'

        c._commit()

        changed(link, True)  # link's number of comments changed

        inbox_rel = None
        # only global admins can be message spammed.
        # Don't send the message if the recipient has blocked
        # the author
        if to and ((not c._spam and author._id not in to.enemies)
            or to.name in g.admins):
            # When replying to your own comment, record the inbox
            # relation, but don't give yourself an orangered
            orangered = (to.name != author.name)
            inbox_rel = Inbox._add(to, c, name, orangered=orangered)

        return (c, inbox_rel)
开发者ID:jcald,项目名称:reddit,代码行数:47,代码来源:link.py

示例14: get_reported_authors

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def get_reported_authors(cls, time = None, sort = None):
        reports = {}
        for t_cls in (Link, Comment, Message):
            q = t_cls._query(t_cls.c._spam == False,
                             t_cls.c.reported > 0,
                             data = True)
            q._sort = desc("_date")
            if time:
                q._filter(time)
            reports.update(Report.reported(things = list(q), amount = 0))

        # at this point, we have a full list of reports made on the interval specified
        # build up an author to report list
        authors = Account._byID([k[1].author_id 
                                 for k, v in reports.iteritems()],
                                data = True) if reports else []

        # and build up a report on each author
        author_rep = {}
        for (tattler, thing, amount), r in reports.iteritems():
            aid = thing.author_id
            if not author_rep.get(aid):
                author_rep[aid] = Storage(author = authors[aid])
                author_rep[aid].num_reports = 1
                author_rep[aid].acct_correct = tattler.report_correct
                author_rep[aid].acct_wrong = tattler.report_ignored
                author_rep[aid].most_recent = r._date
                author_rep[aid].reporters = set([tattler])
            else:
                author_rep[aid].num_reports += 1
                author_rep[aid].acct_correct += tattler.report_correct
                author_rep[aid].acct_wrong += tattler.report_ignored
                if author_rep[aid].most_recent < r._date:
                    author_rep[aid].most_recent = r._date
                author_rep[aid].reporters.add(tattler)
                
        authors = author_rep.values()
        if sort == "hot":
            def report_hotness(a):
                return a.acct_correct / max(a.acct_wrong + a.acct_correct,1)
            def better_reporter(a, b):
                q = report_hotness(b) - report_hotness(a)
                if q == 0:
                    return b.acct_correct - a.acct_correct
                else:
                    return 1 if q > 0 else -1
            authors.sort(better_reporter)
        if sort == "top":
            authors.sort(lambda x, y: y.num_reports - x.num_reports)
        elif sort == "new":
            def newer_reporter(a, b):
                t = b.most_recent - a.most_recent
                t0 = datetime.timedelta(0)
                return 1 if t > t0 else -1 if t < t0 else 0
            authors.sort(newer_reporter)
        return authors
开发者ID:cmak,项目名称:reddit,代码行数:58,代码来源:report.py

示例15: vote

# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import _byID [as 别名]
    def vote(cls, sub, obj, dir, ip, spam=False, organic=False):
        from admintools import valid_user, valid_thing, update_score
        from r2.lib.count import incr_counts

        sr = obj.subreddit_slow
        kind = obj.__class__.__name__.lower()
        karma = sub.karma(kind, sr)

        is_self_link = kind == "link" and hasattr(obj, "is_self") and obj.is_self

        # check for old vote
        rel = cls.rel(sub, obj)
        oldvote = list(rel._query(rel.c._thing1_id == sub._id, rel.c._thing2_id == obj._id, data=True))

        amount = 1 if dir is True else 0 if dir is None else -1

        is_new = False
        # old vote
        if len(oldvote):
            v = oldvote[0]
            oldamount = int(v._name)
            v._name = str(amount)

            # these still need to be recalculated
            old_valid_thing = v.valid_thing
            v.valid_thing = valid_thing(v, karma) and v.valid_thing and not spam
            v.valid_user = v.valid_user and v.valid_thing and valid_user(v, sr, karma)
        # new vote
        else:
            is_new = True
            oldamount = 0
            v = rel(sub, obj, str(amount))
            v.author_id = obj.author_id
            v.ip = ip
            old_valid_thing = v.valid_thing = valid_thing(v, karma) and not spam
            v.valid_user = v.valid_thing and valid_user(v, sr, karma) and not is_self_link
            if organic:
                v.organic = organic

        v._commit()

        up_change, down_change = score_changes(amount, oldamount)

        update_score(obj, up_change, down_change, v.valid_thing, old_valid_thing)

        if v.valid_user:
            author = Account._byID(obj.author_id, data=True)
            author.incr_karma(kind, sr, up_change - down_change)

        # update the sr's valid vote count
        if is_new and v.valid_thing and kind == "link":
            if sub._id != obj.author_id:
                incr_counts([sr])

        return v
开发者ID:vin,项目名称:reddit,代码行数:57,代码来源:vote.py


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