本文整理匯總了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
示例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
示例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
示例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
}
示例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
示例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
示例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)
示例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
示例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("")
示例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
示例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