1
0
Fork 0
mirror of https://github.com/shouptech/humulus.git synced 2026-02-03 15:09:42 +00:00

Add view for recipe type

This commit is contained in:
Emma 2019-07-07 08:19:30 -06:00
parent 7505390f52
commit a58b93285c
No known key found for this signature in database
GPG key ID: 68434BFE85360755
4 changed files with 35 additions and 6 deletions

View file

@ -10,6 +10,9 @@
},
"by-volume": {
"map": "function (doc) {\n if (doc.$type == \"recipe\" && doc.volume && doc.name) {\n emit(doc.volume, doc.name)\n }\n}"
},
"by-type": {
"map": "function (doc) {\n if (doc.$type == \"recipe\" && doc.type && doc.name) {\n emit(doc.type, doc.name)\n }\n}"
}
},
"lists": {},

View file

@ -262,12 +262,7 @@ def index():
['true', 'yes']
)
sort_by = request.args.get('sort_by', default='name', type=str)
if sort_by == 'date':
view = get_view('_design/recipes', 'by-date')
elif sort_by == 'volume':
view = get_view('_design/recipes', 'by-volume')
else:
view = get_view('_design/recipes', 'by-name')
view = get_view('_design/recipes', 'by-{}'.format(sort_by))
return render_template(
'recipes/index.html',

View file

@ -49,6 +49,15 @@
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='volume') }}">Batch Size</a>
{% endif %}
</th>
<th>
{% if sort_by == 'type' and descending %}
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='type') }}">Type &darr;</a>
{% elif sort_by == 'type' %}
<a class="text-dark" href="{{ url_for('recipes.index', descending='true', sort_by='type') }}">Type &uarr;</a>
{% else %}
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='type') }}">Type</a>
{% endif %}
</th>
<th>
{% if sort_by == 'date' and descending %}
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='date') }}">Created On &darr;</a>
@ -64,6 +73,7 @@
<tr>
<td><a href="{{ url_for('recipes.info', id=row.id) }}">{{ row.doc.name }}</a></td>
<td>{{ row.doc.volume }} gal.</td>
<td>{{ row.doc.type }}</td>
<td>{{ moment(row.doc.created) }}</td>
</tr>
{% endfor %}

View file

@ -93,6 +93,27 @@ def test_index(client):
response.data
)
# Test sort by type ascending
response = client.get('/recipes/?descending=false&sort_by=type')
assert (
b'"/recipes/?descending=false&amp;sort_by=name">Name' in
response.data
)
assert (
b'"/recipes/?descending=true&amp;sort_by=type">Type &uarr;' in
response.data
)
# Test sort by type descending
response = client.get('/recipes/?descending=true&sort_by=type')
assert (
b'"/recipes/?descending=false&amp;sort_by=name">Name' in
response.data
)
assert (
b'"/recipes/?descending=false&amp;sort_by=type">Type &darr;' in
response.data
)
def test_create(client, app, auth):
"""Test success in creating a recipe document."""