Skip to content

Commit 49bf283

Browse files
committed
prossime serate
1 parent df06a77 commit 49bf283

File tree

11 files changed

+287
-171
lines changed

11 files changed

+287
-171
lines changed

Flask/Flask05/burlesco70/webapp/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
# Devlog
2+
3+
# 5a settimana
4+
5+
10/11/2020
6+
- base.html - Header Completa Boostrap invece che Navigation bar
7+
- Prossime serate
8+
9+
# 4a settimana
10+
211
03/11/2020
312
- Aggiunto menu corsi (lista/nuovo)
413
- Aggiunta pagina lista corsi
@@ -34,6 +43,7 @@
3443

3544
# TO DO App
3645
- Pagina dettaglio corso: aggiunta / cancellazione serata
46+
- Immagine statica corso
3747
- Gestione serate
3848
- Nella home page fare vedere le 4 "prossime" serate
3949

Flask/Flask05/burlesco70/webapp/data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
##Script to import data into DB with CRUD Operations
1+
## Script to import data into DB with CRUD Operations
22
from project.serate.models import Serata
33
from project.corsi.models import Corso
44
from project.tags.models import Tag
@@ -47,13 +47,13 @@
4747
"Andrea Guzzo",
4848
"Intermedio",
4949
"Corso in cinque serate del microframework Flask",
50-
"immagine_flask"
50+
"flask-icon.png"
5151
)
5252
corsoFlask.tags = [t1, t2, t4, t5]
5353

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

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
1 Byte
Binary file not shown.
474 Bytes
Binary file not shown.

Flask/Flask05/burlesco70/webapp/project/serate/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from project import db
2-
#from project.corsi.models import Corso
32

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

76
__tablename__ = "serata"
87

9-
__table_args__ = (db.UniqueConstraint("id", "data", name="contraint_serata"),)
8+
__table_args__ = (db.UniqueConstraint("id", "data", name="constraint_serata"),)
109

1110
id = db.Column(db.Integer(), primary_key=True)
1211
nome = db.Column(db.String(255), nullable=False)

Flask/Flask05/burlesco70/webapp/project/serate/routes.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,36 @@
88
session,
99
current_app,
1010
)
11-
from project.corsi.forms import CorsiForm, write_to_disk, SerataForm
11+
#from project.serate.forms import SerataForm
1212
from project.serate.models import Serata
1313
from project.corsi.models import Corso
1414
from project import db
1515

1616
from sqlalchemy import desc,asc
1717

18+
from datetime import datetime
19+
1820
# Define blueprint
1921
serate_blueprint = Blueprint(
2022
"serate",
2123
__name__,
2224
template_folder="templates",
2325
static_folder='../static'
24-
)
26+
)
27+
28+
'''
29+
Lista delle serate in ordine di data
30+
'''
31+
@serate_blueprint.route("/prossime", methods=["GET"])
32+
def prossime():
33+
# Filtro data futura, ordinamento per data
34+
lista_serate = Serata.query.filter(Serata.data > datetime.now()).order_by(asc(Serata.data)).all()
35+
# Creo una lista parallela dei corsi collegati alle serate
36+
lista_corsi = [ Corso.query.filter_by(id=s.corso_id).first() for s in lista_serate ]
37+
# Nel template non è possibile iterare su due liste, quindi zippo le due liste e le passo
38+
zipped_data = zip(lista_serate, lista_corsi)
39+
return render_template(
40+
'serate_prossime.html',
41+
zipped_data=zipped_data
42+
)
43+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{% extends "base.html" %}
2+
{% block content %}
3+
4+
<div class="container text-center">
5+
<br>
6+
<h1>Le prossime serate</h1>
7+
<br>
8+
</div>
9+
10+
<table class="table table-striped">
11+
<thead>
12+
<tr>
13+
<th scope="col">Data</th>
14+
<th scope="col">Nome - Descrizione</th>
15+
<th scope="col">Links partecipazione</th>
16+
<th scope="col">Corso</th>
17+
</tr>
18+
</thead>
19+
{% for s,c in zipped_data %}
20+
<tbody>
21+
<tr>
22+
<th scope="row">{{ s.data.strftime('%d/%m/%Y') }}</th>
23+
<td>{{ s.nome }} - {{ s.descrizione }}</td>
24+
<td>
25+
{% if s.link_partecipazione %}
26+
<a href="{{ s.link_partecipazione }}">{{ s.link_partecipazione }}</a>
27+
{% else %}
28+
Non disponibile
29+
{% endif %}
30+
</td>
31+
<td> {{ c.nome }} </td>
32+
</tr>
33+
{% endfor -%}
34+
</tbody>
35+
</table>
36+
37+
{% endblock %}

0 commit comments

Comments
 (0)