def can_edit(self, user: BitpollUser, request: HttpRequest=None) -> bool:
"""
check if the user can edit this Poll
:param user: The user to edit the Poll
:param request: The request object,
if this is set a error message will be emitted via the django.messages framework
:return:
"""
has_owner = self.group or self.user
is_owner = self.is_owner(user)
can_edit = ((not has_owner) or is_owner) and user.is_authenticated or not has_owner
if request and not can_edit:
messages.error(
request, _("You are not allowed to edit this Poll.")
)
return can_edit
评论列表
文章目录