本文整理汇总了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')
示例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)
示例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")
示例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')