本文整理汇总了Python中oc_platform.APIUtilities._api_unauthorized_failure方法的典型用法代码示例。如果您正苦于以下问题:Python APIUtilities._api_unauthorized_failure方法的具体用法?Python APIUtilities._api_unauthorized_failure怎么用?Python APIUtilities._api_unauthorized_failure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oc_platform.APIUtilities
的用法示例。
在下文中一共展示了APIUtilities._api_unauthorized_failure方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reposition_cover_picture
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_unauthorized_failure [as 别名]
def reposition_cover_picture(request, project_id):
try:
project = Project.objects.get(pk=project_id)
except:
raise Http404
if request.user not in project.admins.all():
return APIUtilities._api_unauthorized_failure()
left = request.GET.get('left', None)
top = request.GET.get('top', None)
try:
project.cover_pic_position.top = int(top)
project.cover_pic_position.left = int(left)
project.cover_pic_position.save()
return APIUtilities._api_success()
except:
context = {
'title': 'Cannot reposition project cover picture.',
'message': 'We failed to reposition the project cover picture. Please ' +
'contact us if this problem persists.'
}
return APIUtilities._api_failure(context)
示例2: delete_comment
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_unauthorized_failure [as 别名]
def delete_comment(request, comment_id):
try:
comment = Comment.objects.get(pk=comment_id)
# TODO(Varun): Same logic as duplicated from template generation to show
# delete button
from interactions.CommentUtilities import CommentUtilities
(host_type, host, root) = CommentUtilities.get_comment_root(comment)
if host_type.name == 'project':
if request.user == comment.user or request.user in host.admins.all():
# Delete all descendant elements of this comment.
delete_comment_tree(comment)
return APIUtilities._api_success()
else:
return APIUtilities._api_unauthorized_failure()
elif host_type.name == 'resource':
if request.user == comment.user or (
request.user in host.collaborators.all() or
request.user == host.creator):
delete_comment_tree(comment)
return APIUtilities._api_success()
return APIUtilities._api_failure()
except Comment.DoesNotExist:
return APIUtilities._api_not_found()
示例3: delete_event
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_unauthorized_failure [as 别名]
def delete_event(request, event_id):
try:
event = Event.objects.get(pk=event_id)
except:
return APIUtilities._api_not_found()
if request.user != event.user:
return APIUtilities._api_unauthorized_failure()
event.delete()
return APIUtilities.success()
示例4: delete_curriculum
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_unauthorized_failure [as 别名]
def delete_curriculum(request, curriculum_id):
try:
curriculum = Curriculum.objects.get(pk=curriculum_id)
except:
return APIUtilities._api_not_found()
if request.user != curriculum.user:
return APIUtilities._api_unauthorized_failure()
delete_individual_curriculum(curriculum)
return APIUtilities.success()
示例5: delete_item
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_unauthorized_failure [as 别名]
def delete_item(request, section_item_id):
try:
item = SectionItem.objects.get(pk=section_item_id)
except:
return APIUtilities._api_not_found()
if not request.user:
return APIUtilities._api_unauthorized_failure()
delete_individual_item(item)
return APIUtilities.success()
示例6: delete_section
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_unauthorized_failure [as 别名]
def delete_section(request, section_id):
try:
section = Section.objects.get(pk=section_id)
except:
return APIUtilities._api_not_found()
if not request.user:
return APIUtilities._api_unauthorized_failure()
for item in section.items.all():
delete_individual_item(item)
section.delete()
return APIUtilities.success()
示例7: delete_class
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_unauthorized_failure [as 别名]
def delete_class(request, class_id):
try:
class_to_delete = Class.objects.get(pk=class_id)
except:
return APIUtilities._api_not_found()
if request.user != class_to_delete.user:
return APIUtilities._api_unauthorized_failure()
# Deep delete all events with this class link.
events = Event.objects.filter(class_link=class_to_delete)
for event in events:
event.delete()
class_to_delete.delete()
return APIUtilities.success()
示例8: get_project_visibility
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_unauthorized_failure [as 别名]
def get_project_visibility(request, project_id):
try:
project = Project.objects.get(pk=project_id)
if not request.user:
return APIUtilities._api_unauthorized_failure()
context = {
'visibility': project.visibility
}
return APIUtilities._api_success(context)
except:
context = {
'title': 'Could not get the visibility of this project.',
'message': 'We failed to retrieve the visibility of '
+ 'this project. Please contact us if the problem persists.'
}
return APIUtilities._api_failure(context)
示例9: delete_category
# 需要导入模块: from oc_platform import APIUtilities [as 别名]
# 或者: from oc_platform.APIUtilities import _api_unauthorized_failure [as 别名]
def delete_category(request, project_id, category_id):
try:
category = GroupCategory.objects.get(pk=category_id)
project = Project.objects.get(pk=project_id)
except:
return APIUtilities._api_not_found()
if not request.user.is_authenticated() or request.user not in project.admins.all():
context = {
'title': 'You are not authorized to delete the category',
'message': 'You need to be logged in as an administrator of the group ' +
'to remove a member from the group.'
}
return APIUtilities._api_unauthorized_failure(context)
group_categories = GroupCategory.objects.filter(parent=project).count()
if group_categories == 1:
context = {
'title': 'Could not delete the only category.',
'message': 'We failed to delete the category you marked for deletion ' +
'as this is the only category in the group and you need to have atleast ' +
'one category in a group. Create another category before you delete this one.'
}
return APIUtilities._api_failure(context)
try:
# Delete all the posts in this category.
Comment.objects.filter(category=category).delete()
category.delete()
return APIUtilities._api_success()
except:
context = {
'title': 'Could not delete the category.',
'message': 'We failed to delete the category of this group '
+ 'due to an internal problem. Please contact us if this problem persists.'
}
return APIUtilities._api_failure(context)