Añadida restauración de feeds desde CSV, mejoras en UI, y campo descripción en feeds

This commit is contained in:
jlimolina 2025-05-27 12:36:35 +02:00
parent d7cabbb2c6
commit 4ca48836c9
6 changed files with 298 additions and 182 deletions

View file

@ -1,10 +1,95 @@
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<title>Gestión de Feeds RSS</title>
{% extends "base.html" %}
{% block title %}Gestión de Feeds RSS{% endblock %}
{% block content %}
<h1>Gestión de Feeds RSS</h1>
<a href="/" class="top-link">← Volver a últimas noticias</a>
<div class="card">
<h2>Añadir un nuevo feed</h2>
<form action="/add" method="post" autocomplete="off">
<label for="nombre">Nombre del feed</label>
<input id="nombre" name="nombre" placeholder="Nombre del feed" required>
<label for="descripcion">Descripción</label>
<textarea id="descripcion" name="descripcion" placeholder="Breve descripción del feed" rows="2"></textarea>
<label for="url">URL del RSS</label>
<input id="url" name="url" placeholder="URL del RSS" required>
<label for="categoria_id">Categoría</label>
<select id="categoria_id" name="categoria_id" required>
<option value="">— Elige categoría —</option>
{% for cid, cnom in categorias %}
<option value="{{ cid }}">{{ cnom }}</option>
{% endfor %}
</select>
<label for="continente_id">Continente</label>
<select name="continente_id" id="continente_id" onchange="filtrarPaisesPorContinente()">
<option value="">— Elige continente —</option>
{% for coid, conom in continentes %}
<option value="{{ coid }}">{{ conom }}</option>
{% endfor %}
</select>
<label for="pais_id">País</label>
<select name="pais_id" id="pais_id">
<option value="">— N/A —</option>
{% for pid, pnom, contid in paises %}
<option value="{{ pid }}">{{ pnom }}</option>
{% endfor %}
</select>
<button class="btn" type="submit">Añadir</button>
<!-- Datos en JSON para el filtro dinámico de países -->
<script type="application/json" id="paises-data">{{ paises|tojson }}</script>
</form>
</div>
<div class="card">
<h2>Lista de Feeds</h2>
<a href="/backup_feeds" target="_blank" class="btn">⬇️ Descargar backup de feeds (CSV)</a>
<a href="/restore_feeds" class="btn" style="margin-left:10px;">🔄 Restaurar feeds desde backup</a>
<table>
<thead>
<tr>
<th>Nombre y descripción</th>
<th>URL</th>
<th>Categoría</th>
<th>País</th>
<th>Activo</th>
<th>Acciones</th>
</tr>
</thead>
<tbody>
{% for id, nombre, descripcion, url, categoria_id, pais_id, activo, cat_nom, pais_nom in feeds %}
<tr>
<td>
<strong>{{ nombre }}</strong>
{% if descripcion %}
<div style="font-size:0.95em; color:#64748b;">{{ descripcion }}</div>
{% endif %}
</td>
<td><a href="{{ url }}" target="_blank">{{ url }}</a></td>
<td>{{ cat_nom or 'N/A' }}</td>
<td>{{ pais_nom or 'N/A' }}</td>
<td>{{ 'Sí' if activo else 'No' }}</td>
<td class="actions">
<a href="/edit/{{ id }}">Editar</a> |
<a href="/delete/{{ id }}" onclick="return confirm('¿Seguro que quieres eliminar este feed?');">Eliminar</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="6">No hay feeds aún.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<a href="/" class="top-link">← Volver a últimas noticias</a>
<script>
// Script para filtrar países según continente elegido
function filtrarPaisesPorContinente() {
const continenteId = document.getElementById('continente_id').value;
const paises = JSON.parse(document.getElementById('paises-data').textContent);
@ -25,63 +110,5 @@
});
}
</script>
</head>
<body>
<h1>Gestión de Feeds RSS</h1>
<p><a href="/">← Volver a últimas noticias</a></p>
<!-- Enlace de backup de feeds -->
<p>
<a href="/backup_feeds" target="_blank">⬇️ Descargar backup de feeds (CSV)</a>
</p>
<h2>Añadir un nuevo feed</h2>
<form action="/add" method="post">
<input name="nombre" placeholder="Nombre del feed" required>
<input name="url" placeholder="URL del RSS" required>
<select name="categoria_id" required>
<option value="">— Elige categoría —</option>
{% for cid, cnom in categorias %}
<option value="{{ cid }}">{{ cnom }}</option>
{% endfor %}
</select>
<select name="continente_id" id="continente_id" onchange="filtrarPaisesPorContinente()">
<option value="">— Elige continente —</option>
{% for coid, conom in continentes %}
<option value="{{ coid }}">{{ conom }}</option>
{% endfor %}
</select>
<select name="pais_id" id="pais_id">
<option value="">— N/A —</option>
{% for pid, pnom, contid in paises %}
<option value="{{ pid }}">{{ pnom }}</option>
{% endfor %}
</select>
<button type="submit">Añadir</button>
<!-- Datos en JSON para el filtro dinámico de países -->
<script type="application/json" id="paises-data">{{ paises|tojson }}</script>
</form>
<h2>Lista de Feeds</h2>
<ul>
{% for id, nombre, url, categoria_id, pais_id, activo, cat_nom, pais_nom in feeds %}
<li>
<strong>{{ nombre }}</strong>
(<a href="{{ url }}" target="_blank">{{ url }}</a>)
— Categoría: {{ cat_nom or 'N/A' }}
— País: {{ pais_nom or 'N/A' }}
— Activo: {{ 'Sí' if activo else 'No' }}
<!-- Enlace de edición de feed -->
| <a href="/edit/{{ id }}">Editar</a>
<!-- Enlace para eliminar feed con confirmación -->
| <a href="/delete/{{ id }}" onclick="return confirm('¿Seguro que quieres eliminar este feed?');">Eliminar</a>
</li>
{% else %}
<li>No hay feeds aún.</li>
{% endfor %}
</ul>
<p><a href="/">← Volver a últimas noticias</a></p>
</body>
</html>
{% endblock %}