本文整理汇总了Python中django.http.HttpResponseForbidden方法的典型用法代码示例。如果您正苦于以下问题:Python http.HttpResponseForbidden方法的具体用法?Python http.HttpResponseForbidden怎么用?Python http.HttpResponseForbidden使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http
的用法示例。
在下文中一共展示了http.HttpResponseForbidden方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def configure(self, request, pk=None):
router = self.get_object()
# Check if the router runs on a supported platform
if not router.platform:
raise ServiceUnavailable("Unsupported router platform.")
# Check user permission first
if not request.user.has_perm("peering.deploy_configuration_router"):
return HttpResponseForbidden()
# Commit changes only if not using a GET request
error, changes = router.set_napalm_configuration(
router.generate_configuration(), commit=(request.method not in SAFE_METHODS)
)
return Response({"changed": not error, "changes": changes, "error": error})
示例2: disabled_when_voting
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def disabled_when_voting(func: Callable) -> Callable:
"""A decorator for controls that are disabled during voting.
Only users with appropriate privileges are still able to perform this action."""
def _decorator(
self: "Controller", request: WSGIRequest, *args, **kwargs
) -> HttpResponse:
if (
self.musiq.base.settings.basic.voting_system
and not self.musiq.base.user_manager.has_controls(request.user)
):
return HttpResponseForbidden()
func(self, request, *args, **kwargs)
self.musiq.update_state()
return HttpResponse()
return wraps(func)(_decorator)
示例3: option
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def option(
func: Callable[[T, WSGIRequest], Optional[HttpResponse]]
) -> Callable[[T, WSGIRequest], HttpResponse]:
"""A decorator that makes sure that only the admin changes a setting."""
def _decorator(self: T, request: WSGIRequest) -> HttpResponse:
# don't allow option changes during alarm
if request.user.username != "admin":
return HttpResponseForbidden()
response = func(self, request)
self.base.settings.update_state()
if response is not None:
return response
return HttpResponse()
return wraps(func)(_decorator)
示例4: join
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def join(request, course_slug, group_slug):
course = get_object_or_404(CourseOffering, slug=course_slug)
group = get_object_or_404(Group, courseoffering = course, slug = group_slug)
person = get_object_or_404(Person, userid = request.user.username)
member = get_object_or_404(Member, person = person, offering=course)
if request.method != "POST":
return HttpResponseForbidden()
for groupMember in GroupMember.objects.filter(group = group, student = member):
groupMember.confirmed = True
groupMember.save()
#LOG EVENT#
l = LogEntry(userid=request.user.username,
description="joined group %s." % (group.name,),
related_object=group )
l.save()
messages.add_message(request, messages.SUCCESS, 'You have joined the group "%s".' % (group.name))
return HttpResponseRedirect(reverse('offering:groups:groupmanage', kwargs={'course_slug': course_slug}))
示例5: reject
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def reject(request, course_slug, group_slug):
course = get_object_or_404(CourseOffering, slug=course_slug)
group = get_object_or_404(Group, courseoffering = course, slug = group_slug)
person = get_object_or_404(Person, userid = request.user.username)
member = get_object_or_404(Member, person = person, offering=course)
if request.method != "POST":
return HttpResponseForbidden()
# delete membership on reject
GroupMember.objects.filter(group = group, student = member).delete()
#LOG EVENT#
l = LogEntry(userid=request.user.username,
description="rejected membership in group %s." % (group.name,),
related_object=group )
l.save()
messages.add_message(request, messages.SUCCESS, 'You have left the group "%s".' % (group.name))
return HttpResponseRedirect(reverse('offering:groups:groupmanage', kwargs={'course_slug': course_slug}))
示例6: change_topic_status
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def change_topic_status(request, course_slug, topic_slug):
"""
Form to change the status of a topic
"""
course, view = _get_course_and_view(request, course_slug)
if view is None:
# course is an HttpResponse in this case
return course
topic = get_object_or_404(DiscussionTopic, slug=topic_slug, offering=course)
if view is not 'staff':
return HttpResponseForbidden()
if request.method == 'POST':
form = DiscussionTopicStatusForm(request.POST, instance=topic)
if form.is_valid():
form.save()
messages.add_message(request, messages.SUCCESS, 'Discussion topic has been successfully changed.')
return HttpResponseRedirect(reverse('offering:discussion:view_topic', kwargs={'course_slug': course_slug, 'topic_slug': topic.slug}))
else:
form = DiscussionTopicStatusForm(instance=topic)
return render(request, 'discuss/change_topic.html', {'course': course, 'topic': topic, 'form': form})
示例7: edit_message
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def edit_message(request, course_slug, topic_slug, message_slug):
"""
Form to edit a recently posted reply (5 min window)
"""
course, view = _get_course_and_view(request, course_slug)
if view is None:
# course is an HttpResponse in this case
return course
topic = get_object_or_404(DiscussionTopic, slug=topic_slug, offering=course)
message = get_object_or_404(DiscussionMessage, slug=message_slug, topic=topic)
if not message.author.person.userid == request.user.username:
return HttpResponseForbidden
if (datetime.datetime.now() - message.created_at) > datetime.timedelta(minutes = 5):
raise Http404
if request.method == 'POST':
form = DiscussionMessageForm(data=request.POST, instance=message)
if form.is_valid():
form.save()
messages.add_message(request, messages.SUCCESS, 'Reply successfully edited.')
return HttpResponseRedirect(reverse('offering:discussion:view_topic', kwargs={'course_slug': course_slug, 'topic_slug': topic.slug}))
else:
form = DiscussionMessageForm(instance=message)
return render(request, 'discuss/edit_reply.html', {'course':course, 'topic': topic, 'message': message, 'form': form})
示例8: remove_message
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def remove_message(request, course_slug, topic_slug, message_slug):
"""
POST to remove a topic message
"""
course, view = _get_course_and_view(request, course_slug)
if view is None:
# course is an HttpResponse in this case
return course
if request.method != 'POST':
raise Http404
topic = get_object_or_404(DiscussionTopic, slug=topic_slug, offering=course)
message = get_object_or_404(DiscussionMessage, slug=message_slug, topic=topic)
if view == 'staff' or message.author.person.userid == request.user.username:
message.status = 'HID'
message.save()
messages.add_message(request, messages.SUCCESS, 'Reply successfully removed.')
return HttpResponseRedirect(reverse('offering:discussion:view_topic', kwargs={'course_slug': course_slug, 'topic_slug': topic_slug}))
else:
return HttpResponseForbidden()
示例9: check_csrf
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def check_csrf(func):
"""Checks/removes a csrf_token from request.session's list of valid tokens."""
def _wrapper(request, *args, **kw):
valid_csrf_tokens = request.session.get('csrf_tokens')
request_csrf_token = request.REQUEST.get('csrf_token')
# Special easter-egg to get around the csrf token.
# Because most malintents don't really read code.
if request.GET.get('csrf_override') == 'elsigh':
return func(request, *args, **kw)
if request_csrf_token is None:
return HttpResponseForbidden('CSRF Error - Need csrf_token in request.')
if request_csrf_token not in valid_csrf_tokens:
return HttpResponseForbidden('CSRF Error - Invalid csrf_token.')
request.session['csrf_token'] = None
request.session['csrf_tokens'].remove(request_csrf_token)
return func(request, *args, **kw)
return _wrapper
示例10: ProxyAuth
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def ProxyAuth(func):
@wraps(func)
def wrapped_func(request, *args, **kw):
# if not request.META.get("HTTP_WEICHAT_USER"):
# return HttpResponseForbidden()
# # return HttpResponse(status=403)
# # return HttpResponseNotFound('<h1>Page not found</h1>')
# pass
# print("\33[36mURI %s\33[0m"%request.build_absolute_uri())
# print(dict((regex.sub('', header), value) for (header, value)
# in request.META.items() if header.startswith('HTTP_')))
# print("\33[34mProxy: is_ajax:%s,WeiChat:[%s],AddR:[%s], Custome:[%s], X_F_F:%s, UA:%.10s\33[0m" % (
# request.is_ajax(),
# request.META.get("HTTP_WEICHAT_USER", "None"),
# request.META.get("REMOTE_ADDR", "None"),
# request.META.get("HTTP_CUSTOMPROXY", "None"),
# request.META.get("HTTP_X_FORWARDED_FOR", "None"),
# request.META.get("HTTP_USER_AGENT", "None"),
# ))
print('is_ajax: %s' % request.is_ajax())
return func(request, *args, **kw)
return wrapped_func
示例11: permission_denied
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def permission_denied(request, exception, template_name=ERROR_403_TEMPLATE_NAME):
"""
Permission denied (403) handler.
:template: :file:`403.html`
If the template does not exist, an Http403 response containing the text
"403 Forbidden" (as per RFC 7231) will be returned.
"""
try:
template = loader.get_template(template_name)
except TemplateDoesNotExist:
if template_name != ERROR_403_TEMPLATE_NAME:
# Reraise if it's a missing custom template.
raise
return http.HttpResponseForbidden(
"<h1>403 Forbidden</h1>", content_type="text/html"
)
return http.HttpResponseForbidden(
template.render(request=request, context={"exception": force_text(exception)})
)
示例12: schedule_create_page
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def schedule_create_page(request, course_id):
course = get_object_or_404(Course, id=course_id)
if not course.user_is_teacher(request.user):
return HttpResponseForbidden()
if request.method == 'POST':
return lesson_create(request, course)
schools = course.school_set.all()
context = {
'is_create': True,
'course': course,
'period_types': Lesson().PERIOD_CHOICES,
'school': schools[0] if schools else '',
'user_location': request.user.profile.location,
'geo_suggest_url': settings.GEO_SUGGEST_URL
}
return render(request, 'lesson_create.html', context)
示例13: schedule_edit_page
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def schedule_edit_page(request, lesson_id):
lssn = get_object_or_404(Lesson, id=lesson_id)
if not lssn.course.user_is_teacher(request.user):
return HttpResponseForbidden()
if request.method == 'POST':
return lesson_edit(request, lssn.course, lesson_id)
schools = lssn.course.school_set.all()
context = {
'is_create': False,
'course': lssn.course,
'lesson': lssn,
'period_types': lssn.PERIOD_CHOICES,
'school': schools[0] if schools else '',
'user_location': request.user.profile.location,
'geo_suggest_url': settings.GEO_SUGGEST_URL
}
return render(request, 'lesson_edit.html', context)
示例14: task_import_page
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def task_import_page(request, course_id):
course = get_object_or_404(Course, id=course_id)
if not course.user_is_teacher(request.user):
return HttpResponseForbidden()
schools = course.school_set.all()
seminar_tasks = Task.objects.filter(type=Task().TYPE_SEMINAR).filter(course=course)
context = {
'is_create': True,
'course': course,
'rb_integrated': course.rb_integrated,
'school': schools[0] if schools else '',
'seminar_tasks': seminar_tasks,
'user_location': request.user.profile.location,
'geo_suggest_url': settings.GEO_SUGGEST_URL
}
return render(request, 'task_import.html', context)
示例15: contest_import_page
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseForbidden [as 别名]
def contest_import_page(request, course_id):
course = get_object_or_404(Course, id=course_id)
if not course.user_is_teacher(request.user):
return HttpResponseForbidden()
schools = course.school_set.all()
seminar_tasks = Task.objects.filter(type=Task().TYPE_SEMINAR).filter(course=course)
context = {
'is_create': True,
'course': course,
'rb_integrated': course.rb_integrated,
'seminar_tasks': seminar_tasks,
'school': schools[0] if schools else '',
'contest_import': True,
'user_location': request.user.profile.location,
'geo_suggest_url': settings.GEO_SUGGEST_URL
}
return render(request, 'contest_import.html', context)