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


Python compat.is_authenticated方法代碼示例

本文整理匯總了Python中rest_framework.compat.is_authenticated方法的典型用法代碼示例。如果您正苦於以下問題:Python compat.is_authenticated方法的具體用法?Python compat.is_authenticated怎麽用?Python compat.is_authenticated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.compat的用法示例。


在下文中一共展示了compat.is_authenticated方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: has_permission

# 需要導入模塊: from rest_framework import compat [as 別名]
# 或者: from rest_framework.compat import is_authenticated [as 別名]
def has_permission(self, request, view):
        """
        List/create objects permission.

        :param request: django request instance.
        :type request: django.http.request.HttpRequest.
        :param view: view set.
        :type view: mk42.apps.core.api.viewsets.rsvp.RSVPViewset.
        :return: permission is granted.
        :rtype: bool.
        """

        if request.method in SAFE_METHODS:
            # Read permissions are allowed to any request, so we'll always allow GET, HEAD or OPTIONS requests.
            return True

        if all([request.method == POST, is_authenticated(request.user), ]):
            # Allow join to event only for authenticated users.
            return True

        if request.method == DELETE:
            # In futures steps of flow allow user delete own RSVP.
            return True 
開發者ID:Peer-Lab,項目名稱:mk42,代碼行數:25,代碼來源:rsvp.py

示例2: has_permission

# 需要導入模塊: from rest_framework import compat [as 別名]
# 或者: from rest_framework.compat import is_authenticated [as 別名]
def has_permission(self, request, view):
        """
        List/create objects permission.

        :param request: django request instance.
        :type request: django.http.request.HttpRequest.
        :param view: view set.
        :type view: mk42.apps.core.api.viewsets.event_log.EventLogViewset.
        :return: permission is granted.
        :rtype: bool.
        """

        if request.method in SAFE_METHODS:
            # Read permissions are allowed to any request, so we'll always allow GET, HEAD or OPTIONS requests.
            return True

        if all([request.method == POST, is_authenticated(request.user), self.check_event_owner(request)]):
            # Allow add new status only for authenticated users.
            return True

        if request.method == PATCH:
            # In futures steps of flow allow user edit self owned events.
            return False 
開發者ID:Peer-Lab,項目名稱:mk42,代碼行數:25,代碼來源:log.py

示例3: has_permission

# 需要導入模塊: from rest_framework import compat [as 別名]
# 或者: from rest_framework.compat import is_authenticated [as 別名]
def has_permission(self, request, view):
        """
        List/create objects permission.

        :param request: django request instance.
        :type request: django.http.request.HttpRequest.
        :param view: view set.
        :type view: mk42.apps.core.api.viewsets.group.GroupViewset.
        :return: permission is granted.
        :rtype: bool.
        """

        if request.method in SAFE_METHODS:
            # Read permissions are allowed to any request, so we'll always allow GET, HEAD or OPTIONS requests.
            return True

        if all([request.method == POST, is_authenticated(request.user), ]):
            # Allow create groups only for authenticated users.
            return True

        if all([request.method == PATCH, is_authenticated(request.user), ]):
            # In futures steps of flow allow user edit self owned groups.
            return True 
開發者ID:Peer-Lab,項目名稱:mk42,代碼行數:25,代碼來源:group.py

示例4: get_cache_key

# 需要導入模塊: from rest_framework import compat [as 別名]
# 或者: from rest_framework.compat import is_authenticated [as 別名]
def get_cache_key(self, request, view):
        """
        If `view.throttle_scope` is not set, don't apply this throttle.

        Otherwise generate the unique cache key by concatenating the user id
        with the '.throttle_scope` property of the view.
        """
        if is_authenticated(request.user):
            ident = request.user.pk
        else:
            ident = self.get_ident(request)

        return self.cache_format % {
            'scope': self.scope,
            'ident': ident
        } 
開發者ID:Lurance,項目名稱:sdining,代碼行數:18,代碼來源:throttling.py

示例5: has_permission

# 需要導入模塊: from rest_framework import compat [as 別名]
# 或者: from rest_framework.compat import is_authenticated [as 別名]
def has_permission(self, request, view):
        """
        List/create objects permission.

        :param request: django request instance.
        :type request: django.http.request.HttpRequest.
        :param view: view set.
        :type view: mk42.apps.core.api.viewsets.event.EventViewset.
        :return: permission is granted.
        :rtype: bool.
        """

        if request.method in SAFE_METHODS:
            # Read permissions are allowed to any request, so we'll always allow GET, HEAD or OPTIONS requests.
            return True
  
        if all([request.method == POST, is_authenticated(request.user), ]):
            # Allow create events only for authenticated users.
            if not self.check_event_dates(request):
                self.message = _("Invalid dates.")

                return False
                
            return True

        if request.method == PATCH:
            # In futures steps of flow allow user edit self owned events.
            return True 
開發者ID:Peer-Lab,項目名稱:mk42,代碼行數:30,代碼來源:event.py

示例6: has_permission

# 需要導入模塊: from rest_framework import compat [as 別名]
# 或者: from rest_framework.compat import is_authenticated [as 別名]
def has_permission(self, request, view):
        """
        List/create objects permission.

        :param request: django request instance.
        :type request: django.http.request.HttpRequest.
        :param view: view set.
        :type view: mk42.apps.core.api.viewsets.membership.MembershipViewset.
        :return: permission is granted.
        :rtype: bool.
        """

        if request.method in SAFE_METHODS:
            # Read permissions are allowed to any request, so we'll always allow GET, HEAD or OPTIONS requests.
            return True

        if all([request.method == POST, is_authenticated(request.user), ]):
            # Allow join to groups only for authenticated users.
            return True

        if all([request.method == DELETE, is_authenticated(request.user), ]):
            # In futures steps of flow allow user delete own membership.
            return True

        if all([request.method == PATCH, is_authenticated(request.user), ]):
            # In futures steps of flow allow owner of group to activate membership
            return True 
開發者ID:Peer-Lab,項目名稱:mk42,代碼行數:29,代碼來源:membership.py

示例7: has_permission

# 需要導入模塊: from rest_framework import compat [as 別名]
# 或者: from rest_framework.compat import is_authenticated [as 別名]
def has_permission(self, request, view):
        return request.user and is_authenticated(request.user) 
開發者ID:Lurance,項目名稱:sdining,代碼行數:4,代碼來源:permissions.py

示例8: get_configuration

# 需要導入模塊: from rest_framework import compat [as 別名]
# 或者: from rest_framework.compat import is_authenticated [as 別名]
def get_configuration(self):
        request = self.context.get("request", None)
        if request and is_authenticated(request.user):
            return NotificationBase.get_mapped_user_notifications_types_and_categories(request.user)
        return None 
開發者ID:ArabellaTech,項目名稱:universal_notifications,代碼行數:7,代碼來源:serializers.py

示例9: get

# 需要導入模塊: from rest_framework import compat [as 別名]
# 或者: from rest_framework.compat import is_authenticated [as 別名]
def get(self, request, *args, **kwargs):
        if request.user and is_authenticated(request.user):
            print request.user.profile
            userPro = request.user.profile
            serializer = self.get_serializer(userPro)
            return Response(serializer.data)
        return Response("") 
開發者ID:youjiajia,項目名稱:pigroom,代碼行數:9,代碼來源:views.py

示例10: has_object_permission

# 需要導入模塊: from rest_framework import compat [as 別名]
# 或者: from rest_framework.compat import is_authenticated [as 別名]
def has_object_permission(self, request, view, obj):
        if request.method in ('CREATE',):
            return True
        if request.user and is_authenticated(request.user):
            return True
        return False 
開發者ID:youjiajia,項目名稱:pigroom,代碼行數:8,代碼來源:__init__.py

示例11: has_permission

# 需要導入模塊: from rest_framework import compat [as 別名]
# 或者: from rest_framework.compat import is_authenticated [as 別名]
def has_permission(self, request, view):
		if view.action == "create" and request.user and is_authenticated(request.user):
			return True
		elif view.action == "list" and request.user and request.user.is_superuser:
			return True
		return False 
開發者ID:pmontu,項目名稱:indian_farming,代碼行數:8,代碼來源:permissions.py


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