当前位置: 首页>>代码示例>>Python>>正文


Python response.HttpResponseForbidden方法代码示例

本文整理汇总了Python中django.http.response.HttpResponseForbidden方法的典型用法代码示例。如果您正苦于以下问题:Python response.HttpResponseForbidden方法的具体用法?Python response.HttpResponseForbidden怎么用?Python response.HttpResponseForbidden使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.http.response的用法示例。


在下文中一共展示了response.HttpResponseForbidden方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: yatse_api

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import HttpResponseForbidden [as 别名]
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') 
开发者ID:mediafactory,项目名称:yats,代码行数:27,代码来源:views.py

示例2: dispatch

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import HttpResponseForbidden [as 别名]
def dispatch(self, *args, **kwargs):
        if not self.request.user.has_perm('clips.add_clip'):
            return HttpResponseForbidden()
        return super(ClipCreateView, self).dispatch(*args, **kwargs) 
开发者ID:codeforamerica,项目名称:intake,代码行数:6,代码来源:views.py

示例3: get

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import HttpResponseForbidden [as 别名]
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) 
开发者ID:COEXCZ,项目名称:django-translation-manager,代码行数:16,代码来源:views.py

示例4: _process_individual_form

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import HttpResponseForbidden [as 别名]
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) 
开发者ID:iguana-project,项目名称:iguana,代码行数:17,代码来源:multiform.py

示例5: clear_by_mac_and_ip

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import HttpResponseForbidden [as 别名]
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 
开发者ID:maas,项目名称:maas,代码行数:29,代码来源:discoveries.py

示例6: post

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import HttpResponseForbidden [as 别名]
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.') 
开发者ID:alorence,项目名称:django-modern-rpc,代码行数:46,代码来源:views.py

示例7: clear

# 需要导入模块: from django.http import response [as 别名]
# 或者: from django.http.response import HttpResponseForbidden [as 别名]
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 
开发者ID:maas,项目名称:maas,代码行数:48,代码来源:discoveries.py


注:本文中的django.http.response.HttpResponseForbidden方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。