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

Adds a recipe type field for recipe form.

This commit is contained in:
Emma 2019-07-06 19:11:09 -06:00
parent 221ddbafe0
commit 7505390f52
No known key found for this signature in database
GPG key ID: 68434BFE85360755
5 changed files with 20 additions and 2 deletions

View file

@ -148,6 +148,11 @@ class YeastForm(Form):
class RecipeForm(FlaskForm): class RecipeForm(FlaskForm):
"""Form for recipes.""" """Form for recipes."""
name = StringField('Name', validators=[DataRequired()]) 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 (%)', efficiency = DecimalField('Batch Efficiency (%)',
validators=[DataRequired()]) validators=[DataRequired()])
volume = DecimalField('Batch Volume (gal)', validators=[DataRequired()]) volume = DecimalField('Batch Volume (gal)', validators=[DataRequired()])
@ -176,6 +181,7 @@ class RecipeForm(FlaskForm):
'volume': str(self.volume.data), 'volume': str(self.volume.data),
'notes': self.notes.data, 'notes': self.notes.data,
'$type': 'recipe', '$type': 'recipe',
'type': self.type.data
} }
recipe['fermentables'] = [f.doc for f in self.fermentables] recipe['fermentables'] = [f.doc for f in self.fermentables]
@ -191,6 +197,7 @@ class RecipeForm(FlaskForm):
def copyfrom(self, data): def copyfrom(self, data):
"""Copies from a dictionary (data) into the current object""" """Copies from a dictionary (data) into the current object"""
self.name.data = data['name'] self.name.data = data['name']
self.type.data = data['type']
self.efficiency.data = Decimal(data['efficiency']) self.efficiency.data = Decimal(data['efficiency'])
self.volume.data = Decimal(data['volume']) self.volume.data = Decimal(data['volume'])
self.notes.data = data['notes'] self.notes.data = data['notes']

View file

@ -26,8 +26,9 @@
-#} -#}
<div class="row"> <div class="row">
<div class="col-sm-6">{{ render_field_with_errors(form.name) }}</div> <div class="col-sm-6">{{ render_field_with_errors(form.name) }}</div>
<div class="col-sm-3">{{ render_field_with_errors(form.efficiency, 'ingredient-field') }}</div> <div class="col-sm-2">{{ render_field_with_errors(form.type) }}</div>
<div class="col-sm-3">{{ render_field_with_errors(form.volume, 'ingredient-field') }}</div> <div class="col-sm-2">{{ render_field_with_errors(form.efficiency, 'ingredient-field') }}</div>
<div class="col-sm-2">{{ render_field_with_errors(form.volume, 'ingredient-field') }}</div>
</div> </div>
{#- {#-
Fermentable Ingredients Fermentable Ingredients

View file

@ -28,6 +28,8 @@
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<dl> <dl>
<dt>Recipe Type</dt>
<dd>{{ recipe.type }}</dd>
<dt>Batch Efficiency</dt> <dt>Batch Efficiency</dt>
<dd>{{ recipe.efficiency|int }}%</dd> <dd>{{ recipe.efficiency|int }}%</dd>
<dt>Batch Volume</dt> <dt>Batch Volume</dt>

View file

@ -44,6 +44,7 @@ def app():
put_doc({ put_doc({
'_id': 'awesome-lager', '_id': 'awesome-lager',
'$type': 'recipe', '$type': 'recipe',
'type': 'All-Grain',
'efficiency': '65', 'efficiency': '65',
'name': 'Awesome Lager', 'name': 'Awesome Lager',
'notes': 'Test', 'notes': 'Test',
@ -56,6 +57,7 @@ def app():
'$type': 'recipe', '$type': 'recipe',
'efficiency': '75', 'efficiency': '75',
'name': 'Partial Beer', 'name': 'Partial Beer',
'type': 'Extract',
'notes': 'Contains only required fields for yeast.', 'notes': 'Contains only required fields for yeast.',
'volume': '3.5', 'volume': '3.5',
'fermentables': [], 'fermentables': [],
@ -70,6 +72,7 @@ def app():
'_id': 'full-recipe', '_id': 'full-recipe',
'$type': 'recipe', '$type': 'recipe',
'efficiency': '78', 'efficiency': '78',
'type': 'All-Grain',
'name': 'Awesome Beer', 'name': 'Awesome Beer',
'notes': 'This is a test beer that contains most possible fields.', 'notes': 'This is a test beer that contains most possible fields.',
'volume': '2.5', 'volume': '2.5',
@ -160,6 +163,7 @@ def sample_recipes():
return { return {
'lager': { 'lager': {
'efficiency': '72', 'efficiency': '72',
'type': 'All-Grain',
'fermentables': [ 'fermentables': [
{ {
'amount': '9.5', 'amount': '9.5',
@ -217,6 +221,7 @@ def sample_recipes():
}, },
'sweetstout': { 'sweetstout': {
'efficiency': '72', 'efficiency': '72',
'type': 'All-Grain',
'fermentables': [ 'fermentables': [
{ {
'amount': '2.75', 'amount': '2.75',

View file

@ -253,10 +253,12 @@ def test_recipe_form_doc(app):
recipe.efficiency.data = Decimal('65') recipe.efficiency.data = Decimal('65')
recipe.volume.data = Decimal('5.5') recipe.volume.data = Decimal('5.5')
recipe.notes.data = 'This is a test' recipe.notes.data = 'This is a test'
recipe.type.data = 'All-Grain'
assert recipe.doc == { assert recipe.doc == {
'name': 'Test', 'name': 'Test',
'efficiency': '65', 'efficiency': '65',
'type': 'All-Grain',
'volume': '5.5', 'volume': '5.5',
'notes': 'This is a test', 'notes': 'This is a test',
'fermentables': [], 'fermentables': [],
@ -290,6 +292,7 @@ def test_recipe_form_doc(app):
assert recipe.doc == { assert recipe.doc == {
'name': 'Test', 'name': 'Test',
'efficiency': '65', 'efficiency': '65',
'type': 'All-Grain',
'volume': '5.5', 'volume': '5.5',
'notes': 'This is a test', 'notes': 'This is a test',
'$type': 'recipe', '$type': 'recipe',