def post(self, request): try: uri = request.POST['uri'] name = request.POST['name'] assert uri and name except (AssertionError, KeyError): return HttpResponse('URI and Name are required. Please try again.', status=500, reason="Could not process inputs", content_type="text/plain") klass = Dataset.identify(uri) if klass is not None: try: ds = klass.objects.create(uri=uri, name=name) except IntegrityError: return HttpResponse( 'Name is already taken, please choose another', status=500, reason="Could not process inputs", content_type="application/json") return HttpResponse(serializers.serialize('json', [ds]), status=201, content_type="application/json") else: return HttpResponse( 'Could not process the URI with any of the available Dataset types. Please check the URI and try again', status=500, reason="Could not process inputs", content_type="application/json")
def post(self, request): try: uri = request.POST['uri'] name = request.POST['name'] assert uri and name except (AssertionError, KeyError): return HttpResponse('URI and Name are required. Please try again.', status=500, reason="Could not process inputs", content_type="text/plain") klass = Dataset.identify(uri) if klass is not None: try: ds = klass.objects.create(uri=uri, name=name) except IntegrityError: return HttpResponse('Name is already taken, please choose another', status=500, reason="Could not process inputs", content_type="application/json") return HttpResponse(serializers.serialize('json', [ds]), status=201, content_type="application/json") else: return HttpResponse('Could not process the URI with any of the available Dataset types. Please check the URI and try again', status=500, reason="Could not process inputs", content_type="application/json")
def add_unidentified_dataset(pkey): with HUEY.lock_task('unidentified-{}'.format(pkey)): try: ud = UnidentifiedDataset.objects.get(pk=pkey) klass = Dataset.identify(ud.uri) if klass is not None: try: ud.delete() ds = klass.objects.create(name=ud.name, uri=ud.uri) return 'Added {}'.format(ds.name) except IntegrityError: msg = 'Could not add dataset, name "{}" already exists'.format( ud.name) ud.messages = msg ud.save() return msg else: msg = 'No dataset types found to process {}'.format(ud.uri) ud.messages = msg ud.save() return msg except UnidentifiedDataset.DoesNotExist: return 'UnidentifiedDataset did not exist, can not complete task'
def test_identify(self): d = Dataset.objects.get(name=self.dataset_slug) klass = Dataset.identify(d.uri) assert klass == SGridDataset
def test_identify(self): d = Dataset.objects.get(name=self.dataset_slug) klass = Dataset.identify(d.uri) assert klass == RGridDataset