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