Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualDev-FR committed Mar 31, 2023
1 parent 80497a8 commit 571163a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
20 changes: 15 additions & 5 deletions app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
request,
redirect,
flash,
url_for
url_for,
)


Expand Down Expand Up @@ -58,15 +58,25 @@ def book(competition, club):

@app.route('/purchasePlaces', methods=['POST'])
def purchasePlaces():

competition = [c for c in competitions if c['name'] == request.form['competition']][0] # type: ignore
club = [c for c in clubs if c['name'] == request.form['club']][0] # type: ignore

placesRequired = int(request.form['places']) # type: ignore
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
flash('Great-booking complete!')
return render_template('welcome.html', club=club, competitions=competitions)
available_places = competition['numberOfPlaces']

if available_places >= placesRequired and placesRequired <= 12:
competition['numberOfPlaces'] -= placesRequired
flash('Great-booking complete!')
return render_template('welcome.html', club=club, competitions=competitions)

elif available_places < placesRequired:
flash('Not enought places available')

elif placesRequired > 12:
flash("Can't purchase more than 12 places")

# TODO: Add route for points display
return render_template('booking.html', club=club, competition=competition)


@app.route('/logout')
Expand Down
11 changes: 11 additions & 0 deletions app/templates/booking.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
<body>
<h2>{{competition['name']}}</h2>
Places available: {{competition['numberOfPlaces']}}

{% with messages = get_flashed_messages()%}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{message}}</li>
{% endfor %}
</ul>
{% endif%}
{%endwith%}

<form action="/purchasePlaces" method="post">
<input type="hidden" name="club" value="{{club['name']}}">
<input type="hidden" name="competition" value="{{competition['name']}}">
Expand Down
34 changes: 18 additions & 16 deletions clubs.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{"clubs":[
{
"name":"Simply Lift",
"email":"john@simplylift.co",
"points":"13"
},
{
"name":"Iron Temple",
"email": "admin@irontemple.com",
"points":"4"
},
{ "name":"She Lifts",
"email": "kate@shelifts.co.uk",
"points":"12"
}
]}
{
"clubs":[
{
"name":"Simply Lift",
"email":"john@simplylift.co",
"points":13
},
{
"name":"Iron Temple",
"email": "admin@irontemple.com",
"points":4
},
{ "name":"She Lifts",
"email": "kate@shelifts.co.uk",
"points":12
}
]
}
4 changes: 2 additions & 2 deletions competitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
{
"name": "Spring Festival",
"date": "2020-03-27 10:00:00",
"numberOfPlaces": "25"
"numberOfPlaces": 25
},
{
"name": "Fall Classic",
"date": "2020-10-22 13:30:00",
"numberOfPlaces": "13"
"numberOfPlaces": 13
}
]
}

0 comments on commit 571163a

Please sign in to comment.