def tracksync(request): #print request.json_body track = Track.get_track_by_id(request.json_body['track']['id']) log_json = request.json_body['log'] log = Log.get_log_by_id(log_json['id']) print track.reprJSON_extended()['author'] if interlink_only: return Response(json.dumps({'log_id':log.id, 'type':'track', 'item_uuid':track.uuid, 'sync_status':'was_synced'})) else: headers = {'content-type':'application/json'} url = 'http://poab.org:6544/sync?type=status' payload = {'payloadtype':'track', 'track_json':json.dumps(track.reprJSON()), 'log_json':json.dumps(log.reprJSON())} remote_sync_info = requests.post(url, data=payload) print remote_sync_info.text sync_status=json.loads(remote_sync_info.text)['sync_status'] #if sync_status is 'was_synced', we already have this track on the server print '\n################ TRACK SYNC STATUS: '+sync_status+str(log.id) + '\n' #TODO: this prevents half uploaded trackpoints from beeing finished!!!! if sync_status == 'not_synced': headers = {'content-type':'application/json'} url = 'http://poab.org:6544/sync?type=track' payload = {'track':json.dumps(track.reprJSON_extended()), 'log_json':json.dumps(log.reprJSON())} remote_sync_info = requests.post(url, data=payload) return Response(remote_sync_info.text)
DBSession.add(log) DBSession.flush() print 'logid='+str(log.id) for image in images: try: if image['id']: print 'imageid:'+ str(image['id']) image = Image.get_image_by_id(image['id']) log.image.append(image) except Exception, e: print e print 'ERROR while saving log' for track in tracks: if track['id']: print 'trackid:'+ str(track['id']) track = Track.get_track_by_id(track['id']) log.track.append(track) return Response(json.dumps(dict(log_id=log.id, etappe_id=etappe.id),cls=ComplexEncoder)) @view_config(route_name='update_image_metadata') def update_image_metadata(request): print request.json_body for image_dict in request.json_body: try: if image_dict['id']: image=Image.get_image_by_id(image_dict['id']) if image.title != image_dict['title'] or \ image.alt != image_dict['alt'] or \ image.comment != image_dict['comment']: #only update if there were changes