Beispiel #1
0
def person_add(person_id=None):
    if request.method == "GET":
        if person_id:
            person = mg.Person(person_id=person_id)
            mf = person.get_mf_value()
            if person.get_category():
                cat_nid = person.get_category()["nid"]
                form = PersonAdd(mf=mf, category=cat_nid)
            else:
                form = PersonAdd(mf=mf)
            form.name.data = person.get_name()
        else:
            form = PersonAdd()
        form.category.choices = mg.get_category_list()
        persons = mg.person_list()
        return render_template('person_add.html', form=form, persons=persons)
    else:
        # request.method == "POST":
        form = PersonAdd()
        # if form.validate_on_submit(): Doesn't work with SelectField
        person_dict = dict(name=form.name.data,
                           mf=form.mf.data,
                           category=form.category.data)
        if person_id:
            # This is from person edit function
            # current_app.logger.debug("Person Dictionary: {person_dict}".format(person_dict=person_dict))
            person = mg.Person(person_id=person_id)
            person.edit(**person_dict)
        else:
            person = mg.Person()
            person.add(**person_dict)
        return redirect(url_for('main.person_add'))
Beispiel #2
0
def results(mf, cat, person_id=None):
    result_set = mg.results_for_category(mf=mf, cat=cat)
    cat_name = mg.get_category_name(cat)
    param_dict = dict(result_set=result_set, cat_nid=cat, cat=cat_name, mf=mf)
    if person_id:
        races = mg.races4person(person_id)
        person = mg.Person(person_id)
        person_dict = person.get_dict()
        param_dict["races"] = races
        param_dict["person"] = person_dict
    return render_template("result_list.html", **param_dict)
Beispiel #3
0
def person_delete(pers_id):
    """
    This method will get an id for a participant that can be removed. Checks have been done to make sure that there
    are no more connections (relations) with this participant.

    :param pers_id: NID of the person to be removed

    :return: person_list
    """
    person = mg.Person(pers_id)
    if person.active():
        current_app.logger.warning(
            "Request to delete id {pers_id} but person participates in races".
            format(pers_id=pers_id))
    else:
        mg.remove_node_force(pers_id)
    return redirect(url_for('main.person_list'))
Beispiel #4
0
def person_summary(pers_id):
    """
    This method provides all information about a single person. In case this is an 'isolated' person
    (this means without link to races), then a 'Verwijder' (delete) button will be shown.
    :param pers_id: ID of the Participant for which overview info is required.
    :return:
    """
    part = mg.Person(pers_id)
    person_dict = part.get_dict()
    races = mg.races4person(pers_id)
    # Don't count on len(races), since this is competition races. Remove person only if not used across all
    # competitions.
    persons = mg.person_list()
    return render_template('person_races_list.html',
                           person=person_dict,
                           races=races,
                           persons=persons)
Beispiel #5
0
def participant_edit(part_id):
    """
    This method allows to edit a participant in the race. It is similar to the participant_add, but with sufficient
    differences to justify a separate method.
    :param part_id: NID of the participant. This is sufficient to find Person and Race objects.
    :return:
    """
    part = mg.Participant(part_id=part_id)
    person_nid = part.get_person_nid()
    person = mg.Person(person_id=person_nid)
    person_dict = person.get_dict()
    race_id = part.get_race_nid()
    race = mg.Race(race_id=race_id)
    race_label = race.get_label()
    if request.method == "POST":
        # Call form to get input values
        form = ParticipantEdit()
        # Collect properties for this participant
        props = {}
        for prop in part_config_props:
            try:
                props[prop] = form.data[prop]
            except KeyError:
                pass
        part.set_props(**props)
        return redirect(url_for('main.participant_add', race_id=race_id))
    else:
        # Get method, initialize page.
        org_id = mg.get_org_id(race_id)
        # Initialize Form, populate with keyword arguments
        # (http://wtforms.readthedocs.io/en/latest/crash_course.html#how-forms-get-data)
        part_props = part.get_props()
        form = ParticipantEdit(**part_props)
        finishers = mg.participant_seq_list(race_id)
        # There must be finishers, since I can update one of them
        return render_template('participant_edit.html',
                               form=form,
                               race_id=race_id,
                               finishers=finishers,
                               race_label=race_label,
                               org_id=org_id,
                               person=person_dict)