-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbread.py
96 lines (81 loc) · 2.56 KB
/
bread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'''
bread.py
implementation of model.Model for bread/baking tracker.
'''
import datetime
import wtforms
from . import connection
import model, view_helpers
@connection.register
class Bread(model.Model):
__collection__ = 'bread'
# rename the db to something more general at some point
__database__ = 'books'
use_schemaless = False
#use_schemaless = True
view_decorators = [view_helpers.login_required]
structure = {
'starter_hydration_percent': int,
'starter_mass': int,
'sponge_white_mass': int,
'sponge_whole_wheat_mass': int,
'sponge_water_mass': int,
'dough_white_mass': int,
'dough_whole_wheat_mass': int,
'dough_water_mass': int,
'dough_salt_mass': int,
'other_ingredients': unicode,
'preparation_comments': unicode,
'rating': int,
'final_comments': unicode,
'date': model.Date(),
'name': unicode,
}
structure.update(model.Model.structure)
default_values = {
'date': datetime.date.today,
'starter_hydration_percent': 50,
'starter_mass': 56,
'sponge_white_mass': 227,
'sponge_whole_wheat_mass': 0,
'sponge_water_mass': 142,
'dough_white_mass': 567,
'dough_whole_wheat_mass': 0,
'dough_water_mass': 400,
'dough_salt_mass': 18,
}
default_values.update(model.Model.default_values)
form_fields = {
'preparation_comments': [wtforms.TextAreaField, 'Preparation Comments'],
'other_ingredients': [wtforms.TextAreaField, 'Other Ingredients'],
'final_comments': [wtforms.TextAreaField, 'Final Comments'],
}
required_fields = ['date']
required_fields.extend(model.Model.required_fields)
form_validators = {
'rating': [wtforms.validators.NumberRange(min=0, max=10)],
}
form_validators.update(model.Model.form_validators)
field_order = ['name', 'date',
'starter_hydration_percent',
'starter_mass',
'sponge_white_mass',
'sponge_whole_wheat_mass',
'sponge_water_mass',
'dough_white_mass',
'dough_whole_wheat_mass',
'dough_water_mass',
'dough_salt_mass',
'other_ingredients',
'preparation_comments',
'rating',
'final_comments',
]
def __repr__(self):
return "<%s %r>" % (self.__class__.__name__, self['_id'])
def get_name(self):
if 'name' in self and self['name']:
s = self['name']
else:
s = 'Bread'
return "%s: %s" % (s, self['date'])