當前位置: 首頁>>代碼示例>>Python>>正文


Python mixins.UserPassesTestMixin方法代碼示例

本文整理匯總了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 
開發者ID:ubccr,項目名稱:coldfront,代碼行數:18,代碼來源:views.py

示例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 
開發者ID:ubccr,項目名稱:coldfront,代碼行數:23,代碼來源:views.py

示例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 
開發者ID:ubccr,項目名稱:coldfront,代碼行數:15,代碼來源:views.py

示例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.') 
開發者ID:ubccr,項目名稱:coldfront,代碼行數:16,代碼來源:views.py


注:本文中的django.contrib.auth.mixins.UserPassesTestMixin方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。