def save_table_state(): """ Save the current state of the table for next / previous buttons """ user_id = g.user.id json_data = request.json table_state_list = [] for ii in range(len(json_data["field_id"])): field_id = json_data["field_id"][ii] ccd_id = json_data["ccd_id"][ii] source_id = json_data["source_id"][ii] table_state_list.append(str_encode_field_ccd_source(field_id, ccd_id, source_id)) # See if there is currently a state stored for this user table_state = table_state_collection.find_one({"user_id" : user_id}) if table_state == None: table_state = dict() table_state["user_id"] = user_id table_state["state"] = table_state_list table_state_collection.insert(table_state, safe=True) else: table_state_collection.update({"user_id" : user_id}, {"$set" : {"state" : table_state_list}}) return ""
def previous_next_light_curve(): """ Load the current state of the table for next / previous buttons """ if not request.args.has_key("source_id") or not request.args.has_key("field_id") or not request.args.has_key("ccd_id"): abort(404) field_id = int(request.args["field_id"]) ccd_id = int(request.args["ccd_id"]) source_id = int(request.args["source_id"]) user_id = g.user.id table_state = table_state_collection.find_one({"user_id" : user_id}) if table_state == None: return jsonify({}) else: idx = table_state["state"].index(str_encode_field_ccd_source(field_id, ccd_id, source_id)) if idx > len(table_state["state"])-1: next_idx = -1 else: next_idx = idx+1 return jsonify(previous=str_decode_field_ccd_source(table_state["state"][idx-1]), next=str_decode_field_ccd_source(table_state["state"][next_idx]))