def place_rough_atlas(id): ''' ''' conn = mysql_connection() mysql = conn.cursor(cursor_class=MySQLCursorDict) map_id = choose_map(mysql, atlas_id=id) conn.close() return redirect('/place-rough/map/%s' % map_id)
def place_rough_map(id): ''' ''' conn = mysql_connection() mysql = conn.cursor(cursor_class=MySQLCursorDict) # get atlas, supplies edit ui w/ hints mysql.execute('SELECT * FROM maps WHERE id = %s', (id, )) map = mysql.fetchdict() if not map: abort(404) # get atlas, supplies edit ui w/ hints atlas_id = map['atlas_id'] mysql.execute('SELECT * FROM atlases WHERE id = %s', (map['atlas_id'], )) atlas = mysql.fetchdict() # cookies to check if you've placed all maps in atlas # maps_remaining will return 0 when on last map cookie_id = '__%s_atlas_%s' % (aws_prefix, atlas_id) if request.method == 'POST': if request.form.get('action', None) == 'place': # # Expect four floating point values from a submitted form: ul_lat, # ul_lon, lr_lat, and lr_lon corresponding to the four corners of the # roughly-placed map. Make a note of the new placement and respond # with a 303 redirect to send the submitter someplace useful. # ul_lat = float(request.form.get('ul_lat', None)) ul_lon = float(request.form.get('ul_lon', None)) lr_lat = float(request.form.get('lr_lat', None)) lr_lon = float(request.form.get('lr_lon', None)) place_roughly(mysql, queue_tile, map, ul_lat, ul_lon, lr_lat, lr_lon) elif request.form.get('action', None) == 'skip': # counting number of times the map has been skipped, possibly to track bad maps if 'skip_map' in map: skip_map_ct = int(map['skip_map']) + 1 else: skip_map_ct = 1 map['skip_map'] = skip_map_ct # TODO: do something with skip map? else: raise Exception('Mission or invalid "action"') next_map_id = choose_map(mysql, atlas_id=map['atlas_id'], skip_map_id=map['id']) maps_cookie = request.cookies.get(cookie_id) cookie_str = '' if maps_cookie: maps_cookie = maps_cookie.split("|") maps_remaining = int(atlas['map_count']) - len(maps_cookie) if maps_remaining == 0: cookie_str = "done" elif map['id'] not in maps_cookie: maps_cookie.append(map['id']) cookie_str = "|".join(maps_cookie) else: cookie_str = "|".join(maps_cookie) else: maps_cookie = [map['id']] cookie_str = "|".join(maps_cookie) resp = make_response( redirect('/place-rough/map/%s' % next_map_id, code=303)) resp.set_cookie(cookie_id, cookie_str) return resp maps_cookie = request.cookies.get(cookie_id) if maps_cookie: if maps_cookie == "done": maps_remaining = '0' else: maps_cookie = maps_cookie.split("|") maps_remaining = int(atlas['map_count']) - len(maps_cookie) else: maps_remaining = int(atlas['map_count']) return render_template('place-rough-map.html', map=map, atlas=atlas, maps_remaining=maps_remaining)