diff --git a/src/humulus/recipes.py b/src/humulus/recipes.py index bc2ead0..5c10daf 100644 --- a/src/humulus/recipes.py +++ b/src/humulus/recipes.py @@ -22,7 +22,7 @@ from wtforms import (Form, StringField, DecimalField, TextAreaField, FieldList, FormField, SelectField) from wtforms.validators import DataRequired, Optional -from humulus.couch import get_doc_or_404, put_doc, update_doc +from humulus.couch import get_doc_or_404, put_doc, update_doc, get_view bp = Blueprint('recipes', __name__, url_prefix='/recipes') @@ -185,6 +185,26 @@ class RecipeForm(FlaskForm): return recipe +@bp.route('/') +def index(): + descending = ( + request.args.get('descending', default='false', type=str).lower() in + ['true', 'yes'] + ) + sort_by = request.args.get('sort_by', default='name', type=str) + if sort_by == 'date': + view = get_view('_design/recipes', 'by-date') + else: + view = get_view('_design/recipes', 'by-name') + + return render_template( + 'recipes/index.html', + rows=view(include_docs=True, descending=descending)['rows'], + descending=descending, + sort_by=sort_by + ) + + @bp.route('/create', methods=('GET', 'POST')) def create(): form = RecipeForm() diff --git a/src/humulus/templates/recipes/index.html b/src/humulus/templates/recipes/index.html new file mode 100644 index 0000000..544a8d2 --- /dev/null +++ b/src/humulus/templates/recipes/index.html @@ -0,0 +1,56 @@ +{#- + 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 %} +{% from "recipes/_macros.html" import render_recipe_form %} + +{% extends '_base.html' %} +{% block title %}Recipes{% endblock %} + +{% block body %} +
| + {% if sort_by == 'name' and descending %} + Name ↓ + {% elif sort_by == 'name' %} + Name ↑ + {% else %} + Name + {% endif %} + | +Batch Size | ++ {% if sort_by == 'date' and descending %} + Created On ↓ + {% elif sort_by == 'date' %} + Created On ↑ + {% else %} + Created On + {% endif %} + | +
|---|---|---|
| {{ row.doc.name }} | +{{ row.doc.volume }} | +{{ moment(row.doc.created) }} | +