Beispiel #1
0
def interlink_track(request):
    track_json = json.loads(request.POST.get('track_json'))
    print track_json['id']
    print track_json['start_time']
    track = Track.get_track_by_uuid(track_json['uuid'])
    etappen = Etappe.get_etappen_by_date(track_json['start_time'])
    print etappen
    for etappe in etappen:
        print etappe.start_date
        etappe.track.append(track)    
    return Response(json.dumps({'link_status':'linked', 'item_uuid': track.uuid}))
Beispiel #2
0
def logsync(request):
    sync_status='sync_error'
    log_json = json.loads(request.POST.get('log_json').value)
    print log_json
    etappe_json = log_json['etappe']
    #TODO: might be better with dates instead of uuid
    etappe = Etappe.get_etappe_by_uuid(etappe_json['uuid']) 
    if not etappe:
        etappe = Etappe(
                start_date = etappe_json['start_date'],
                end_date = etappe_json['end_date'],
                name = etappe_json['name'],
                uuid = etappe_json['uuid']
                )
        DBSession.add(etappe)
        DBSession.flush()

    log = Log.get_log_by_uuid(log_json['uuid'])
    if not log:
        print 'No log found, adding new log.'
        print 'Author: '+log_json['author']
        author = Author.get_author(log_json['author'])
        print author
        log = Log(
                infomarker = None,
                topic=log_json['topic'],
                content=log_json['content'],
                author=author.id,
                etappe=etappe.id,
                created=log_json['created'],
                published=timetools.now(),
                uuid=log_json['uuid']
                )
        DBSession.add(log)
        DBSession.flush()
        sync_status = 'is_synced'; #Item was not synced before we started
    elif log: #TODO: Updating log, needs last_change comparison and stuff
        print 'Log already exists on server'
        sync_status = 'was_synced' #Item was already on the server earlier        
    else:
        sync_status = 'sync_error' #something is wrong here!
    return Response(json.dumps({'log_id':log_json['id'], 'type':'log', 'item_uuid':log_json['uuid'], 'sync_status':sync_status}))