def POST_del(self, res, thing): '''for deleting all sorts of things''' thing._deleted = True thing._commit() # flag search indexer that something has changed tc.changed(thing) #expire the item from the sr cache if isinstance(thing, Link): sr = thing.subreddit_slow expire_hot(sr)
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')
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')
def vote(cls, sub, obj, dir, ip, spam = False, organic = False): from admintools import valid_user, valid_thing, update_score sr = obj.subreddit_slow kind = obj.__class__.__name__.lower() karma = sub.karma(kind, sr) #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 = (v.valid_thing and (not spam) and valid_thing(v, karma)) 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 = ((not spam) and valid_thing(v, karma)) v.valid_user = v.valid_thing and valid_user(v, sr, karma) 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: # sr._incr('valid_votes', 1) #expire the sr if kind == 'link' and v.valid_thing: expire_hot(sr)