def admin_round_points(selected_season, selected_round): # Get and validate season seasons = config.get_all_seasons() if not selected_season in seasons: abort(404, "Season data not found") round_obj = Round(config, selected_season, selected_round) round_obj.load_points() return render_template("admin_round_points.html", selected_season=selected_season, selected_round=selected_round, round_obj=round_obj)
def admin_round(selected_season): # Get and validate season seasons = config.get_all_seasons() if not selected_season in seasons: abort(404, "Season data not found") season_data = config.get_season_data(selected_season) action = request.form['action'] selected_round = int(request.form['round']) round_obj = Round(config, selected_season, selected_round) # This is when we want to download a round from mylaps by URL if action == 'download': mylaps_url = request.form['url'] mylaps_id_match = re.search(r'\d+', mylaps_url) if not mylaps_id_match: abort(500, "Cannot parse event id from: " + mylaps_url) mylaps_id = mylaps_id_match.group() print "Downloading round #%s year %s: %s" % (selected_round, selected_season, round_obj.get_url(mylaps_id)) result = round_obj.download(mylaps_id) if not result: return abort(500, "Cannot download round data from: " + round_obj.get_url(mylaps_id)) round_obj.store_mylaps_id(mylaps_id) try: print "Recalculating points after downloading a round" season_data.calc_and_store_points() except Exception, e: # If something happens during initial calculation of points, we don't want to keep this session around print "Cannot recalculate points, may be a bad round" print e # round_obj.delete_stored_data() # season_data.calc_and_store_points() return abort(500, "Cannot calculate points: " + str(e)) return jsonify()