1
from gourmet.plugin import BaseExporterPlugin
2
from gourmet.recipeManager import default_rec_manager
3
from nutritionLabel import MAIN_NUT_LAYOUT, MAJOR, MINOR, TINY, SEP, SHOW_PERCENT, DONT_SHOW_PERCENT, SEP
4
from gettext import gettext as _
6
class NutritionBaseExporterPlugin (BaseExporterPlugin):
9
BaseExporterPlugin.__init__(self)
10
self.add_field('Nutritional Information',
11
self.get_nutritional_info_as_text_blob,
14
def get_nutritional_info_as_text_blob (self, rec):
17
rd = default_rec_manager()
19
nutinfo = nd.get_nutinfo_for_inglist(rd.get_ings(rec),rd)
20
ings = rd.get_ings(rec)
21
vapor = nutinfo._get_vapor()
23
txt += '<i>%s</i>'%((rec.servings and _('Nutritional information reflects amount per serving.'))
25
_('Nutritional information reflects amounts for entire recipe'))
26
if len(vapor)==len(ings): return None
29
footnotes = '\n*' + _('Nutritional information is missing for %s ingredients: %s')%(
31
', '.join([nv.__ingobject__.item for nv in vapor])
33
for itm in MAIN_NUT_LAYOUT:
35
# We don't have any nice way of outputting separator
39
label,typ,name,properties,show_percent,unit = itm
41
itm_text = '<b>'+label+'</b>'
45
itm_text += ' (%s)'%unit
46
if type(properties) == list:
47
print 'Summing',properties
48
amts = [getattr(nutinfo,att) for att in properties]
52
amt = getattr(nutinfo,properties)
54
amt = amt/rec.servings
55
itm_text += ' %d'%round(amt)
57
return '\n'.join([txt,footnotes])