From 868d12fcedf1ee594732becd95c5df21effb266a Mon Sep 17 00:00:00 2001 From: Mike Shoup Date: Mon, 8 Jul 2019 12:40:01 -0600 Subject: [PATCH] Add info endpoint --- src/humulus/styles.py | 8 ++- src/humulus/templates/styles/index.html | 2 +- src/humulus/templates/styles/info.html | 84 +++++++++++++++++++++++++ tests/test_styles.py | 14 +++++ 4 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 src/humulus/templates/styles/info.html diff --git a/src/humulus/styles.py b/src/humulus/styles.py index 7ef9ab1..43e3405 100644 --- a/src/humulus/styles.py +++ b/src/humulus/styles.py @@ -23,7 +23,7 @@ from flask import Blueprint, abort, current_app, render_template, request from flask.cli import with_appcontext from humulus.auth import login_required -from humulus.couch import get_db, put_doc, get_view +from humulus.couch import get_db, put_doc, get_view, get_doc_or_404 bp = Blueprint('styles', __name__, url_prefix='/styles') @@ -147,3 +147,9 @@ def index(): num_pages=math.ceil(len(rows)/limit), limit=limit ) + + +@bp.route('/info/') +@login_required +def info(id): + return render_template('styles/info.html', style=get_doc_or_404(id)) diff --git a/src/humulus/templates/styles/index.html b/src/humulus/templates/styles/index.html index c230703..8d3718b 100644 --- a/src/humulus/templates/styles/index.html +++ b/src/humulus/templates/styles/index.html @@ -46,7 +46,7 @@ {% for row in rows %} {{ row.doc.id }} - {{ row.doc.name }} + {{ row.doc.name }} {% endfor %} diff --git a/src/humulus/templates/styles/info.html b/src/humulus/templates/styles/info.html new file mode 100644 index 0000000..88a6ba7 --- /dev/null +++ b/src/humulus/templates/styles/info.html @@ -0,0 +1,84 @@ +{#- + Copyright 2019 Mike Shoup + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +-#} +{% from "_macros.html" import moment %} + +{% macro render_detail(field, header) %} +
+

{{ header }}

+
+
+

{{ field }}

+
+{% endmacro %} + + +{% extends '_base.html' %} +{% block title %}{{ style.id }} {{ style.name }}{% endblock %} + +{% block body %} +

{{ style.id }} {{ style.name }}

+{{ render_detail(style.impression, 'Overall Impression') }} +{{ render_detail(style.appearance, 'Appearance') }} +{{ render_detail(style.aroma, 'Aroma') }} +{{ render_detail(style.flavor, 'Flavor') }} +{{ render_detail(style.mouthfeel, 'Mouthfeel') }} + +{% if style.comments %} + {{ render_detail(style.comments, 'Comments') }} +{% endif %} +{% if style.history %} +{{ render_detail(style.history, 'History') }} +{% endif %} +{% if style.ingredients %} +{{ render_detail(style.ingredients, 'Characteristic Ingredients') }} +{% endif %} +{% if style.comparison %} +{{ render_detail(style.comparison, 'Style Comparisons') }} +{% endif %} + +
+

Vital Statistics

+ + + + + + + + + + + + + + + + + + + + + +
IBU{{ style.ibu.low }} - {{ style.ibu.high }}
OG{{ '%.3f' | format(style.og.low|float) }} - {{ '%.3f' | format(style.og.high|float) }}
FG{{ '%.3f' | format(style.fg.low|float) }} - {{ '%.3f' | format(style.fg.high|float) }}
SRM{{ style.srm.low }} - {{ style.srm.high }}
ABV{{ style.abv.low }} - {{ style.abv.high }}
+
+ +{% if style.examples %} +{{ render_detail(style.examples, 'Commercial Examples') }} +{% endif %} + + + +{% endblock %} diff --git a/tests/test_styles.py b/tests/test_styles.py index 45ac4ac..72b321d 100644 --- a/tests/test_styles.py +++ b/tests/test_styles.py @@ -198,3 +198,17 @@ def test_index(auth, client): # Test for bad request response = client.get('/styles/?sort_by=foobar') assert response.status_code == 400 + + +def test_info(auth, client): + """Test success in retrieving a style's info page""" + # Test not logged in + response = client.get('/styles/info/style_1A') + assert response.status_code == 302 + + # Login and test + auth.login() + response = client.get('/styles/info/style_1A') + assert response.status_code == 200 + assert b'1A' in response.data + assert b'Test Style' in response.data