def increase_hackathon_stat(self, hackathon, stat_type, increase): """Increase or descrease the count for certain hackathon stat :type hackathon: Hackathon :param hackathon: instance of Hackathon to be counted :type stat_type: str|unicode :param stat_type: type of stat that defined in constants.py#HACKATHON_STAT :type increase: int :param increase: increase of the count. Can be positive or negative """ stat = self.db.find_first_object_by(HackathonStat, hackathon_id=hackathon.id, type=stat_type) if stat: stat.count += increase else: stat = HackathonStat(hackathon_id=hackathon.id, type=stat_type, count=increase) self.db.add_object(stat) if stat.count < 0: stat.count = 0 self.db.commit()
def update_hackathon_stat(self, hackathon, stat_type, count): """Increase or descrease the count for certain hackathon stat :type hackathon: Hackathon :param hackathon: instance of Hackathon to be counted :type stat_type: str|unicode :param stat_type: type of stat that defined in constants.py#HACKATHON_STAT :type count: int :param count: the new count for this stat item """ stat = self.db.find_first_object_by(HackathonStat, hackathon_id=hackathon.id, type=stat_type) if stat: stat.count = count stat.update_time = self.util.get_now() else: stat = HackathonStat(hackathon_id=hackathon.id, type=stat_type, count=count) self.db.add_object(stat) if stat.count < 0: stat.count = 0 self.db.commit()
def update_hackathon_stat(self, hackathon, stat_type, count): """Increase or descrease the count for certain hackathon stat :type hackathon: Hackathon :param hackathon: instance of Hackathon to be counted :type stat_type: str|unicode :param stat_type: type of stat that defined in constants.py#HACKATHON_STAT :type count: int :param count: the new count for this stat item """ stat = self.db.find_first_object_by(HackathonStat, hackathon_id=hackathon.id, type=stat_type) if stat: stat.count = count else: stat = HackathonStat(hackathon_id=hackathon.id, type=stat_type, count=count) if stat.count < 0: stat.count = 0 self.db.commit()