def status(request): if request.method == 'POST': #Make sure we were passed a feature if not request.POST.has_key('status'): return HttpResponse('{"status_code":"-1", "success":"false", "message":"Expected \'feature\'"}', status=403) import simplejson status = simplejson.loads(request.POST.get('status')) #It must be a new status, create it result = '{"status_code":"-1", "success":"false", "message":"Error saving"}' try: if status.get('field') == 'map_status': up_status = SurveyStatus.objects.get(survey_id=request.session['interview_id']) up_status.map_status=status.get('val') up_status.save() elif status.get('field') == 'act_status': up_status = SurveyStatus.objects.get(survey_id=request.session['interview_id']) up_status.act_status=status.get('val') up_status.save() elif status.get('field') == 'complete': up_status = SurveyStatus.objects.get(survey_id=request.session['interview_id']) up_status.complete=status.get('val') up_status.complete_time = datetime.datetime.now() up_status.save() except Exception, e: return HttpResponse(result + e.message, status=500) result = { "status_code":1, "success":True, "message":"Saved successfully", "status": up_status } return HttpResponse(geojson_encode(result))
def gen_validate_response(code, message, geom, type): if geom: geom.transform( settings.CLIENT_SRID ) result = { 'status_code':code, 'message':message, 'geom':geom, 'type':type } return HttpResponse(geojson_encode(result))
def shapes(request, id=None): if request.method == 'POST': #Make sure we were passed a feature if not request.POST.has_key('feature'): return HttpResponse('{"status_code":"-1", "success":"false", "message":"Expected \'feature\'"}', status=403) import simplejson feat = simplejson.loads(request.POST.get('feature')) #It must be a new shape, create it result = '{"status_code":"-1", "success":"false", "message":"Error saving"}' try: geom = GEOSGeometry(feat.get('geometry'), srid=settings.CLIENT_SRID) geom.transform(settings.SERVER_SRID) if feat.get('type') == 'route': factors = feat.get('factors') other_factor = feat.get('other_factor') if other_factor == '': other_factor = None new_shape = Route( survey = SurveyStatus.objects.get(survey_id=feat.get('survey_id')), geometry = geom, zoom_level = feat.get('zoom_level') ) status = SurveyStatus.objects.get(survey_id=feat.get('survey_id')) status.map_status = 'Route drawn' status.save() # elif feat.get('type') == 'act_area': # new_shape = ActivityArea( # survey_id = SurveyStatus.objects.get(survey_id=feat.get('survey_id')), # geometry = geom, # primary_activity = feat.get('primary_act'), # duration = feat.get('duration'), # rank = feat.get('rank'), # alternate_activity_type = feat.get('alt_act_type'), # ) # status = SurveyStatus.objects.get(survey_id=feat.get('survey_id')) # status.act_status = 'Area drawn' # status.save() elif feat.get('type') == 'act_point': activities = feat.get('activities') if activities['other']: other_act = activities['other'] else: other_act = None fish_targets = feat.get('fish_tgts') if fish_targets and not fish_targets['fish-other'] == False: fish_other = fish_targets['fish-other'] else: fish_other = None if not fish_targets: fish_targets = { 'striped-bass': False, 'bluefish': False, 'flounder': False, 'cod': False, 'haddock': False, 'mackerel': False, 'scup': False, 'tautog': False, 'tuna': False, 'shark': False, 'billfish': False, 'wahoo': False } view_targets = feat.get('view_tgts') if view_targets and not view_targets['view-other'] == False: view_other = view_targets['view-other'] else : view_other = None if not view_targets: view_targets = { 'whales': False, 'dolphin-porpoises': False, 'sea-turtles': False, 'birds': False, 'seals': False } dive_targets = feat.get('dive_tgts') if dive_targets and not dive_targets['dive-other'] == False: dive_other = dive_targets['dive-other'] else : dive_other = None if not dive_targets: dive_targets = { 'exploring': False, 'wrecks': False, 'fishing': False } new_shape = ActivityPoint( survey = SurveyStatus.objects.get(survey_id=feat.get('survey_id')), geometry = geom, fishing = activities['fishing'], viewing = activities['wildlife-viewing'], diving = activities['diving'], swimming = activities['swimming'], relaxing = activities['relaxing'], other_act = other_act, f_strbass = fish_targets['striped-bass'], f_bluefish = fish_targets['bluefish'], f_flounder = fish_targets['flounder'], f_atl_cod = fish_targets['cod'], f_haddock = fish_targets['haddock'], f_mackerel = fish_targets['mackerel'], f_scup = fish_targets['scup'], f_tautog = fish_targets['tautog'], f_tuna = fish_targets['tuna'], f_shark = fish_targets['shark'], f_billfish = fish_targets['billfish'], f_wahoo = fish_targets['wahoo'], f_other = fish_other, v_whales = view_targets['whales'], v_dol_porp = view_targets['dolphin-porpoises'], v_turtles = view_targets['sea-turtles'], v_birds = view_targets['birds'], v_seals = view_targets['seals'], v_other = view_other, d_fishing = dive_targets['fishing'], d_wrecks = dive_targets['wrecks'], d_explore = dive_targets['exploring'], d_other = dive_other, zoom_level = feat.get('zoom_level') ) status = SurveyStatus.objects.get(survey_id=feat.get('survey_id')) status.act_status = 'Point plotted' status.save() new_shape.save() except Exception, e: return HttpResponse(result + e.message, status=500) result = { "status_code":1, "success":True, "message":"Saved successfully", "feature": new_shape } return HttpResponse(geojson_encode(result))