})
-def process_save(request, objects, map_projection, attr_or_geom):
+def process_save(request, objects, map_projection, attr_or_geom, check_rights):
"""
Process Save
Param: POST Json with feature to save
forbidden_msg = _("You are not allowed to modify information in this zone.")
- # Check zone right for the current user
- auth_geom = request.user.get_profile().get_geometry_extent()
- if auth_geom :
- ext_coords = ((auth_geom[0], auth_geom[1]), (auth_geom[0], auth_geom[3]), (auth_geom[2], auth_geom[3]), (auth_geom[2], auth_geom[1]), (auth_geom[0], auth_geom[1]))
- auth_poly_geom = Polygon(ext_coords)
- else :
- response_content = {'records': []}
- response = HttpResponse()
- response_content['records'].append({
- 'status': False,
- 'msg': forbidden_msg
- })
- simplejson.dump(response_content, response, ensure_ascii=False, separators=(',', ':'))
- return response
+ # Check zone right for the current user
+ if check_rights :
+ auth_geom = request.user.get_profile().get_geometry_extent()
+ if auth_geom :
+ ext_coords = ((auth_geom[0], auth_geom[1]), (auth_geom[0], auth_geom[3]), (auth_geom[2], auth_geom[3]), (auth_geom[2], auth_geom[1]), (auth_geom[0], auth_geom[1]))
+ auth_poly_geom = Polygon(ext_coords)
+ else :
+ response_content = {'records': []}
+ response = HttpResponse()
+ response_content['records'].append({
+ 'status': False,
+ 'msg': forbidden_msg
+ })
+ simplejson.dump(response_content, response, ensure_ascii=False, separators=(',', ':'))
+ return response
+
+ for feature in objects:
+ geom = feature.get('geom')
+ if geom :
+ # See if auth_geom contains geom. If not, refuse the modification : not allowed
+ wkt_str = "SRID=%s;%s" % (map_projection, geom)
+ geometry = GEOSGeometry(wkt_str)
+ srid = settings.GRACE_DATA_PROJECTION
+ geometry = geometry.transform(srid, clone=True)
+
+ intersect = auth_poly_geom.intersects(geometry)
+ if not intersect:
+ response_content = {'records': []}
+ response = HttpResponse()
+ response_content['records'].append({
+ 'status': False,
+ 'msg': forbidden_msg
+ })
+ simplejson.dump(response_content, response, ensure_ascii=False, separators=(',', ':'))
+ return response
- for feature in objects:
- geom = feature.get('geom')
- if geom :
- # See if auth_geom contains geom. If not, refuse the modification : not allowed
- wkt_str = "SRID=%s;%s" % (map_projection, geom)
- geometry = GEOSGeometry(wkt_str)
- srid = settings.GRACE_DATA_PROJECTION
- geometry = geometry.transform(srid, clone=True)
-
- intersect = auth_poly_geom.intersects(geometry)
- if not intersect:
- response_content = {'records': []}
- response = HttpResponse()
- response_content['records'].append({
- 'status': False,
- 'msg': forbidden_msg
- })
- simplejson.dump(response_content, response, ensure_ascii=False, separators=(',', ':'))
- return response
-
- # If we deal with saving attributes only, then pop the geom value
- if attr_or_geom :
- feature.pop('geom')
+ # If we deal with saving attributes only, then pop the geom value
+ if attr_or_geom :
+ feature.pop('geom')
today = time.strftime('%y/%m/%d', time.localtime())
params = request.POST
objects = simplejson.loads(params['data'])
map_projection = params['map_projection']
- return process_save(request, objects, map_projection, True)
+ return process_save(request, objects, map_projection, True, True)
@csrf_exempt
def save_feature_geom(request):
objects = simplejson.loads(params['data'])
map_projection = params['map_projection']
- return process_save(request, objects, map_projection, False)
+ return process_save(request, objects, map_projection, False, True)
@csrf_exempt
def add_feature(request):
objects = simplejson.loads(params['data'])
map_projection = params['map_projection']
- return process_save(request, objects, map_projection, False)
+ return process_save(request, objects, map_projection, False, False)