mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 17:09:44 +00:00
Add hops in the backend
This commit is contained in:
parent
5af167e394
commit
1c3b91bbfc
2 changed files with 51 additions and 4 deletions
|
|
@ -33,7 +33,6 @@ class FermentableForm(Form):
|
||||||
CSRF is disabled for this subform (using `Form as parent class) because it
|
CSRF is disabled for this subform (using `Form as parent class) because it
|
||||||
is never used by itself.
|
is never used by itself.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = StringField('Name', validators=[DataRequired()])
|
name = StringField('Name', validators=[DataRequired()])
|
||||||
type = SelectField('Type', validators=[DataRequired()],
|
type = SelectField('Type', validators=[DataRequired()],
|
||||||
choices=[(c, c) for c in ['Grain', 'LME', 'DME', 'Sugar',
|
choices=[(c, c) for c in ['Grain', 'LME', 'DME', 'Sugar',
|
||||||
|
|
@ -57,18 +56,50 @@ class FermentableForm(Form):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class HopForm(Form):
|
||||||
|
"""Form for hops.
|
||||||
|
|
||||||
|
CSRF is disabled for this subform (using `Form as parent class) because it
|
||||||
|
is never used by itself.
|
||||||
|
"""
|
||||||
|
name = StringField('Name', validators=[DataRequired()])
|
||||||
|
use = SelectField('Usage', validators=[DataRequired()],
|
||||||
|
choices=[(c, c) for c in ['Boil', 'FWH', 'Whirlpool',
|
||||||
|
'Dry-Hop']])
|
||||||
|
alpha = DecimalField('Alpha Acid %', validators=[DataRequired()])
|
||||||
|
duration = DecimalField('Duration (min/day)', validators=[DataRequired()])
|
||||||
|
amount = DecimalField('Amount (oz)', validators=[DataRequired()])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def doc(self):
|
||||||
|
"""Returns a dictionary that can be deserialized into JSON.
|
||||||
|
|
||||||
|
Used for putting into CouchDB.
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
'name': self.name.data,
|
||||||
|
'use': self.use.data,
|
||||||
|
'alpha': str(self.alpha.data),
|
||||||
|
'duration': str(self.duration.data),
|
||||||
|
'amount': str(self.amount.data)
|
||||||
|
}
|
||||||
|
|
||||||
class RecipeForm(FlaskForm):
|
class RecipeForm(FlaskForm):
|
||||||
"""Form for recipes."""
|
"""Form for recipes."""
|
||||||
name = StringField('Name', validators=[DataRequired()])
|
name = StringField('Name', validators=[DataRequired()])
|
||||||
efficiency = DecimalField('Batch Efficiency (%)', validators=[DataRequired()])
|
efficiency = DecimalField('Batch Efficiency (%)', validators=[DataRequired()])
|
||||||
volume = DecimalField('Batch Volume (gal)', validators=[DataRequired()])
|
volume = DecimalField('Batch Volume (gal)', validators=[DataRequired()])
|
||||||
notes = TextAreaField('Notes')
|
notes = TextAreaField('Notes')
|
||||||
|
|
||||||
fermentables = FieldList(
|
fermentables = FieldList(
|
||||||
FormField(FermentableForm),
|
FormField(FermentableForm),
|
||||||
min_entries=0,
|
min_entries=0,
|
||||||
max_entries=20
|
max_entries=20
|
||||||
)
|
)
|
||||||
|
hops = FieldList(
|
||||||
|
FormField(HopForm),
|
||||||
|
min_entries=0,
|
||||||
|
max_entries=20
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def doc(self):
|
def doc(self):
|
||||||
|
|
@ -81,7 +112,8 @@ class RecipeForm(FlaskForm):
|
||||||
'efficiency': str(self.efficiency.data),
|
'efficiency': str(self.efficiency.data),
|
||||||
'volume': str(self.volume.data),
|
'volume': str(self.volume.data),
|
||||||
'notes': self.notes.data,
|
'notes': self.notes.data,
|
||||||
'fermentables': [f.doc for f in self.fermentables]
|
'fermentables': [f.doc for f in self.fermentables],
|
||||||
|
'hops': [h.doc for h in self.hops],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from humulus.couch import get_db
|
from humulus.couch import get_db
|
||||||
from humulus.recipes import FermentableForm, RecipeForm
|
from humulus.recipes import FermentableForm, HopForm, RecipeForm
|
||||||
|
|
||||||
|
|
||||||
def test_create(client, app):
|
def test_create(client, app):
|
||||||
|
|
@ -71,11 +71,19 @@ def test_recipe_form_doc(app):
|
||||||
ferm.ppg.data = Decimal('37')
|
ferm.ppg.data = Decimal('37')
|
||||||
ferm.color.data = Decimal('1.8')
|
ferm.color.data = Decimal('1.8')
|
||||||
|
|
||||||
|
hop = HopForm()
|
||||||
|
hop.name.data = 'Test'
|
||||||
|
hop.use.data = 'Boil'
|
||||||
|
hop.alpha.data = Decimal('12.5')
|
||||||
|
hop.duration.data = Decimal('60')
|
||||||
|
hop.amount.data = Decimal('0.5')
|
||||||
|
|
||||||
recipe.name.data = 'Test'
|
recipe.name.data = 'Test'
|
||||||
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.fermentables = [ferm]
|
recipe.fermentables = [ferm]
|
||||||
|
recipe.hops = [hop]
|
||||||
|
|
||||||
assert recipe.doc == {
|
assert recipe.doc == {
|
||||||
'name': 'Test',
|
'name': 'Test',
|
||||||
|
|
@ -89,4 +97,11 @@ def test_recipe_form_doc(app):
|
||||||
'ppg': '37',
|
'ppg': '37',
|
||||||
'color': '1.8',
|
'color': '1.8',
|
||||||
}],
|
}],
|
||||||
|
'hops': [{
|
||||||
|
'name': 'Test',
|
||||||
|
'use': 'Boil',
|
||||||
|
'alpha': '12.5',
|
||||||
|
'duration': '60',
|
||||||
|
'amount': '0.5'
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue