Skip to content

Feature/ Add public points display on index page and welcome page #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ lib
.Python
tests/
.envrc
__pycache__
__pycache__
pyvenv.cfg
6 changes: 3 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def loadCompetitions():

@app.route('/')
def index():
return render_template('index.html')
return render_template('index.html', clubs=clubs)

@app.route('/showSummary',methods=['POST'])
def showSummary():
club = [club for club in clubs if club['email'] == request.form['email']][0]
return render_template('welcome.html',club=club,competitions=competitions)
return render_template('welcome.html',club=club,competitions=competitions, clubs=clubs)


@app.route('/book/<competition>/<club>')
Expand Down Expand Up @@ -56,4 +56,4 @@ def purchasePlaces():

@app.route('/logout')
def logout():
return redirect(url_for('index'))
return redirect(url_for('index'))
14 changes: 14 additions & 0 deletions templates/_points_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- templates/_points_table.html -->
<h2>Clubs Points Board</h2>
<table border="1">
<tr>
<th>Club Name</th>
<th>Points</th>
</tr>
{% for club in clubs %}
<tr>
<td>{{ club['name'] }}</td>
<td>{{ club['points'] }}</td>
</tr>
{% endfor %}
</table>
4 changes: 3 additions & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ <h1>Welcome to the GUDLFT Registration Portal!</h1>
<input type="email" name="email" id=""/>
<button type="submit">Enter</button>
</form>

{% include '_points_table.html' %}
</body>
</html>
</html>
57 changes: 30 additions & 27 deletions templates/welcome.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Summary | GUDLFT Registration</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Summary | GUDLFT Registration</title>
</head>
<body>
<h2>Welcome, {{club['email']}} </h2><a href="{{url_for('logout')}}">Logout</a>
<h2>Welcome, {{club['email']}}</h2>
<a href="{{url_for('logout')}}">Logout</a>

{% with messages = get_flashed_messages()%}
{% include '_points_table.html' %}

{% with messages = get_flashed_messages() %}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{message}}</li>
{% endfor %}
</ul>
{% endif%}
Points available: {{club['points']}}
<h3>Competitions:</h3>
<ul>
{% for comp in competitions%}
<li>
{{comp['name']}}<br />
Date: {{comp['date']}}</br>
Number of Places: {{comp['numberOfPlaces']}}
{%if comp['numberOfPlaces']|int >0%}
<a href="{{ url_for('book',competition=comp['name'],club=club['name']) }}">Book Places</a>
{%endif%}
</li>
<hr />
<ul>
{% for message in messages %}
<li>{{message}}</li>
{% endfor %}
</ul>
{%endwith%}
</ul>
{% endif %}
{% endwith %}

Points available: {{club['points']}}
<h3>Competitions:</h3>
<ul>
{% for comp in competitions %}
<li>
{{comp['name']}}<br />
Date: {{comp['date']}}</br>
Number of Places: {{comp['numberOfPlaces']}}
{% if comp['numberOfPlaces']|int > 0 %}
<a href="{{ url_for('book', competition=comp['name'], club=club['name']) }}">Book Places</a>
{% endif %}
</li>
<hr />
{% endfor %}
</ul>
</body>
</html>
</html>
37 changes: 37 additions & 0 deletions tests/unit/test_points_display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys
import os
import pytest
sys.path.insert(
0, os.path.abspath(
os.path.join(os.path.dirname(__file__), '../../')
)
)

from server import app, clubs, competitions # noqa


@pytest.fixture
def client():
app.config['TESTING'] = True
with app.test_client() as client:
yield client


def test_points_display_on_index(client):
response = client.get('/')
assert response.status_code == 200

for club in clubs:
assert bytes(club['name'], 'utf-8') in response.data
assert bytes(club['points'], 'utf-8') in response.data


def test_points_display_after_login(client):
response = client.post(
'/showSummary', data={'email': 'john@simplylift.co'}
)
assert response.status_code == 200

for club in clubs:
assert bytes(club['name'], 'utf-8') in response.data
assert bytes(club['points'], 'utf-8') in response.data