Merge branch 'bbmaster' of ssh://git.cy55.de/home/git/cybertools into bbmaster

This commit is contained in:
hplattner 2012-07-09 08:24:28 +02:00
commit 26487b5598
6 changed files with 40 additions and 11 deletions

View file

@ -43,9 +43,11 @@ class BaseRow(object):
class Row(BaseRow):
attributeHandlers = {}
cssClass = u''
def getRawValue(self, attr):
return self.attributeHandlers.get(attr, self.getContextAttr)(self, attr)
return self.attributeHandlers.get(
attr, self.getContextAttr)(self, attr)
@staticmethod
def getContextAttr(obj, attr):

View file

@ -49,9 +49,9 @@ Field types
>>> from cybertools.composer.schema.interfaces import fieldTypes
>>> sorted(t.token for t in fieldTypes)
['checkbox', 'checkboxes', 'date', 'display', 'dropdown', 'email', 'explanation',
'fileupload', 'heading', 'html', 'list', 'number', 'password', 'radiobuttons',
'spacer', 'textarea', 'textline']
['checkbox', 'checkboxes', 'date', 'decimal', 'display', 'dropdown',
'email', 'explanation', 'fileupload', 'heading', 'html', 'list', 'number',
'password', 'radiobuttons', 'spacer', 'textarea', 'textline']
>>> from zope.schema.vocabulary import SimpleVocabulary
>>> textFieldTypes = SimpleVocabulary([t for t in fieldTypes if t.token in

View file

@ -18,8 +18,6 @@
"""
Schema factory stuff.
$Id$
"""
from zope.component import adapts
@ -41,7 +39,7 @@ class Email(schema.TextLine):
schema.Field.__typeInfo__ = ('textline',)
schema.Password.__typeInfo__ = ('password',)
schema.Int.__typeInfo__ = ('number',)
schema.Float.__typeInfo__ = ('number',)
schema.Float.__typeInfo__ = ('decimal',)
schema.Choice.__typeInfo__ = ('dropdown',)
@ -56,13 +54,13 @@ class SchemaFactory(object):
fieldMapping = {
#schema.TextLine: ('textline',),
#schema.ASCIILine: ('textline',),
schema.Password: ('password',),
#schema.Password: ('password',),
schema.Text: ('textarea',),
schema.ASCII: ('textarea',),
schema.Date: ('date',),
schema.Datetime: ('date',),
schema.Int: ('number',),
schema.Float: ('number',),
#schema.Int: ('number',),
#schema.Float: ('decimal',),
schema.Bool: ('checkbox',),
schema.List: ('list',),
#schema.Choice: ('dropdown',),

View file

@ -24,6 +24,7 @@ from datetime import datetime
from logging import getLogger
from time import strptime, strftime
from zope.app.form.browser.interfaces import ITerms
from zope.i18n.locales import locales
from zope.interface import implements
from zope.cachedescriptors.property import Lazy
from zope.component import adapts
@ -262,6 +263,32 @@ class NumberFieldInstance(FieldInstance):
self.setError('invalid_number')
class DecimalFieldInstance(NumberFieldInstance):
format = 'decimal'
def marshall(self, value):
return self.display(value, pattern=u'0.00;-0.00')
def display(self, value, pattern=u'#,##0.00;-#,##0.00'):
if value is None:
return ''
view = self.clientInstance.view
langInfo = view and getattr(view, 'languageInfo', None) or None
if langInfo:
locale = locales.getLocale(langInfo.language)
fmt = locale.numbers.getFormatter(self.format)
return fmt.format(value, pattern=pattern)
return '%.2f' % value
def unmarshall(self, value):
if not value:
return None
if ',' in value:
value = value.replace(',', '.')
return float(value)
class DateFieldInstance(NumberFieldInstance):
def marshall(self, value):

View file

@ -114,7 +114,7 @@ class GridFieldInstance(ListFieldInstance):
def unmarshallRow(self, row):
item = {}
for fi in self.columnFieldInstances:
value = fi.unmarshall(row[fi.name])
value = fi.unmarshall(row.get(fi.name) or u'')
if isinstance(value, basestring):
value = value.strip()
if fi.default is not None:

View file

@ -98,6 +98,8 @@ fieldTypes = SimpleVocabulary((
FieldType('html', 'html', u'HTML Text'),
FieldType('number', 'number', u'Number',
inputRenderer='input_textline', instanceName='number'),
FieldType('decimal', 'decimal', u'Decimal',
inputRenderer='input_textline', instanceName='decimal'),
FieldType('date', 'date', u'Date', instanceName='date'),
FieldType('email', 'email', u'E-Mail Address',
displayRenderer='display_email', inputRenderer='input_textline',