Skip to content

Commit

Permalink
prossime serate
Browse files Browse the repository at this point in the history
  • Loading branch information
Burlesco70 committed Nov 10, 2020
1 parent df06a77 commit 49bf283
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 171 deletions.
10 changes: 10 additions & 0 deletions Flask/Flask05/burlesco70/webapp/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Devlog

# 5a settimana

10/11/2020
- base.html - Header Completa Boostrap invece che Navigation bar
- Prossime serate

# 4a settimana

03/11/2020
- Aggiunto menu corsi (lista/nuovo)
- Aggiunta pagina lista corsi
Expand Down Expand Up @@ -34,6 +43,7 @@

# TO DO App
- Pagina dettaglio corso: aggiunta / cancellazione serata
- Immagine statica corso
- Gestione serate
- Nella home page fare vedere le 4 "prossime" serate

Expand Down
6 changes: 3 additions & 3 deletions Flask/Flask05/burlesco70/webapp/data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
##Script to import data into DB with CRUD Operations
## Script to import data into DB with CRUD Operations
from project.serate.models import Serata
from project.corsi.models import Corso
from project.tags.models import Tag
Expand Down Expand Up @@ -47,13 +47,13 @@
"Andrea Guzzo",
"Intermedio",
"Corso in cinque serate del microframework Flask",
"immagine_flask"
"flask-icon.png"
)
corsoFlask.tags = [t1, t2, t4, t5]

# Relazione n:n TAG - CORSO
corsoPygame = Corso(
"Pygame", "Mario Nardi", "Principiante", "Introduzione a Pygame"
"Pygame", "Mario Nardi", "Principiante", "Introduzione a Pygame", "pygame-icon.png"
)
corsoPygame.tags = [t1, t3, t6]

Expand Down
Binary file not shown.
Binary file modified Flask/Flask05/burlesco70/webapp/project/data.sqlite
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 1 addition & 2 deletions Flask/Flask05/burlesco70/webapp/project/serate/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from project import db
#from project.corsi.models import Corso

# Tabella di relazione 1 Corso : N Serate
class Serata(db.Model):

__tablename__ = "serata"

__table_args__ = (db.UniqueConstraint("id", "data", name="contraint_serata"),)
__table_args__ = (db.UniqueConstraint("id", "data", name="constraint_serata"),)

id = db.Column(db.Integer(), primary_key=True)
nome = db.Column(db.String(255), nullable=False)
Expand Down
23 changes: 21 additions & 2 deletions Flask/Flask05/burlesco70/webapp/project/serate/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,36 @@
session,
current_app,
)
from project.corsi.forms import CorsiForm, write_to_disk, SerataForm
#from project.serate.forms import SerataForm
from project.serate.models import Serata
from project.corsi.models import Corso
from project import db

from sqlalchemy import desc,asc

from datetime import datetime

# Define blueprint
serate_blueprint = Blueprint(
"serate",
__name__,
template_folder="templates",
static_folder='../static'
)
)

'''
Lista delle serate in ordine di data
'''
@serate_blueprint.route("/prossime", methods=["GET"])
def prossime():
# Filtro data futura, ordinamento per data
lista_serate = Serata.query.filter(Serata.data > datetime.now()).order_by(asc(Serata.data)).all()
# Creo una lista parallela dei corsi collegati alle serate
lista_corsi = [ Corso.query.filter_by(id=s.corso_id).first() for s in lista_serate ]
# Nel template non è possibile iterare su due liste, quindi zippo le due liste e le passo
zipped_data = zip(lista_serate, lista_corsi)
return render_template(
'serate_prossime.html',
zipped_data=zipped_data
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends "base.html" %}
{% block content %}

<div class="container text-center">
<br>
<h1>Le prossime serate</h1>
<br>
</div>

<table class="table table-striped">
<thead>
<tr>
<th scope="col">Data</th>
<th scope="col">Nome - Descrizione</th>
<th scope="col">Links partecipazione</th>
<th scope="col">Corso</th>
</tr>
</thead>
{% for s,c in zipped_data %}
<tbody>
<tr>
<th scope="row">{{ s.data.strftime('%d/%m/%Y') }}</th>
<td>{{ s.nome }} - {{ s.descrizione }}</td>
<td>
{% if s.link_partecipazione %}
<a href="{{ s.link_partecipazione }}">{{ s.link_partecipazione }}</a>
{% else %}
Non disponibile
{% endif %}
</td>
<td> {{ c.nome }} </td>
</tr>
{% endfor -%}
</tbody>
</table>

{% endblock %}
Loading

0 comments on commit 49bf283

Please sign in to comment.