access.py 文件源码

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

项目:c3nav 作者: c3nav 项目源码 文件源码
def redeem(self, user=None):
        if (user is None and self.redeemed) or self.accesspermissions.exists():
            raise self.RedeemError('Already redeemed.')

        if timezone.now() > self.valid_until + timedelta(minutes=5 if self.redeemed else 0):
            raise self.RedeemError('No longer valid.')

        if user:
            with transaction.atomic():
                if self.author_id and self.unique_key:
                    AccessPermission.objects.filter(author_id=self.author_id, unique_key=self.unique_key).delete()
                for restriction in self.restrictions:
                    AccessPermission.objects.create(
                        user=user,
                        access_restriction_id=restriction.pk,
                        author_id=self.author_id,
                        expire_date=restriction.expire_date,
                        can_grant=self.can_grant,
                        unique_key=self.unique_key,
                        token=self if self.pk else None,
                    )

        if self.pk and not self.unlimited:
            self.redeemed = True
            self.save()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号