示例#1
0
    def create(self, validated_data):
        schema_url = validated_data.pop('schemaURL')
        schema_request = requests.get(schema_url)
        schema_request.raise_for_status()

        schemadoc = etree.fromstring(schema_request.content)

        print(schemadoc.nsmap)
        nsmap = {
            k: v
            for k, v in schemadoc.nsmap.items()
            if k and v != "http://www.w3.org/2001/XMLSchema"
        }
        targetNamespace = schemadoc.get('targetNamespace')

        prefix = validated_data.pop('prefix')
        extensionElements, extensionAll, attributes = generateExtensionRef(
            schemadoc, prefix)

        return extensionPackage.objects.create(
            prefix=prefix,
            schemaURL=schema_url,
            targetNamespace=targetNamespace,
            allElements=extensionAll,
            existingElements=extensionElements,
            allAttributes=attributes,
            nsmap=nsmap,
            **validated_data)
示例#2
0
    def create(self, validated_data):
        schema_url = validated_data.pop('schemaURL')
        schema_request = requests.get(schema_url)
        schema_request.raise_for_status()

        schemadoc = etree.fromstring(schema_request.content)

        print(schemadoc.nsmap)
        nsmap = {k: v for k, v in schemadoc.nsmap.items() if k and v != "http://www.w3.org/2001/XMLSchema"}
        targetNamespace = schemadoc.get('targetNamespace')

        prefix = validated_data.pop('prefix')
        extensionElements, extensionAll, attributes = generateExtensionRef(schemadoc, prefix)

        return extensionPackage.objects.create(
            prefix=prefix, schemaURL=schema_url, targetNamespace=targetNamespace,
            allElements=extensionAll, existingElements=extensionElements,
            allAttributes=attributes, nsmap=nsmap, **validated_data
        )
示例#3
0
    def post(self, request, *args, **kwargs):
        obj = get_object_or_404(templatePackage, pk=kwargs['name'])

        form = AddExtensionForm(request.POST)

        if form.is_valid():
            prefix = form.cleaned_data.get('namespace_prefix')
            schema = form.cleaned_data.get('schema')

            from requests.packages.urllib3.exceptions import (
                InsecureRequestWarning, InsecurePlatformWarning)

            requests.packages.urllib3.disable_warnings(InsecurePlatformWarning)
            requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

            schema_request = requests.get(schema)
            schema_request.raise_for_status()

            schemadoc = etree.fromstring(schema_request.content)
            nsmap = {
                k: v
                for k, v in schemadoc.nsmap.items()
                if k and v != "http://www.w3.org/2001/XMLSchema"
            }
            targetNamespace = schemadoc.get('targetNamespace')

            extensionElements, extensionAll, attributes = generateExtensionRef(
                schemadoc, prefix)

            e = extensionPackage.objects.create(
                prefix=prefix,
                schemaURL=schema,
                targetNamespace=targetNamespace,
                allElements=extensionAll,
                existingElements=extensionElements,
                allAttributes=attributes)
            obj.extensions.add(e)
            obj.existingElements["root"]["nsmap"].update(nsmap)
            obj.save()

            return HttpResponse('Success: Added extension schema')

        return render(request, self.template_name, {'form': form})