예제 #1
0
def admin_add_logros_screen():
    """ Screen for players' achievements administration and route for new achievement submision"""

    if request.method == 'POST':
        add_one(PUBLIC_DATABASE, 'logros', request)

    logros = get_items("logros", PUBLIC_DATABASE)
    atletas = get_items("atletas",
                        PUBLIC_DATABASE,
                        fields=['id', 'nombre', 'apellido'])
    options = {
        "atleta": atletas,
        "tipo":
        {element.get('tipo')
         for element in logros if element.get('tipo')},
        "nivel_torneo": {
            element.get('nivel_torneo')
            for element in logros if element.get('nivel_torneo')
        },
        "puesto":
        {element.get('puesto')
         for element in logros if element.get('puesto')},
        "categoria": {
            element.get('categoria')
            for element in logros if element.get('categoria')
        }
    }

    return render_template('admin_add_logros.html', options=options)
예제 #2
0
def atletas():
    """ Renders page about the athletes """
    name = 'atletas'
    _atletas = get_items("atletas", PUBLIC_DATABASE)
    logros = format_logros(
        get_items("logros", PUBLIC_DATABASE, group_by="alumno_id"))

    return render_template(f"{name}.html", active=name, atletas=_atletas, logros=logros)
예제 #3
0
def about():
    """ Renders About Page """
    name = 'about'
    directiva = get_items("miembros_directiva", PUBLIC_DATABASE)
    entrenadores = get_items("entrenadores", PUBLIC_DATABASE)
    hitos = get_items("hitos", PUBLIC_DATABASE, order_by=[
                      ['año', 'ASC'], ['mes', 'ASC']])

    return render_template(f"{name}.html", active=f"{name}", hitos=hitos,
                           directiva=directiva, entrenadores=entrenadores)
def admin_directiva_miembro_screen(_id):
    """ Screen for single directiva member administration """

    _type = 'miembros_directiva'
    if request.method == 'POST':
        updated = update_one(PUBLIC_DATABASE, _type, request, _id)
        if not updated:
            return jsonify({'message': 'Something went wrong'}), 500

    if request.method == 'DELETE':
        deleted = delete_one(PUBLIC_DATABASE, _type, _id)

        if not deleted:
            return jsonify({'message': 'Something went wrong'}), 500

        return jsonify({"redirect_to": "/directiva"}), 200

    try:
        miembro_directiva = next(
            iter(
                get_items(_type,
                          PUBLIC_DATABASE,
                          filters=[{
                              'field': 'id',
                              'values': [_id]
                          }])))
    except Exception:
        return f"Miembro de directiva con id {_id} no encontrado, <a href='/directiva'>regresar</a>"

    return render_template('admin_persona.html',
                           persona=miembro_directiva,
                           type='directiva')
def admin_directiva_miembros_screen():
    """ Screen for directiva members administration """
    miembros = get_items("miembros_directiva", PUBLIC_DATABASE)

    return render_template('admin_personas.html',
                           personas=miembros,
                           type="directiva")
예제 #6
0
def admin_athlete_screen(_id):
    """ Screen for players' administration """
    _type = 'atletas'

    if request.method == 'POST':
        updated = update_one(PUBLIC_DATABASE, _type, request, _id)
        if not updated:
            return jsonify({'message': 'Something went wrong'}), 500

    if request.method == 'DELETE':
        deleted = delete_one(PUBLIC_DATABASE, _type, _id)

        if not deleted:
            return jsonify({'message': 'Something went wrong'}), 500

        return jsonify({"redirect_to": f"/{_type}"}), 200

    try:
        atleta = next(
            iter(
                get_items("atletas",
                          PUBLIC_DATABASE,
                          filters=[{
                              'field': 'id',
                              'values': [_id]
                          }])))
    except Exception:
        return f"Alumnno con id {_id} no encontrado, <a href='/atletas'>regresar</a>"

    return render_template('admin_persona.html', persona=atleta, type=_type)
예제 #7
0
def admin_players_screen():
    """ Screen for players' administration """
    atletas = get_items("atletas", PUBLIC_DATABASE)

    return render_template('admin_personas.html',
                           personas=atletas,
                           type='atletas')
예제 #8
0
def admin_trainers_screen():
    """ Screen for trainers' administration """
    entrenadores = get_items("entrenadores", PUBLIC_DATABASE)

    return render_template('admin_personas.html',
                           personas=entrenadores,
                           type="entrenadores")
예제 #9
0
def send_logros():
    """ Returns json with the achievements by athlete """
    player_id = request.args.get('player_id')

    if not player_id:
        return jsonify({"message": "missing player id"}), 400

    filters = [{"field": "atleta_id", "values": [player_id]}]
    logros = get_items("logros", PUBLIC_DATABASE, filters=filters)
    return jsonify({"message": "success", "items": logros}), 200
예제 #10
0
def atleta_achievement_screen(athlete_id, logro_id):
    """ Screen for player's achievement administration """
    _type = 'logros'

    if request.method == 'POST':
        updated = update_one(PUBLIC_DATABASE, _type, request, logro_id)
        if not updated:
            return jsonify({'message': 'Something went wrong'}), 500

    if request.method == 'DELETE':
        deleted = delete_one(PUBLIC_DATABASE, _type, logro_id)

        if not deleted:
            return jsonify({'message': 'Something went wrong'}), 500

        return jsonify({"redirect_to": f"/atletas/{athlete_id}/logros"}), 200

    try:
        atleta = next(
            iter(
                get_items('atletas',
                          PUBLIC_DATABASE,
                          filters=[{
                              'field': 'id',
                              'values': [athlete_id]
                          }])))
        logro = next(
            iter(
                get_items('logros',
                          PUBLIC_DATABASE,
                          filters=[{
                              'field': 'id',
                              'values': [logro_id]
                          }])))
    except Exception:
        return f"Logro con id {logro_id} no encontrado, <a href='/atletas/{athlete_id}/logros'>regresar</a>"

    return render_template('admin_atleta_logro.html',
                           atleta=atleta,
                           logro=logro)
예제 #11
0
def athletes_achievements(athlete_id):
    """ Get all achievements for an athlete """
    _type = 'logros'

    atleta = next(
        iter(
            get_items('atletas',
                      PUBLIC_DATABASE,
                      filters=[{
                          'field': 'id',
                          'values': [athlete_id]
                      }])))
    achievements = format_logros(
        get_items(_type,
                  PUBLIC_DATABASE,
                  filters=[{
                      'field': 'alumno_id',
                      'values': [athlete_id]
                  }]))

    return render_template('admin_atleta_logros.html',
                           atleta=atleta,
                           logros=achievements)
예제 #12
0
def admin_new_achievement_screen(athlete_id):
    """ Screen to add new milestone """
    _type = 'hito'
    if request.method == 'POST':
        added = add_one(PUBLIC_DATABASE, _type, request)
        if not added:
            return jsonify({'message': 'Something went wrong'}), 500

    atleta = next(
        iter(
            get_items('atletas',
                      PUBLIC_DATABASE,
                      filters=[{
                          'field': 'id',
                          'values': [athlete_id]
                      }])))
    return render_template('admin_atleta_logro.html', atleta=atleta)