Example #1
0
def delete_my_metadataFormat(request):
    """
    POST http://localhost/oai_pmh/api/delete/my-metadataFormat
    POST data query='{"MetadataFormatId":"value"}'
    """
    try:
        serializer = DeleteMyMetadataFormatSerializer(data=request.DATA)
        if serializer.is_valid():
            id = request.DATA['MetadataFormatId']
            return delete_my_metadataFormat_model(id)
        else:
            raise OAIAPISerializeLabelledException(errors=serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    except OAIAPIException as e:
        return e.response()
    except Exception as e:
        content = APIMessage.getMessageLabelled(e.message)
        return Response(content, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def delete_my_metadataFormat(request):
    try:
        id = request.POST.get('MetadataFormatId')
    except ValueError:
        return HttpResponseBadRequest('Please provide an ID in order to delete the metadata format.')
    try:
        req = delete_my_metadataFormat_model(id)
        #If the status is OK, sucess message
        if req.status_code == status.HTTP_200_OK:
            messages.add_message(request, messages.INFO, 'Metadata Format deleted with success.')
            return HttpResponse(json.dumps({}), content_type='application/javascript')
        #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.')