mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 16:09:44 +00:00
Add view for recipe type
This commit is contained in:
parent
7505390f52
commit
a58b93285c
4 changed files with 35 additions and 6 deletions
|
|
@ -10,6 +10,9 @@
|
||||||
},
|
},
|
||||||
"by-volume": {
|
"by-volume": {
|
||||||
"map": "function (doc) {\n if (doc.$type == \"recipe\" && doc.volume && doc.name) {\n emit(doc.volume, doc.name)\n }\n}"
|
"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": {},
|
"lists": {},
|
||||||
|
|
|
||||||
|
|
@ -262,12 +262,7 @@ def index():
|
||||||
['true', 'yes']
|
['true', 'yes']
|
||||||
)
|
)
|
||||||
sort_by = request.args.get('sort_by', default='name', type=str)
|
sort_by = request.args.get('sort_by', default='name', type=str)
|
||||||
if sort_by == 'date':
|
view = get_view('_design/recipes', 'by-{}'.format(sort_by))
|
||||||
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')
|
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'recipes/index.html',
|
'recipes/index.html',
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,15 @@
|
||||||
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='volume') }}">Batch Size</a>
|
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='volume') }}">Batch Size</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</th>
|
</th>
|
||||||
|
<th>
|
||||||
|
{% if sort_by == 'type' and descending %}
|
||||||
|
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='type') }}">Type ↓</a>
|
||||||
|
{% elif sort_by == 'type' %}
|
||||||
|
<a class="text-dark" href="{{ url_for('recipes.index', descending='true', sort_by='type') }}">Type ↑</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='type') }}">Type</a>
|
||||||
|
{% endif %}
|
||||||
|
</th>
|
||||||
<th>
|
<th>
|
||||||
{% if sort_by == 'date' and descending %}
|
{% if sort_by == 'date' and descending %}
|
||||||
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='date') }}">Created On ↓</a>
|
<a class="text-dark" href="{{ url_for('recipes.index', descending='false', sort_by='date') }}">Created On ↓</a>
|
||||||
|
|
@ -64,6 +73,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ url_for('recipes.info', id=row.id) }}">{{ row.doc.name }}</a></td>
|
<td><a href="{{ url_for('recipes.info', id=row.id) }}">{{ row.doc.name }}</a></td>
|
||||||
<td>{{ row.doc.volume }} gal.</td>
|
<td>{{ row.doc.volume }} gal.</td>
|
||||||
|
<td>{{ row.doc.type }}</td>
|
||||||
<td>{{ moment(row.doc.created) }}</td>
|
<td>{{ moment(row.doc.created) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,27 @@ def test_index(client):
|
||||||
response.data
|
response.data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Test sort by type ascending
|
||||||
|
response = client.get('/recipes/?descending=false&sort_by=type')
|
||||||
|
assert (
|
||||||
|
b'"/recipes/?descending=false&sort_by=name">Name' in
|
||||||
|
response.data
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
b'"/recipes/?descending=true&sort_by=type">Type ↑' in
|
||||||
|
response.data
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test sort by type descending
|
||||||
|
response = client.get('/recipes/?descending=true&sort_by=type')
|
||||||
|
assert (
|
||||||
|
b'"/recipes/?descending=false&sort_by=name">Name' in
|
||||||
|
response.data
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
b'"/recipes/?descending=false&sort_by=type">Type ↓' in
|
||||||
|
response.data
|
||||||
|
)
|
||||||
|
|
||||||
def test_create(client, app, auth):
|
def test_create(client, app, auth):
|
||||||
"""Test success in creating a recipe document."""
|
"""Test success in creating a recipe document."""
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue