Add missing model files: post.py and category.py

This commit is contained in:
2025-09-21 21:18:54 +02:00
parent 8b7ab9d66e
commit 7ec30b8d5e
5 changed files with 606 additions and 0 deletions

View File

@@ -0,0 +1,149 @@
{% extends "dashboard/base.html" %}
{% block page_title %}
{% if action == 'create' %}Nuovo Progetto{% else %}Modifica Progetto{% endif %}
{% endblock %}
{% block content %}
<div class="row">
<div class="col-lg-8">
<div class="card">
<div class="card-body">
<form method="POST">
<div class="mb-3">
<label for="title" class="form-label">Titolo *</label>
<input type="text" class="form-control" id="title" name="title"
value="{{ project.title if project else '' }}" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Descrizione Breve</label>
<textarea class="form-control" id="description" name="description" rows="3"
maxlength="1000">{{ project.description if project else '' }}</textarea>
<div class="form-text">Massimo 1000 caratteri</div>
</div>
<div class="mb-3">
<label for="content" class="form-label">Contenuto Completo</label>
<textarea class="form-control" id="content" name="content" rows="10">{{ project.content if project else '' }}</textarea>
<div class="form-text">Supporta HTML di base</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="github_url" class="form-label">URL GitHub</label>
<input type="url" class="form-control" id="github_url" name="github_url"
value="{{ project.github_url if project else '' }}"
placeholder="https://github.com/username/repo">
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="demo_url" class="form-label">URL Demo/Live</label>
<input type="url" class="form-control" id="demo_url" name="demo_url"
value="{{ project.demo_url if project else '' }}"
placeholder="https://example.com">
</div>
</div>
</div>
<div class="mb-3">
<label for="image_url" class="form-label">URL Immagine</label>
<input type="url" class="form-control" id="image_url" name="image_url"
value="{{ project.image_url if project else '' }}"
placeholder="https://example.com/image.jpg">
</div>
<div class="mb-3">
<label for="technologies" class="form-label">Tecnologie</label>
<div class="row">
{% set common_techs = ['Python', 'JavaScript', 'HTML', 'CSS', 'React', 'Vue.js', 'Node.js', 'MySQL', 'PostgreSQL', 'MongoDB', 'Docker', 'Git', 'Bootstrap', 'jQuery'] %}
{% for tech in common_techs %}
<div class="col-md-3 col-sm-4 col-6">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="technologies"
value="{{ tech }}" id="tech_{{ loop.index }}"
{% if project and tech in project.technologies %}checked{% endif %}>
<label class="form-check-label" for="tech_{{ loop.index }}">
{{ tech }}
</label>
</div>
</div>
{% endfor %}
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="category_id" class="form-label">Categoria</label>
<select class="form-select" id="category_id" name="category_id">
<option value="">Seleziona categoria</option>
{% for category in categories %}
<option value="{{ category.id }}"
{% if project and project.category_id == category.id %}selected{% endif %}>
{{ category.name }}
</option>
{% endfor %}
</select>
</div>
</div>
</div>
<div class="mb-3">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="is_featured" name="is_featured" value="1"
{% if project and project.is_featured %}checked{% endif %}>
<label class="form-check-label" for="is_featured">
Progetto in evidenza
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="is_published" name="is_published" value="1"
{% if not project or project.is_published %}checked{% endif %}>
<label class="form-check-label" for="is_published">
Pubblica progetto
</label>
</div>
</div>
<div class="d-flex justify-content-between">
<a href="{{ url_for('dashboard.projects') }}" class="btn btn-secondary">
<i class="bi bi-arrow-left"></i> Annulla
</a>
<button type="submit" class="btn btn-primary">
<i class="bi bi-check"></i>
{% if action == 'create' %}Crea Progetto{% else %}Aggiorna Progetto{% endif %}
</button>
</div>
</form>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="card">
<div class="card-body">
<h6 class="card-title">Suggerimenti</h6>
<ul class="list-unstyled small">
<li><i class="bi bi-lightbulb text-warning"></i> Un titolo chiaro e descrittivo attira più attenzione</li>
<li><i class="bi bi-lightbulb text-warning"></i> La descrizione breve appare nelle anteprime</li>
<li><i class="bi bi-lightbulb text-warning"></i> Usa il contenuto completo per dettagli tecnici</li>
<li><i class="bi bi-lightbulb text-warning"></i> I progetti "featured" appaiono in homepage</li>
</ul>
</div>
</div>
{% if project and project.image_url %}
<div class="card mt-3">
<div class="card-body">
<h6 class="card-title">Anteprima Immagine</h6>
<img src="{{ project.image_url }}" class="img-fluid rounded" alt="Project preview">
</div>
</div>
{% endif %}
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,117 @@
{% extends "dashboard/base.html" %}
{% block page_title %}Gestione Progetti{% endblock %}
{% block page_actions %}
<a href="{{ url_for('dashboard.new_project') }}" class="btn btn-primary">
<i class="bi bi-plus"></i> Nuovo Progetto
</a>
{% endblock %}
{% block content %}
<div class="card">
<div class="card-body">
{% if projects %}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Titolo</th>
<th>Stato</th>
<th>Featured</th>
<th>Creato</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
{% for project in projects %}
<tr>
<td>
<strong>{{ project.title }}</strong>
{% if project.description %}
<br><small class="text-muted">{{ project.description[:100] }}...</small>
{% endif %}
</td>
<td>
{% if project.is_published %}
<span class="badge bg-success">Pubblicato</span>
{% else %}
<span class="badge bg-secondary">Bozza</span>
{% endif %}
</td>
<td>
{% if project.is_featured %}
<span class="badge bg-warning">Featured</span>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>{{ project.created_at.strftime('%d/%m/%Y') if project.created_at else 'N/D' }}</td>
<td>
<div class="btn-group" role="group">
<a href="{{ url_for('dashboard.edit_project', project_id=project.id) }}"
class="btn btn-sm btn-outline-primary" title="Modifica">
<i class="bi bi-pencil"></i>
</a>
<form method="POST" action="{{ url_for('dashboard.delete_project', project_id=project.id) }}"
style="display: inline;"
onsubmit="return confirm('Sei sicuro di voler eliminare questo progetto?')">
<button type="submit" class="btn btn-sm btn-outline-danger" title="Elimina">
<i class="bi bi-trash"></i>
</button>
</form>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Pagination -->
{% if pagination.total_pages > 1 %}
<nav aria-label="Pagination">
<ul class="pagination justify-content-center">
{% if pagination.has_prev %}
<li class="page-item">
<a class="page-link" href="?page={{ pagination.prev_page }}">Precedente</a>
</li>
{% endif %}
{% for page_num in range(1, pagination.total_pages + 1) %}
{% if page_num == pagination.page %}
<li class="page-item active">
<span class="page-link">{{ page_num }}</span>
</li>
{% elif page_num <= 3 or page_num > pagination.total_pages - 3 or (page_num >= pagination.page - 1 and page_num <= pagination.page + 1) %}
<li class="page-item">
<a class="page-link" href="?page={{ page_num }}">{{ page_num }}</a>
</li>
{% elif page_num == 4 or page_num == pagination.total_pages - 3 %}
<li class="page-item disabled">
<span class="page-link">...</span>
</li>
{% endif %}
{% endfor %}
{% if pagination.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{ pagination.next_page }}">Successivo</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}
{% else %}
<div class="text-center py-5">
<i class="bi bi-folder2-open display-1 text-muted"></i>
<h4 class="mt-3">Nessun progetto ancora</h4>
<p class="text-muted">Inizia creando il tuo primo progetto</p>
<a href="{{ url_for('dashboard.new_project') }}" class="btn btn-primary">
<i class="bi bi-plus"></i> Crea Primo Progetto
</a>
</div>
{% endif %}
</div>
</div>
{% endblock %}