本文整理匯總了Python中django.contrib.auth.mixins.UserPassesTestMixin方法的典型用法代碼示例。如果您正苦於以下問題:Python mixins.UserPassesTestMixin方法的具體用法?Python mixins.UserPassesTestMixin怎麽用?Python mixins.UserPassesTestMixin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.contrib.auth.mixins
的用法示例。
在下文中一共展示了mixins.UserPassesTestMixin方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_func
# 需要導入模塊: from django.contrib.auth import mixins [as 別名]
# 或者: from django.contrib.auth.mixins import UserPassesTestMixin [as 別名]
def test_func(self):
""" UserPassesTestMixin Tests"""
if self.request.user.is_superuser:
return True
if self.request.user.has_perm('project.can_view_all_projects'):
return True
project_obj = self.get_object()
if project_obj.projectuser_set.filter(user=self.request.user, status__name='Active').exists():
return True
messages.error(
self.request, 'You do not have permission to view the previous page.')
return False
示例2: test_func
# 需要導入模塊: from django.contrib.auth import mixins [as 別名]
# 或者: from django.contrib.auth.mixins import UserPassesTestMixin [as 別名]
def test_func(self):
""" UserPassesTestMixin Tests"""
if self.request.user.is_superuser:
return True
if self.request.user.has_perm('allocation.can_view_all_allocations'):
return True
pk = self.kwargs.get('pk')
allocation_obj = get_object_or_404(Allocation, pk=pk)
user_can_access_project = allocation_obj.project.projectuser_set.filter(
user=self.request.user, status__name__in=['Active', 'New', ]).exists()
user_can_access_allocation = allocation_obj.allocationuser_set.filter(
user=self.request.user, status__name__in=['Active', ]).exists()
if user_can_access_project and user_can_access_allocation:
return True
return False
示例3: test_func
# 需要導入模塊: from django.contrib.auth import mixins [as 別名]
# 或者: from django.contrib.auth.mixins import UserPassesTestMixin [as 別名]
def test_func(self):
""" UserPassesTestMixin Tests"""
if self.request.user.is_superuser:
return True
project_obj = get_object_or_404(
Project, pk=self.kwargs.get('project_pk'))
if project_obj.pi == self.request.user:
return True
if project_obj.projectuser_set.filter(user=self.request.user, role__name='Manager', status__name='Active').exists():
return True
示例4: test_func
# 需要導入模塊: from django.contrib.auth import mixins [as 別名]
# 或者: from django.contrib.auth.mixins import UserPassesTestMixin [as 別名]
def test_func(self):
""" UserPassesTestMixin Tests"""
if self.request.user.is_superuser:
return True
project_obj = get_object_or_404(Project, pk=self.kwargs.get('project_pk'))
if project_obj.pi == self.request.user:
return True
if project_obj.projectuser_set.filter(user=self.request.user, role__name='Manager', status__name='Active').exists():
return True
messages.error(self.request, 'You do not have permission to add a new grant to this project.')