コード例 #1
0
ファイル: api.py プロジェクト: ABasoni/starterkit
def mdimport(request, template='mdtools/upload_metadata.html'):
    if request.method == 'POST':
        form = UploadMetadataFileForm(request.POST, request.FILES)
        if form.is_valid():
            # response_data = set_metadata(request.FILES['file'].read())
            # return HttpResponse(json.dumps(response_data, 
            #                                sort_keys=True,
            #                                indent=4, 
            #                                separators=(',', ': '),
            #                                cls=DjangoJSONEncoder), 
            #                     content_type="application/json")
            layerid = form.cleaned_data['layerid']
            layer = Layer.objects.get(pk=layerid)

            xml = request.FILES['file'].read()
            # response_data = _parse_metadata(xml)
            vals, keywords = rndt2dict(etree.fromstring(xml))
            response_data = _mdimport(layer, vals, keywords, xml)
            
            return HttpResponse(json.dumps(response_data, 
                                           default=lambda o: o.__dict__, 
                                           sort_keys=True,
                                           indent=4, 
                                           separators=(',', ': '),
                                           cls=DjangoJSONEncoder), 
                                content_type="application/json")

    else:
        form = UploadMetadataFileForm()
    return render_to_response(template,
                              RequestContext(request, {'form': form}))
コード例 #2
0
def importediml(request, template='mdtools/upload_metadata.html'):
    if request.method == 'POST':
        form = UploadMetadataFileForm(request.POST, request.FILES)
        if form.is_valid():
            layername = Layer.objects.get(
                pk=form.cleaned_data['layer']).typename
            layer = _resolve_layer(request, layername, 'base.change_layer',
                                   _PERMISSION_MSG_METADATA)
            ediml = request.FILES['file'].read()
            try:
                rndt = _ediml2rndt(ediml)
            except UnregisteredSKException as e:
                messages.add_message(request, messages.ERROR, e)
            if not rndt:
                messages.add_message(request, messages.ERROR,
                                     'Cannot get RNDT.')
            try:
                _savelayermd(layer, rndt, ediml)
                messages.add_message(request, messages.SUCCESS,
                                     'Metadata Uploaded')
            except Exception as e:
                messages.add_message(request, messages.ERROR, e)

    else:
        form = UploadMetadataFileForm()
    return render(request, template, {'form': form})
コード例 #3
0
def mdimport(request, template='mdtools/upload_metadata.html'):
    if request.method == 'POST':
        form = UploadMetadataFileForm(request.POST, request.FILES)
        if form.is_valid():
            # response_data = set_metadata(request.FILES['file'].read())
            # return HttpResponse(json.dumps(response_data,
            #                                sort_keys=True,
            #                                indent=4,
            #                                separators=(',', ': '),
            #                                cls=DjangoJSONEncoder),
            #                     content_type="application/json")
            layerid = form.cleaned_data['layerid']
            layer = Layer.objects.get(pk=layerid)

            xml = request.FILES['file'].read()
            # response_data = _parse_metadata(xml)
            vals, keywords = rndt2dict(etree.fromstring(xml))
            response_data = _mdimport(layer, vals, keywords, xml)

            return HttpResponse(json.dumps(response_data,
                                           default=lambda o: o.__dict__,
                                           sort_keys=True,
                                           indent=4,
                                           separators=(',', ': '),
                                           cls=DjangoJSONEncoder),
                                content_type="application/json")

    else:
        form = UploadMetadataFileForm()
    return render_to_response(template, RequestContext(request,
                                                       {'form': form}))
コード例 #4
0
ファイル: api.py プロジェクト: SP7-Ritmare/starterkit
def importrndt(request, template='mdtools/upload_metadata.html'):
    if request.method == 'POST':
        form = UploadMetadataFileForm(request.POST, request.FILES)
        if form.is_valid():
            layername = Layer.objects.get(pk=form.cleaned_data['layer']).typename
            layer = _resolve_layer(request, layername, 'base.change_layer', _PERMISSION_MSG_METADATA)
            rndt = request.FILES['file'].read()
            try:
                _savelayermd(layer, rndt, None)
                messages.add_message(request, messages.SUCCESS, 'Metadata Uploaded')
            except Exception as e:
                messages.add_message(request, messages.ERROR, e)

    else:
        form = UploadMetadataFileForm()
    return render_to_response(template,
                              RequestContext(request, {'form': form}))
コード例 #5
0
def importrndt(request, template='mdtools/upload_metadata.html'):
    if request.method == 'POST':
        form = UploadMetadataFileForm(request.POST, request.FILES)
        if form.is_valid():
            layername = Layer.objects.get(pk=form.cleaned_data['layer']).typename
            layer = _resolve_layer(request, layername, 'layers.change_layer', _PERMISSION_MSG_METADATA)
            rndt = request.FILES['file'].read()
            try:
                _savelayermd(layer, rndt, None)
                messages.add_message(request, messages.SUCCESS, 'Metadata Uploaded')
            except Exception as e:
                messages.add_message(request, messages.ERROR, e)

    else:
        form = UploadMetadataFileForm()
    return render_to_response(template,
                              RequestContext(request, {'form': form}))
コード例 #6
0
ファイル: api.py プロジェクト: SP7-Ritmare/starterkit
def importediml(request, template='mdtools/upload_metadata.html'):
    if request.method == 'POST':
        form = UploadMetadataFileForm(request.POST, request.FILES)
        if form.is_valid():
            layername = Layer.objects.get(pk=form.cleaned_data['layer']).typename
            layer = _resolve_layer(request, layername, 'base.change_layer', _PERMISSION_MSG_METADATA)
            ediml = request.FILES['file'].read()
            try:
                rndt = _ediml2rndt(ediml)
            except UnregisteredSKException, e:
                messages.add_message(request, messages.ERROR, e)
            if not rndt:
                messages.add_message(request, messages.ERROR, 'Cannot get RNDT.')
            try:
                _savelayermd(layer, rndt, ediml)
                messages.add_message(request, messages.SUCCESS, 'Metadata Uploaded')
            except Exception as e:
                messages.add_message(request, messages.ERROR, e)