mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 17:19:42 +00:00
Add info endpoint
This commit is contained in:
parent
dd25448ed9
commit
868d12fced
4 changed files with 106 additions and 2 deletions
|
|
@ -23,7 +23,7 @@ from flask import Blueprint, abort, current_app, render_template, request
|
||||||
from flask.cli import with_appcontext
|
from flask.cli import with_appcontext
|
||||||
|
|
||||||
from humulus.auth import login_required
|
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')
|
bp = Blueprint('styles', __name__, url_prefix='/styles')
|
||||||
|
|
||||||
|
|
@ -147,3 +147,9 @@ def index():
|
||||||
num_pages=math.ceil(len(rows)/limit),
|
num_pages=math.ceil(len(rows)/limit),
|
||||||
limit=limit
|
limit=limit
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/info/<id>')
|
||||||
|
@login_required
|
||||||
|
def info(id):
|
||||||
|
return render_template('styles/info.html', style=get_doc_or_404(id))
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@
|
||||||
{% for row in rows %}
|
{% for row in rows %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ row.doc.id }}</td>
|
<td>{{ row.doc.id }}</td>
|
||||||
<td>{{ row.doc.name }}</td>
|
<td><a href="{{ url_for('styles.info', id=row.doc._id) }}">{{ row.doc.name }}</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
||||||
84
src/humulus/templates/styles/info.html
Normal file
84
src/humulus/templates/styles/info.html
Normal file
|
|
@ -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) %}
|
||||||
|
<div class="row">
|
||||||
|
<h2>{{ header }}</h2>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<p>{{ field }}</p>
|
||||||
|
</div>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
|
||||||
|
{% extends '_base.html' %}
|
||||||
|
{% block title %}{{ style.id }} {{ style.name }}{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div class="row mb-3"><h1>{{ style.id }} {{ style.name }}</h1></div>
|
||||||
|
{{ 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 %}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<h2>Vital Statistics</h2>
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th>IBU</th>
|
||||||
|
<td>{{ style.ibu.low }} - {{ style.ibu.high }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>OG</th>
|
||||||
|
<td>{{ '%.3f' | format(style.og.low|float) }} - {{ '%.3f' | format(style.og.high|float) }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>FG</th>
|
||||||
|
<td>{{ '%.3f' | format(style.fg.low|float) }} - {{ '%.3f' | format(style.fg.high|float) }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>SRM</th>
|
||||||
|
<td>{{ style.srm.low }} - {{ style.srm.high }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>ABV</th>
|
||||||
|
<td>{{ style.abv.low }} - {{ style.abv.high }}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if style.examples %}
|
||||||
|
{{ render_detail(style.examples, 'Commercial Examples') }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="row"><a href="{{ url_for('styles.index') }}">Back to styles list</a></div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -198,3 +198,17 @@ def test_index(auth, client):
|
||||||
# Test for bad request
|
# Test for bad request
|
||||||
response = client.get('/styles/?sort_by=foobar')
|
response = client.get('/styles/?sort_by=foobar')
|
||||||
assert response.status_code == 400
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue