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


Python Vote.vote方法代码示例

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


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

示例1: handle_vote

# 需要导入模块: from r2.models import Vote [as 别名]
# 或者: from r2.models.Vote import vote [as 别名]
def handle_vote(user, thing, dir, ip, organic, cheater=False, foreground=False):
    from r2.lib.db import tdb_sql
    from sqlalchemy.exc import IntegrityError
    try:
        v = Vote.vote(user, thing, dir, ip, organic, cheater = cheater)
    except (tdb_sql.CreationError, IntegrityError):
        g.log.error("duplicate vote for: %s" % str((user, thing, dir)))
        return

    if isinstance(thing, Link):
        new_vote(v, foreground=foreground)

        #update the modified flags
        if user._id == thing.author_id:
            set_last_modified(user, 'overview')
            set_last_modified(user, 'submitted')
            #update sup listings
            sup.add_update(user, 'submitted')

            #update sup listings
            if dir:
                set_last_modified(user, 'liked')
                sup.add_update(user, 'liked')
            elif dir is False:
                set_last_modified(user, 'disliked')
                sup.add_update(user, 'disliked')

    elif isinstance(thing, Comment):
        #update last modified
        if user._id == thing.author_id:
            set_last_modified(user, 'overview')
            set_last_modified(user, 'commented')
            #update sup listings
            sup.add_update(user, 'commented')
开发者ID:rram,项目名称:reddit,代码行数:36,代码来源:queries.py

示例2: fix_about_post

# 需要导入模块: from r2.models import Vote [as 别名]
# 或者: from r2.models.Vote import vote [as 别名]
def fix_about_post():
    user = Account._by_name('Eliezer_Yudkowsky')
    l = Link._byID(1, data=True)
    # l = Link._byID(int('1i', 36))
    if l.url.lower() == 'self':
        l.url = l.make_permalink_slow()
        l.is_self = True
        l._commit()
        l.set_url_cache()
    v = Vote.vote(user, l, True, l.ip, False)
开发者ID:AndrewHay,项目名称:lesswrong,代码行数:12,代码来源:post_tools.py

示例3: handle_vote

# 需要导入模块: from r2.models import Vote [as 别名]
# 或者: from r2.models.Vote import vote [as 别名]
def handle_vote(user, thing, dir, ip, organic,
                cheater=False, foreground=False, timer=None):
    if timer is None:
        timer = SimpleSillyStub()

    from r2.lib.db import tdb_sql
    from sqlalchemy.exc import IntegrityError
    try:
        v = Vote.vote(user, thing, dir, ip, organic, cheater = cheater,
                      timer=timer)
    except (tdb_sql.CreationError, IntegrityError):
        g.log.error("duplicate vote for: %s" % str((user, thing, dir)))
        return

    timestamps = []
    if isinstance(thing, Link):
        new_vote(v, foreground=foreground, timer=timer)

        #update the modified flags
        if user._id == thing.author_id:
            timestamps.append('Overview')
            timestamps.append('Submitted')
            #update sup listings
            sup.add_update(user, 'submitted')

            #update sup listings
            if dir:
                sup.add_update(user, 'liked')
            elif dir is False:
                sup.add_update(user, 'disliked')

    elif isinstance(thing, Comment):
        #update last modified
        if user._id == thing.author_id:
            timestamps.append('Overview')
            timestamps.append('Commented')
            #update sup listings
            sup.add_update(user, 'commented')

    timer.intermediate("sup")

    for timestamp in timestamps:
        set_last_modified(user, timestamp.lower())
    LastModified.touch(user._fullname, timestamps)
    timer.intermediate("last_modified")
开发者ID:Anenome,项目名称:reddit,代码行数:47,代码来源:queries.py

示例4: handle_vote

# 需要导入模块: from r2.models import Vote [as 别名]
# 或者: from r2.models.Vote import vote [as 别名]
def handle_vote(user, thing, dir, ip, organic, cheater = False):
    from r2.lib.db import tdb_sql
    from sqlalchemy.exc import IntegrityError
    try:
        v = Vote.vote(user, thing, dir, ip, organic, cheater = cheater)
    except (tdb_sql.CreationError, IntegrityError):
        g.log.error("duplicate vote for: %s" % str((user, thing, dir)))
        return

    # keep track of upvotes in the hard cache by subreddit
    sr_id = getattr(thing, "sr_id", None)
    if (sr_id and dir > 0 and getattr(thing, "author_id", None) != user._id
        and v.valid_thing):
        now = datetime.now(g.tz).strftime("%Y/%m/%d")
        g.hardcache.add("subreddit_vote-%s_%s_%s" % (now, sr_id, user._id),
                        sr_id, time = 86400 * 7) # 1 week for now

    if isinstance(thing, Link):
        new_vote(v)
        if v.valid_thing:
            expire_hot(thing.subreddit_slow)

        #update the modified flags
        set_last_modified(user, 'liked')
        if user._id == thing.author_id:
            set_last_modified(user, 'overview')
            set_last_modified(user, 'submitted')
            #update sup listings
            sup.add_update(user, 'submitted')

            #update sup listings
            if dir:
                sup.add_update(user, 'liked')
            elif dir is False:
                sup.add_update(user, 'disliked')

    elif isinstance(thing, Comment):
        #update last modified
        if user._id == thing.author_id:
            set_last_modified(user, 'overview')
            set_last_modified(user, 'commented')
            #update sup listings
            sup.add_update(user, 'commented')
开发者ID:XieConnect,项目名称:reddit,代码行数:45,代码来源:queries.py


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