Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Navi-27/Proyecto-UPC/llms.txt

Use this file to discover all available pages before exploring further.

My Pokédex (GET /mi-pokedex) gives every registered user a personal, automatically maintained catalogue of every Pokémon they have ever viewed. There is no manual catch mechanic — the moment you visit a Pokémon’s detail page while logged in, that Pokémon is silently added to your history. The page displays your entire viewing history as a card grid, sorted with the most recently seen Pokémon at the top.

Authentication Requirement

This page is protected. If no active session is present (i.e. usuario_id is not in the Flask session), the route immediately redirects to /login:
# application.py
@application.route("/mi-pokedex")
def mi_pokedex():
    if "usuario_id" not in session:
        return redirect(url_for("login"))
    vistos = PokedexUsuario.obtener_vistos(session["usuario_id"])
    return render_template("mi-pokedex.html", vistos=vistos)

History Entries

Each entry in your Pokédex history contains the following fields, sourced directly from the pokedex_usuario table:
FieldDescription
pokemon_idNational Pokédex number, used to construct the sprite URL
pokemon_nombrePokémon name slug (e.g. charizard), used to link back to the detail page
fecha_vistoISO 8601 timestamp of when the Pokémon was first viewed (e.g. 2024-03-15 10:42:07)
The template renders the date portion only (fecha_visto[:10]) beneath each card for a clean display, while the full timestamp drives the sort order server-side.

How Viewing Is Recorded

Tracking happens automatically inside the GET /pokemon/<nombre> route. Every time a logged-in user opens a detail page, the handler calls:
PokedexUsuario.registrar_visto(
    session["usuario_id"],
    pokemon.id,
    pokemon.nombre,
)
Internally, registrar_visto() uses INSERT OR IGNORE against a UNIQUE constraint on (usuario_id, pokemon_id):
# models/pokedex_usuario.py
@staticmethod
def registrar_visto(usuario_id, pokemon_id, pokemon_nombre):
    conn = get_connection()
    conn.execute('''
        INSERT OR IGNORE INTO pokedex_usuario
        (usuario_id, pokemon_id, pokemon_nombre)
        VALUES (?,?,?)
    ''', (usuario_id, pokemon_id, pokemon_nombre))
    conn.commit()
    conn.close()
Because of the UNIQUE constraint on (usuario_id, pokemon_id), visiting the same Pokémon ten times still results in exactly one row per Pokémon — the fecha_visto timestamp is set on first insert and never updated. The total number of entries on your My Pokédex page equals the number of distinct Pokémon you have visited, not your total page view count.

Retrieving Your History

When the /mi-pokedex page loads, PokedexUsuario.obtener_vistos(usuario_id) fetches all rows for the current user, ordered by most recent visit:
# models/pokedex_usuario.py
@staticmethod
def obtener_vistos(usuario_id):
    conn = get_connection()
    rows = conn.execute('''
        SELECT * FROM pokedex_usuario WHERE usuario_id = ? ORDER BY fecha_visto DESC
    ''', (usuario_id,)).fetchall()
    conn.close()
    return rows
The result is passed directly to the mi-pokedex.html template as vistos. The template header shows your total count ({{ vistos | length }} Pokémon), and the card grid links each entry back to /pokemon/<pokemon_nombre> so you can revisit any Pokémon in one click.
Visit as many Pokémon detail pages as you want to grow your Pokédex — no action required beyond browsing. The easiest strategy is to use the type filters on the index page to work through one type at a time, clicking each card in turn. Your history fills up automatically as you go.

Build docs developers (and LLMs) love