Python django.http.response.HttpResponseForbidden() Examples
The following are 9
code examples of django.http.response.HttpResponseForbidden().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.http.response
, or try the search function
.
Example #1
Source File: views.py From yats with MIT License | 6 votes |
def yatse_api(request): try: if request.method != 'PROPFIND': api_login(request) except PermissionDenied: return HttpResponseForbidden(request.META.get('HTTP_API_USER')) if request.method == 'PROPPATCH': data = json.loads(request.body) if 'ticket' in data and 'method' in data: if data['method'] == 'notify': tickets_participants.objects.filter(ticket=data['ticket'], user=request.user).update(seen=True) return HttpResponse('OK') return HttpResponseNotFound('invalid method\n\n%s' % request.body) elif request.method == 'PROPFIND': fields = buildYATSFields([]) return JsonResponse(fields[0], safe=False) elif request.method == 'SEARCH': return JsonResponse(YATSSearch(request), safe=False) else: return HttpResponseNotFound('invalid method')
Example #2
Source File: views.py From intake with MIT License | 5 votes |
def dispatch(self, *args, **kwargs): if not self.request.user.has_perm('clips.add_clip'): return HttpResponseForbidden() return super(ClipCreateView, self).dispatch(*args, **kwargs)
Example #3
Source File: views.py From intake with MIT License | 5 votes |
def dispatch(self, *args, **kwargs): if not self.request.user.has_perm('clips.change_clip'): return HttpResponseForbidden() return super(ClipUpdateView, self).dispatch(*args, **kwargs)
Example #4
Source File: views.py From intake with MIT License | 5 votes |
def dispatch(self, *args, **kwargs): if not self.request.user.has_perm('clips.delete_clip'): return HttpResponseForbidden() return super(ClipDeleteView, self).dispatch(*args, **kwargs)
Example #5
Source File: views.py From django-translation-manager with Mozilla Public License 2.0 | 5 votes |
def get(self, request): token = request.GET.get('token') if not token or token != settings.TRANSLATIONS_SYNC_LOCAL_TOKEN: return HttpResponseForbidden() translations = TranslationEntry.objects.all() data = defaultdict(dict) for entry in translations: data[entry.language].setdefault(entry.domain, defaultdict(dict))[entry.original] = dict(translation=entry.translation, changed=entry.changed) return JsonResponse(data)
Example #6
Source File: multiform.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def _process_individual_form(self, form_name, form_classes): """ Perform the is_valid() check for a single form. """ forms = self.get_forms(form_classes, (form_name,)) form = forms.get(form_name) if not form: # there is no form with this name registered in the form_classes dictionary return HttpResponseForbidden() elif form.is_valid(): # the form is valid -> call the from valid method return self.forms_valid(forms, form_name) else: # call the form invalid method return self.forms_invalid(forms, form_name)
Example #7
Source File: discoveries.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def clear_by_mac_and_ip(self, request, **kwargs): """@description-title Delete discoveries that match a MAC and IP @description Deletes all discovered neighbours (and associated reverse DNS entries) associated with the given IP address and MAC address. @param (string) "ip" [required=true] IP address @param (string) "mac" [required=true] MAC address @success (http-status-code) "server-success" 204 """ ip = get_mandatory_param(request.POST, "ip") mac = get_mandatory_param(request.POST, "mac") if not request.user.has_perm(NodePermission.admin, Discovery): response = HttpResponseForbidden( content_type="text/plain", content="Must be an administrator to clear discovery entries.", ) return response delete_result = Discovery.objects.delete_by_mac_and_ip( ip=ip, mac=mac, user=request.user ) if delete_result[0] == 0: return rc.NOT_HERE else: return rc.DELETED
Example #8
Source File: views.py From django-modern-rpc with MIT License | 4 votes |
def post(self, request, *args, **kwargs): """ Handle a XML-RPC or JSON-RPC request. :param request: Incoming request :param args: Additional arguments :param kwargs: Additional named arguments :return: A HttpResponse containing XML-RPC or JSON-RPC response, depending on the incoming request """ logger.debug('RPC request received...') for handler_cls in self.get_handler_classes(): handler = handler_cls(request, self.entry_point) try: if not handler.can_handle(): continue logger.debug('Request will be handled by {}'.format(handler_cls.__name__)) result = handler.process_request() return handler.result_success(result) except AuthenticationFailed as e: # Customize HttpResponse instance used when AuthenticationFailed was raised logger.warning(e) return handler.result_error(e, HttpResponseForbidden) except RPCException as e: logger.warning('RPC exception: {}'.format(e), exc_info=settings.MODERNRPC_LOG_EXCEPTIONS) return handler.result_error(e) except Exception as e: logger.error('Exception raised from a RPC method: "{}"'.format(e), exc_info=settings.MODERNRPC_LOG_EXCEPTIONS) return handler.result_error(RPCInternalError(str(e))) logger.error('Unable to handle incoming request.') return HttpResponse('Unable to handle your request. Please ensure you called the right entry point. If not, ' 'this could be a server error.')
Example #9
Source File: discoveries.py From maas with GNU Affero General Public License v3.0 | 4 votes |
def clear(self, request, **kwargs): """@description-title Delete all discovered neighbours @description Deletes all discovered neighbours and/or mDNS entries. Note: One of ``mdns``, ``neighbours``, or ``all`` parameters must be supplied. @param (boolean) "mdns" [required=false] Delete all mDNS entries. @param (boolean) "neighbours" [required=false] Delete all neighbour entries. @param (boolean) "all" [required=false] Delete all discovery data. @success (http-status-code) "server-success" 204 """ all = get_optional_param( request.POST, "all", default=False, validator=StringBool ) mdns = get_optional_param( request.POST, "mdns", default=False, validator=StringBool ) neighbours = get_optional_param( request.POST, "neighbours", default=False, validator=StringBool ) if not request.user.has_perm(NodePermission.admin, Discovery): response = HttpResponseForbidden( content_type="text/plain", content="Must be an administrator to clear discovery entries.", ) return response if True not in (mdns, neighbours, all): content = dedent( """\ Bad request: could not determine what data to clear. Must specify mdns=True, neighbours=True, or all=True.""" ) response = HttpResponseBadRequest( content_type="text/plain", content=content ) return response Discovery.objects.clear( user=request.user, all=all, mdns=mdns, neighbours=neighbours ) return rc.DELETED