Пример #1
0
    def post(self, request, *args, **kwargs):
        feature = None
        aoi = request.POST.get('aoi')
        geometry = request.POST.get('geometry')
        geojson = json.loads(geometry)
        properties = geojson.get('properties')

        aoi = AOI.objects.get(id=aoi)
        job = getattr(aoi, 'job')
        project = getattr(job, 'project')
        template = properties.get('template') if properties else None

        #TODO: handle exceptions
        if template:
            template = FeatureType.objects.get(id=template)

        attrs = dict(aoi=aoi,
                     job=job,
                     project=project,
                     analyst=request.user,
                     template=template)

        geometry = geojson.get('geometry')
        attrs['the_geom'] = GEOSGeometry(json.dumps(geometry))

        try:
            response = Feature(**attrs)
            response.full_clean()
            response.save()
        except ValidationError as e:
            return HttpResponse(content=json.dumps(dict(errors=e.messages)), mimetype="application/json", status=400)

        return HttpResponse([response], mimetype="application/json")
Пример #2
0
    def post(self, request, *args, **kwargs):
        feature = None
        aoi = request.POST.get('aoi')
        geometry = request.POST.get('geometry')
        geojson = json.loads(geometry)
        properties = geojson.get('properties')

        aoi = AOI.objects.get(id=aoi)
        job = getattr(aoi, 'job')
        project = getattr(job, 'project')
        template = properties.get('template') if properties else None

        # TODO: handle exceptions
        if template:
            template = FeatureType.objects.get(id=template)

        attrs = dict(aoi=aoi,
                     job=job,
                     project=project,
                     analyst=request.user,
                     template=template)

        geometry = geojson.get('geometry')
        attrs['the_geom'] = GEOSGeometry(json.dumps(geometry))

        try:
            response = Feature(**attrs)
            response.full_clean()
            response.save()
        except ValidationError as e:
            return HttpResponse(content=json.dumps(dict(errors=e.messages)),
                                mimetype="application/json",
                                status=400)

        return HttpResponse([response], mimetype="application/json")
Пример #3
0
    def post(self, request, *args, **kwargs):
        feature = None
        tpi = request.META.get('HTTP_TEMP_POINT_ID', "none")
        aoi = request.POST.get('aoi')
        geometry = request.POST.get('geometry')
        geojson = json.loads(geometry)
        properties = geojson.get('properties')

        aoi = AOI.objects.get(id=aoi)
        job = getattr(aoi, 'job')
        project = getattr(job, 'project')
        template = properties.get('template') if properties else None

        # TODO: handle exceptions
        if template:
            template = FeatureType.objects.get(id=template)

        attrs = dict(aoi=aoi,
                     job=job,
                     project=project,
                     analyst=request.user,
                     template=template)

        geometry = geojson.get('geometry')
        geom_obj = GEOSGeometry(json.dumps(geometry))
        attrs['the_geom'] = geom_obj

        county_list = Counties.objects.filter(
            poly__contains=geom_obj.centroid.wkt)
        county = None
        if len(county_list):
            county = str(county_list[0].name)

        try:
            feature = Feature(**attrs)
            feature.full_clean()
            if not feature.properties:
                feature.properties = {}
            if county:
                feature.properties['county'] = county

            feature.save()
        except ValidationError as e:
            response = HttpResponse(content=json.dumps(
                dict(errors=e.messages)),
                                    mimetype="application/json",
                                    status=400)
            response['Temp-Point-Id'] = tpi
            return response
        # This feels a bit ugly but it does get the GeoJSON into the response
        feature_json = serializers.serialize('json', [
            feature,
        ])
        feature_list = json.loads(feature_json)
        feature_list[0]['geojson'] = feature.geoJSON(True)

        response = HttpResponse(json.dumps(feature_list),
                                mimetype="application/json")
        response['Temp-Point-Id'] = tpi
        return response
Пример #4
0
 def test_basic_validation(self):
     feature = Feature(
         account=self.account,
         name="Crm.Business",
         )
     try:
         feature.full_clean()
     except ValidationError as e:
         self.assertEqual(e.message_dict, {'__all__': [u'Name must start with a letter and contain only letters, numbers and underscore.']})
Пример #5
0
    def post(self, request, *args, **kwargs):
        feature = None
        tpi = request.META.get('HTTP_TEMP_POINT_ID', "none")
        aoi = request.POST.get('aoi')
        geometry = request.POST.get('geometry')
        geojson = json.loads(geometry)
        properties = geojson.get('properties')

        aoi = AOI.objects.get(id=aoi)
        job = getattr(aoi, 'job')
        project = getattr(job, 'project')
        template = properties.get('template') if properties else None

        # TODO: handle exceptions
        if template:
            template = FeatureType.objects.get(id=template)

        attrs = dict(aoi=aoi,
                     job=job,
                     project=project,
                     analyst=request.user,
                     template=template)

        geometry = geojson.get('geometry')
        geom_obj = GEOSGeometry(json.dumps(geometry))
        attrs['the_geom'] = geom_obj

        county_list = Counties.objects.filter(poly__contains=geom_obj.centroid.wkt)
        county = None
        if len(county_list):
            county = str(county_list[0].name)

        try:
            feature = Feature(**attrs)
            feature.full_clean()
            if not feature.properties:
                feature.properties = {}
            if county:
                feature.properties['county'] = county

            feature.save()
        except ValidationError as e:
            response =  HttpResponse(content=json.dumps(dict(errors=e.messages)), mimetype="application/json", status=400)
            response['Temp-Point-Id'] = tpi
            return response
        # This feels a bit ugly but it does get the GeoJSON into the response
        feature_json = serializers.serialize('json', [feature,])
        feature_list = json.loads(feature_json)
        feature_list[0]['geojson'] = feature.geoJSON(True)

        response = HttpResponse(json.dumps(feature_list), mimetype="application/json")
        response['Temp-Point-Id'] = tpi
        return response
Пример #6
0
    def post(self, request, *args, **kwargs):
        feature = None
        aoi = request.POST.get('aoi')
        geometry = request.POST.get('geometry')
        geojson = json.loads(geometry)
        properties = geojson.get('properties')

        aoi = AOI.objects.get(id=aoi)
        job = getattr(aoi, 'job')
        project = getattr(job, 'project')
        template = properties.get('template') if properties else None

        # TODO: handle exceptions
        if template:
            template = FeatureType.objects.get(id=template)

        attrs = dict(aoi=aoi,
                     job=job,
                     project=project,
                     analyst=request.user,
                     template=template)

        geometry = geojson.get('geometry')
        attrs['the_geom'] = GEOSGeometry(json.dumps(geometry))

        try:
            feature = Feature(**attrs)
            feature.full_clean()
            feature.save()
        except ValidationError as e:
            return HttpResponse(content=json.dumps(dict(errors=e.messages)),
                                mimetype="application/json",
                                status=400)

        # This feels a bit ugly but it does get the GeoJSON into the response
        feature_json = serializers.serialize('json', [
            feature,
        ])
        feature_list = json.loads(feature_json)
        feature_list[0]['geojson'] = feature.geoJSON(True)

        return HttpResponse(json.dumps(feature_list),
                            mimetype="application/json")
Пример #7
0
    def post(self, request, *args, **kwargs):
        feature = None
        aoi = request.POST.get('aoi')
        geometry = request.POST.get('geometry')
        geojson = json.loads(geometry)
        properties = geojson.get('properties')

        aoi = AOI.objects.get(id=aoi)
        job = getattr(aoi, 'job')
        project = getattr(job, 'project')
        template = properties.get('template') if properties else None

        # TODO: handle exceptions
        if template:
            template = FeatureType.objects.get(id=template)

        attrs = dict(aoi=aoi,
                     job=job,
                     project=project,
                     analyst=request.user,
                     template=template)

        geometry = geojson.get('geometry')
        attrs['the_geom'] = GEOSGeometry(json.dumps(geometry))

        try:
            feature = Feature(**attrs)
            feature.full_clean()
            feature.save()
        except ValidationError as e:
            return HttpResponse(content=json.dumps(dict(errors=e.messages)), mimetype="application/json", status=400)

        # This feels a bit ugly but it does get the GeoJSON into the response
        feature_json = serializers.serialize('json', [feature,])
        feature_list = json.loads(feature_json)
        feature_list[0]['geojson'] = feature.geoJSON(True)

        return HttpResponse(json.dumps(feature_list), mimetype="application/json")