def get_rules(event): if event is None: return None rule_sets = scoring_rules.get_rule_sets() if event['rule_set'] in rule_sets: rules = rule_sets[event['rule_set']]() if event['max_runs'] is not None: rules.max_runs = event['max_runs'] if event['drop_runs'] is not None: rules.drop_runs = event['drop_runs'] return rules else: return None
def events_page(): db = get_db() action = request.form.get('action') if action == 'activate': event_id = request.form.get('event_id') if db.event_exists(event_id): db.reg_set('active_event_id', event_id) flash("Set active event to %r" % event_id) else: flash("Invalid event_id", F_ERROR) return redirect(url_for('events_page')); elif action == 'deactivate': db.reg_set('active_event_id', None) flash("Event de-activated") return redirect(url_for('events_page')); elif action == 'update': event_id = request.form.get('event_id') if not db.event_exists(event_id): flash("Invalid event id", F_ERROR) return redirect(url_for('events_page')) event_data = {} for key in db.table_columns('events'): if key in ['event_id']: continue # ignore elif key in request.form: event_data[key] = request.form.get(key) db.update('events', event_id, **event_data) flash("Event changes saved") return redirect(url_for('events_page')) elif action == 'insert': event_data = {} for key in db.table_columns('events'): if key in ['event_id']: continue # ignore elif key in request.form: event_data[key] = request.form.get(key) event_id = db.insert('events', **event_data) flash("Added new event [%r]" % event_id) return redirect(url_for('events_page')) elif action == 'delete': if request.form.get('confirm_delete'): event_id = request.form.get('event_id') if db.event_exists(event_id): if db.reg_get('active_event_id') == event_id: db.reg_set('active_event_id',None) db.update("events", event_id, deleted=1) # FIXME do we need to propagate this to runs and entries? flash("Event deleted") else: flash("Invalid event_id for delete operation.", F_ERROR) else: flash("Delete ignored, no confirmation", F_WARN) return redirect(url_for('events_page')) elif action == 'recalc': event_id = request.form.get('event_id') if not db.event_exists(event_id): flash("Invalid event id", F_ERROR) return redirect(url_for('events_page')) # flag all entries for this event to be recalculated db.set_event_recalc(event_id) uwsgi.mule_msg('recalc') flash("Event scores recalculating") return redirect(url_for('events_page')) elif action is not None: flash("Invalid form action %r" % action, F_ERROR) return redirect(url_for('events_page')) g.event = get_event(db) g.event_list = db.select_all('events', deleted=0, _order_by='event_id') g.default_date = datetime.date.today().isoformat() g.default_season = datetime.date.today().year g.rule_sets = scoring_rules.get_rule_sets() g.default_rule_set = db.reg_get('default_rule_set') return render_template('admin_events.html')