diff --git a/src/templates/index.html b/src/templates/index.html
index 527dac8..e742deb 100644
--- a/src/templates/index.html
+++ b/src/templates/index.html
@@ -41,25 +41,30 @@
«
{% else %}
-
+
«
{% endif %}
{# Things are kinda messy here #}
{% for i in range(pagination[2] - pagination[3] - 1, pagination[2] - 1) %}
- {{ i + 1 }}
+ {{ i + 1 }}
{% endfor %}
- {{ pagination[2] }}
+ {{ pagination[2] }}
{% for i in range(pagination[2], pagination[2] + pagination[4]) %}
- {{ i + 1 }}
+ {{ i + 1 }}
{% endfor %}
{% if pagination[4] <= 0 %}
»
{% else %}
-
+
»
{% endif %}
diff --git a/src/templates/root.html b/src/templates/root.html
index 34ad735..98e6e96 100644
--- a/src/templates/root.html
+++ b/src/templates/root.html
@@ -28,9 +28,15 @@
diff --git a/src/views/scoreboard.py b/src/views/scoreboard.py
index 6583594..a09f3a9 100644
--- a/src/views/scoreboard.py
+++ b/src/views/scoreboard.py
@@ -85,7 +85,7 @@ def result(id):
flask.abort(404)
-@scoreboard.route("/")
+@scoreboard.route("/", methods=['GET', 'POST'])
def index():
"""
This method returns the index page.
@@ -93,15 +93,24 @@ def index():
results_per_page = flask.current_app.config["MAX_RESULTS_PER_PAGE"]
max_pages = flask.current_app.config["MAX_PAGES"]
- # We're extracting the page argument from the url, if it's not present we set page_no to zero.
+ # We're extracting the page argument from the url, if it's not present we set page_no to zero.
page_no = utilities.to_zero_count(flask.request.args.get('page'))
+ searched_name = flask.request.args.get('result_name')
- # Compute the offset and the available pages
- results_length = Result.query.count()
+ # The filters dictionary is used to filter the data
+ filters = {}
+ if searched_name is not None and searched_name is not '':
+ filters['name'] = searched_name
+
+ # Computing the offset for the results
offset = page_no * results_per_page
- available_pages = math.floor((results_length - offset) / results_per_page)
- results = Result.query.order_by(Result.score.desc()).offset(offset).limit(results_per_page)
+ # We're getting the results length and data
+ results_length = Result.query.filter_by(**filters).count()
+ results = Result.query.filter_by(**filters).order_by(Result.score.desc()).offset(offset).limit(results_per_page)
+
+ # This is used by the view to display available pages, if any.
+ available_pages = math.floor((results_length - offset) / results_per_page)
# Compute the available pages to the left
pages_left = min(page_no, max_pages)
diff --git a/test/test_scoreboard.py b/test/test_scoreboard.py
index 57e8c16..3b2c559 100644
--- a/test/test_scoreboard.py
+++ b/test/test_scoreboard.py
@@ -67,6 +67,17 @@ class ScoreboardTestCase(unittest.TestCase):
self.assertTrue("true" in response.get_data(as_text=True))
self.assertEqual(response.status_code, 201)
+ def test_search(self):
+ e = Result(name="Test", cpu="TestCPU", gpu="TestGPU", log="TestLOG", score=11)
+ response = self.client.post('/', data={"result_name": "test"})
+ self.assertTrue("No results found" in response.get_data(as_text=True))
+
+ db.session.add(e)
+ db.session.commit()
+
+ response = self.client.post('/', data={"result_name": "test"})
+ self.assertFalse("No results found" in response.get_data(as_text=True))
+
def test_get_upload(self):
response = self.client.get('/upload')
self.assertEqual(response.status_code, 200)