本文整理汇总了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