Beispiel #1
0
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)
Beispiel #2
0
def interlink(request):
    item_info_json = request.json_body
    sync_status = item_info_json['sync_status']
    type = item_info_json['type']
    uuid =  item_info_json['item_uuid']
    log_id = item_info_json['log_id']
    remote_sync_info = None

    if sync_status == 'is_synced' or sync_status == 'was_synced':
        if type == 'log':
            log = Log.get_log_by_uuid(uuid)
            headers = {'content-type':'application/json'}
            url = 'http://poab.org:6544/sync?interlink=log'
            payload = {'log_json':json.dumps(log.reprJSON_extended())}
            remote_sync_info = requests.post(url, data=payload)
        if type == 'image':
            image = Image.get_image_by_uuid(uuid)
            print image
            headers = {'content-type':'application/json'}
            url = 'http://poab.org:6544/sync?interlink=image'
            payload = {'image_json':json.dumps(image.reprJSON_extended())}
            remote_sync_info = requests.post(url, data=payload)
        if type == 'track':
            track = Track.get_track_by_uuid(uuid)
            print track
            headers = {'content-type':'application/json'}
            url = 'http://poab.org:6544/sync?interlink=track'
            payload = {'track_json':json.dumps(track.reprJSON())}
            remote_sync_info = requests.post(url, data=payload)
    print remote_sync_info
    return Response(remote_sync_info.text)
Beispiel #3
0
def add_track_to_db(track_details, author):
    track = track_details['track']
    trackpoints = track_details['trackpoints']
    track_in_db = Track.get_track_by_reduced_trackpoints(track.reduced_trackpoints)
    
    if not track_in_db:
        track.author = author.id
        track.uuid = str(uuid.uuid4())
        track.start_time = trackpoints[0].timestamp
        track.end_time = trackpoints[-1].timestamp
        try:
            DBSession.add(track)
            DBSession.flush()
        except Exception, e:
            DBSession.rollback()
            print "\n\nTrack could not be added!\n\n"
            print e
            return None
Beispiel #4
0
    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