models.py 文件源码

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

项目:Bitpoll 作者: fsinfuhh 项目源码 文件源码
def can_vote(self, user: BitpollUser, request: HttpRequest, is_edit: bool=False) -> bool:
        """
        Determine if the user is allowed to vote

        :param is_edit: if the vote is an edit
        :param user:
        :param request:
        :return:
        """
        has_voted = self.has_voted(user)
        if self.one_vote_per_user and has_voted and not is_edit:
            messages.error(request, _("It is only one vote allowed. You have already voted."))
            return False
        elif self.require_login and not user.is_authenticated:
            messages.error(request, _("Login required to vote."))
            return False
        elif self.require_invitation and (not user.is_authenticated or user not in self.invitation_set.all().values('user')):
            messages.error(request, _("You are not allowed to vote in this poll. You have to be invited"))
            return False
        return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号