bio_models.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:USTC-Software-2017 作者: igemsoftware2017 项目源码 文件源码
def vote(self, user):

        from django.core.cache import cache
        from biohub.core.conf import settings as biohub_settings

        key = 'user_{}_vote'.format(user.id)
        if cache.get(key) is not None:
            raise Throttled()

        cache.set(key, 1, timeout=biohub_settings.THROTTLE['vote'])

        if self.author is not None and self.author.id == user.id:
            return False
        if not self.voted_users.filter(pk=user.id).exists():
            with transaction.atomic():
                self.votes += 1
                self.voted_users.add(user)
                self.save(update_fields=['votes'])
                voted_experience_signal.send(
                    sender=self.__class__, instance=self,
                    user_voted=user, current_votes=self.votes)
            return True
        return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号