diff --git a/.gitignore b/.gitignore index df07c09..15a2090 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ ajax/dojo/* *.pydevproject *.sublime-project *.sublime-workspace +.settings diff --git a/composer/schema/field.py b/composer/schema/field.py index fb058fe..5bbc020 100644 --- a/composer/schema/field.py +++ b/composer/schema/field.py @@ -368,7 +368,7 @@ class EmailFieldInstance(FieldInstance): class BooleanFieldInstance(FieldInstance): def marshall(self, value): - return value + return bool(value) def display(self, value): #return value and _(u'Yes') or _(u'No') diff --git a/util/date.py b/util/date.py index fd495b0..a325799 100644 --- a/util/date.py +++ b/util/date.py @@ -71,7 +71,6 @@ def year(d=None): d = datetime.today() return d.year - def toLocalTime(d): if pytz is None or not d: return d @@ -82,3 +81,13 @@ def toLocalTime(d): return d.astimezone(cet) except ValueError: return d + +def month(d=None): + if d is None: + d = datetime.today() + return d.month + +def day(d=None): + if d is None: + d = datetime.today() + return d.day diff --git a/util/format.py b/util/format.py index 1299778..43c58c9 100644 --- a/util/format.py +++ b/util/format.py @@ -50,9 +50,12 @@ def formatDate(dt=None, type='date', variant='medium', lang='de'): return fmt.format(dt or datetime.now()) -def formatNumber(num, type='decimal', lang='de', pattern=u'#,##0.00;-#,##0.00'): +def formatNumber(num, type='decimal', lang='de', + pattern=u'#,##0.00;-#,##0.00', precision=2): loc = locales.getLocale(lang) fmt = loc.numbers.getFormatter(type) + if precision: + num = round(num, precision) # avoid zope.i18n formatting bug return fmt.format(num, pattern=pattern) diff --git a/util/format.txt b/util/format.txt index b96450a..cfab90f 100644 --- a/util/format.txt +++ b/util/format.txt @@ -15,3 +15,5 @@ Basic Formatting Functions >>> format.formatNumber(17.2) u'17,20' + >>> format.formatNumber(13399.99999997) + u'13.400,00'