def delete_registry(request): try: id = request.POST.get('RegistryId') except ValueError: return HttpResponseBadRequest('Please provide an ID in order to delete the data provider.') try: req = delete_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 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.')
def delete_registry(request): """ POST http://localhost/oai_pmh/api/delete/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 delete_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)