예제 #1
0
def add_my_metadataFormat(request):
    if request.method == 'POST':
        form = MyMetadataFormatForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                #We retrieve information from the form
                if 'metadataPrefix' in request.POST:
                    metadataprefix = request.POST.get('metadataPrefix')
                if 'schema' in request.POST:
                    schema = request.POST.get('schema')
                #Call to the API to add the registry
                try:
                    req = add_my_metadataFormat_model(metadataprefix, schema)
                    #If the status is OK, sucess message
                    if req.status_code == status.HTTP_201_CREATED:
                        messages.add_message(request, messages.SUCCESS, 'Metadata Format added with success.')
                        return HttpResponse('CREATED')
                    #Else, we return a bad request response with the message provided by the API
                    else:
                        data = req.data
                        return HttpResponseBadRequest(data[APIMessage.label])
                except OAIAPIException as e:
                    return HttpResponseBadRequest(e.message)
                except Exception as e:
                    return HttpResponseBadRequest('An error occurred. Please contact your administrator.')
            except Exception as e:
                return HttpResponseBadRequest('An error occurred. Please contact your administrator.')
        else:
            return HttpResponseBadRequest('Bad entries. Check your entry')
예제 #2
0
def add_my_metadataFormat(request):
    """
    POST http://localhost/oai_pmh/api/add/my-metadataformat
    POST data query='{"metadataPrefix":"value", "schema":"schemaURL"}'
    """
    try:
        serializer = MyMetadataFormatSerializer(data=request.DATA)
        if serializer.is_valid():
            metadataprefix = request.DATA['metadataPrefix']
            schema = request.DATA['schema']
            return add_my_metadataFormat_model(metadataprefix, schema)
        else:
            raise OAIAPISerializeLabelledException(errors=serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    except OAIAPIException as e:
        return e.response()
    except Exception, e:
        content = APIMessage.getMessageLabelled('Unable to add the new metadata format. \n%s'%e.message)
        return Response(content, status=status.HTTP_500_INTERNAL_SERVER_ERROR)