diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-06-15 13:03:55 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-06-15 13:03:55 +0100 |
commit | 43a50c8b7da0714e52c2a0506eece440a7cd3930 (patch) | |
tree | eb94bef89146c7bd3ec064e6edb658563a40ccad | |
parent | f96155fc082e614dc1c9db6a9e429649f8b63e49 (diff) | |
download | morph-cache-server-43a50c8b7da0714e52c2a0506eece440a7cd3930.tar.gz |
Add simple paging to artifacts page
There must be a library for this.. but I don't know of it.
-rw-r--r-- | morphcacheserver/artifact_database.py | 18 | ||||
-rw-r--r-- | morphcacheserver/frontend.py | 22 |
2 files changed, 38 insertions, 2 deletions
diff --git a/morphcacheserver/artifact_database.py b/morphcacheserver/artifact_database.py index 9bc35a9..b9550a1 100644 --- a/morphcacheserver/artifact_database.py +++ b/morphcacheserver/artifact_database.py @@ -141,6 +141,24 @@ class ArtifactDatabase(object): 'hash_sha1': hash_sha1 } + def count_artifacts(self): + '''Return the number of known artifacts. + + This may include artifacts where the actual files aren't stored in the + cache, as we allow submitting just the hash in order to check + reproducibility. + + ''' + n_artifacts_sql = ''' + SELECT COUNT(cache_name) FROM artifact_files + ''' + + cursor = self.db.cursor() + logging.debug('Running: %s', n_artifacts_sql) + cursor.execute(n_artifacts_sql) + + return cursor.fetchone()[0] + def view_artifact_statistics(self, start=0, page_size=50): '''Return information on number of builds for each artifact. diff --git a/morphcacheserver/frontend.py b/morphcacheserver/frontend.py index 0376aa0..bc21f70 100644 --- a/morphcacheserver/frontend.py +++ b/morphcacheserver/frontend.py @@ -13,7 +13,9 @@ # with this program. If not, see <http://www.gnu.org/licenses/>. -from bottle import Bottle, template +from bottle import Bottle, request, template + +import math def make_table(data, heading_ids, heading_titles): @@ -47,14 +49,30 @@ def web_frontend(db): def artifacts(): '''View artifacts in the cache.''' + # This causes a 500 error if the parameter is not an integer. + page = int(request.query.get('page', 1)) + page_size = 50 + content = '<p>Artifacts:</p>' - artifacts = db.view_artifact_statistics() + artifacts = db.view_artifact_statistics( + start=(page-1)*page_size, page_size=page_size) content += make_table( artifacts, ['cache_name', 'n_builds', 'n_different_builds'], ['Artifact', 'Total builds', 'Mismatching builds']) + n_artifacts = db.count_artifacts() + n_pages = int(math.ceil(n_artifacts / float(page_size))) + + content += '<p>Page %i of %i</p>' % (page, n_pages) + if page > 1: + content += '<a href="?page=%i">prev</a>' % (page-1) + if page < n_pages: + content += ' -- ' + if page < n_pages: + content += '<a href="?page=%i">next</a>' % (page+1) + return template('morphcacheserver/templates/base', base=content) @app.get('/') |