コード例 #1
0
ファイル: views.py プロジェクト: acrosby/sci-wms
    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")
コード例 #2
0
ファイル: views.py プロジェクト: jdickin/sci-wms
    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")
コード例 #3
0
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'
コード例 #4
0
ファイル: test_sgrid.py プロジェクト: lhongjum/sci-wms
 def test_identify(self):
     d = Dataset.objects.get(name=self.dataset_slug)
     klass = Dataset.identify(d.uri)
     assert klass == SGridDataset
コード例 #5
0
ファイル: test_rgrid.py プロジェクト: ayan-usgs/sci-wms
 def test_identify(self):
     d = Dataset.objects.get(name=self.dataset_slug)
     klass = Dataset.identify(d.uri)
     assert klass == RGridDataset