def reactivate_registry(request):
    try:
        id = request.POST.get('RegistryId')
    except ValueError:
        return HttpResponseBadRequest('Please provide an ID in order to reactivate the data provider.')
    try:
        req = reactivate_registry_model(id)

        #If the status is OK, sucess message
        if req.status_code == status.HTTP_200_OK:
            messages.add_message(request, messages.INFO, 'Data provider reactivate 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.')
Example #2
0
def reactivate_registry(request):
    """
    POST http://localhost/oai_pmh/api/reactivate/registry
    POST data query='{"RegistryId":"value"}'
    """
    try:
        #Serialization of the input data
        serializer = RegistryIdSerializer(data=request.DATA)
        #If it's valid
        if serializer.is_valid():
            #Get the ID
            id = request.DATA['RegistryId']
            return reactivate_registry_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)