From 7505390f521132c169964fb332ae5f6c7c1024c4 Mon Sep 17 00:00:00 2001 From: Mike Shoup Date: Sat, 6 Jul 2019 19:11:09 -0600 Subject: [PATCH] Adds a recipe type field for recipe form. --- src/humulus/recipes.py | 7 +++++++ src/humulus/templates/recipes/_macros.html | 5 +++-- src/humulus/templates/recipes/info.html | 2 ++ tests/conftest.py | 5 +++++ tests/test_recipes.py | 3 +++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/humulus/recipes.py b/src/humulus/recipes.py index 4c1bf65..7aeefd3 100644 --- a/src/humulus/recipes.py +++ b/src/humulus/recipes.py @@ -148,6 +148,11 @@ class YeastForm(Form): class RecipeForm(FlaskForm): """Form for recipes.""" name = StringField('Name', validators=[DataRequired()]) + type = SelectField('Type', default='', + choices=[(c, c) for c in ['All-Grain', + 'Partial Extract', + 'Extract']], + validators=[Optional()]) efficiency = DecimalField('Batch Efficiency (%)', validators=[DataRequired()]) volume = DecimalField('Batch Volume (gal)', validators=[DataRequired()]) @@ -176,6 +181,7 @@ class RecipeForm(FlaskForm): 'volume': str(self.volume.data), 'notes': self.notes.data, '$type': 'recipe', + 'type': self.type.data } recipe['fermentables'] = [f.doc for f in self.fermentables] @@ -191,6 +197,7 @@ class RecipeForm(FlaskForm): def copyfrom(self, data): """Copies from a dictionary (data) into the current object""" self.name.data = data['name'] + self.type.data = data['type'] self.efficiency.data = Decimal(data['efficiency']) self.volume.data = Decimal(data['volume']) self.notes.data = data['notes'] diff --git a/src/humulus/templates/recipes/_macros.html b/src/humulus/templates/recipes/_macros.html index ae48f16..6ac50ac 100644 --- a/src/humulus/templates/recipes/_macros.html +++ b/src/humulus/templates/recipes/_macros.html @@ -26,8 +26,9 @@ -#}
{{ render_field_with_errors(form.name) }}
-
{{ render_field_with_errors(form.efficiency, 'ingredient-field') }}
-
{{ render_field_with_errors(form.volume, 'ingredient-field') }}
+
{{ render_field_with_errors(form.type) }}
+
{{ render_field_with_errors(form.efficiency, 'ingredient-field') }}
+
{{ render_field_with_errors(form.volume, 'ingredient-field') }}
{#- Fermentable Ingredients diff --git a/src/humulus/templates/recipes/info.html b/src/humulus/templates/recipes/info.html index 13252ba..0a8695c 100644 --- a/src/humulus/templates/recipes/info.html +++ b/src/humulus/templates/recipes/info.html @@ -28,6 +28,8 @@
+
Recipe Type
+
{{ recipe.type }}
Batch Efficiency
{{ recipe.efficiency|int }}%
Batch Volume
diff --git a/tests/conftest.py b/tests/conftest.py index 917f4fd..d997ccb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -44,6 +44,7 @@ def app(): put_doc({ '_id': 'awesome-lager', '$type': 'recipe', + 'type': 'All-Grain', 'efficiency': '65', 'name': 'Awesome Lager', 'notes': 'Test', @@ -56,6 +57,7 @@ def app(): '$type': 'recipe', 'efficiency': '75', 'name': 'Partial Beer', + 'type': 'Extract', 'notes': 'Contains only required fields for yeast.', 'volume': '3.5', 'fermentables': [], @@ -70,6 +72,7 @@ def app(): '_id': 'full-recipe', '$type': 'recipe', 'efficiency': '78', + 'type': 'All-Grain', 'name': 'Awesome Beer', 'notes': 'This is a test beer that contains most possible fields.', 'volume': '2.5', @@ -160,6 +163,7 @@ def sample_recipes(): return { 'lager': { 'efficiency': '72', + 'type': 'All-Grain', 'fermentables': [ { 'amount': '9.5', @@ -217,6 +221,7 @@ def sample_recipes(): }, 'sweetstout': { 'efficiency': '72', + 'type': 'All-Grain', 'fermentables': [ { 'amount': '2.75', diff --git a/tests/test_recipes.py b/tests/test_recipes.py index d8ca6a4..525cd52 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -253,10 +253,12 @@ def test_recipe_form_doc(app): recipe.efficiency.data = Decimal('65') recipe.volume.data = Decimal('5.5') recipe.notes.data = 'This is a test' + recipe.type.data = 'All-Grain' assert recipe.doc == { 'name': 'Test', 'efficiency': '65', + 'type': 'All-Grain', 'volume': '5.5', 'notes': 'This is a test', 'fermentables': [], @@ -290,6 +292,7 @@ def test_recipe_form_doc(app): assert recipe.doc == { 'name': 'Test', 'efficiency': '65', + 'type': 'All-Grain', 'volume': '5.5', 'notes': 'This is a test', '$type': 'recipe',