provide separate float field instance; predefine cssClass in row base class
This commit is contained in:
parent
b0354c4435
commit
8a77fec13d
5 changed files with 39 additions and 8 deletions
|
@ -42,9 +42,11 @@ class BaseRow(object):
|
||||||
class Row(BaseRow):
|
class Row(BaseRow):
|
||||||
|
|
||||||
attributeHandlers = {}
|
attributeHandlers = {}
|
||||||
|
cssClass = u''
|
||||||
|
|
||||||
def getRawValue(self, attr):
|
def getRawValue(self, attr):
|
||||||
return self.attributeHandlers.get(attr, self.getContextAttr)(self, attr)
|
return self.attributeHandlers.get(
|
||||||
|
attr, self.getContextAttr)(self, attr)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getContextAttr(obj, attr):
|
def getContextAttr(obj, attr):
|
||||||
|
|
|
@ -49,9 +49,9 @@ Field types
|
||||||
|
|
||||||
>>> from cybertools.composer.schema.interfaces import fieldTypes
|
>>> from cybertools.composer.schema.interfaces import fieldTypes
|
||||||
>>> sorted(t.token for t in fieldTypes)
|
>>> sorted(t.token for t in fieldTypes)
|
||||||
['checkbox', 'checkboxes', 'date', 'display', 'dropdown', 'email', 'explanation',
|
['checkbox', 'checkboxes', 'date', 'display', 'dropdown', 'email',
|
||||||
'fileupload', 'heading', 'html', 'list', 'number', 'password', 'radiobuttons',
|
'explanation', 'fileupload', 'float', 'heading', 'html', 'list', 'number',
|
||||||
'spacer', 'textarea', 'textline']
|
'password', 'radiobuttons', 'spacer', 'textarea', 'textline']
|
||||||
|
|
||||||
>>> from zope.schema.vocabulary import SimpleVocabulary
|
>>> from zope.schema.vocabulary import SimpleVocabulary
|
||||||
>>> textFieldTypes = SimpleVocabulary([t for t in fieldTypes if t.token in
|
>>> textFieldTypes = SimpleVocabulary([t for t in fieldTypes if t.token in
|
||||||
|
|
|
@ -41,7 +41,7 @@ class Email(schema.TextLine):
|
||||||
schema.Field.__typeInfo__ = ('textline',)
|
schema.Field.__typeInfo__ = ('textline',)
|
||||||
schema.Password.__typeInfo__ = ('password',)
|
schema.Password.__typeInfo__ = ('password',)
|
||||||
schema.Int.__typeInfo__ = ('number',)
|
schema.Int.__typeInfo__ = ('number',)
|
||||||
schema.Float.__typeInfo__ = ('number',)
|
schema.Float.__typeInfo__ = ('float',)
|
||||||
schema.Choice.__typeInfo__ = ('dropdown',)
|
schema.Choice.__typeInfo__ = ('dropdown',)
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,13 +56,13 @@ class SchemaFactory(object):
|
||||||
fieldMapping = {
|
fieldMapping = {
|
||||||
#schema.TextLine: ('textline',),
|
#schema.TextLine: ('textline',),
|
||||||
#schema.ASCIILine: ('textline',),
|
#schema.ASCIILine: ('textline',),
|
||||||
schema.Password: ('password',),
|
#schema.Password: ('password',),
|
||||||
schema.Text: ('textarea',),
|
schema.Text: ('textarea',),
|
||||||
schema.ASCII: ('textarea',),
|
schema.ASCII: ('textarea',),
|
||||||
schema.Date: ('date',),
|
schema.Date: ('date',),
|
||||||
schema.Datetime: ('date',),
|
schema.Datetime: ('date',),
|
||||||
schema.Int: ('number',),
|
#schema.Int: ('number',),
|
||||||
schema.Float: ('number',),
|
#schema.Float: ('float',),
|
||||||
schema.Bool: ('checkbox',),
|
schema.Bool: ('checkbox',),
|
||||||
schema.List: ('list',),
|
schema.List: ('list',),
|
||||||
#schema.Choice: ('dropdown',),
|
#schema.Choice: ('dropdown',),
|
||||||
|
|
|
@ -24,6 +24,7 @@ from datetime import datetime
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from time import strptime, strftime
|
from time import strptime, strftime
|
||||||
from zope.app.form.browser.interfaces import ITerms
|
from zope.app.form.browser.interfaces import ITerms
|
||||||
|
from zope.i18n.locales import locales
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
from zope.cachedescriptors.property import Lazy
|
from zope.cachedescriptors.property import Lazy
|
||||||
from zope.component import adapts
|
from zope.component import adapts
|
||||||
|
@ -262,6 +263,32 @@ class NumberFieldInstance(FieldInstance):
|
||||||
self.setError('invalid_number')
|
self.setError('invalid_number')
|
||||||
|
|
||||||
|
|
||||||
|
class FloatFieldInstance(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):
|
class DateFieldInstance(NumberFieldInstance):
|
||||||
|
|
||||||
def marshall(self, value):
|
def marshall(self, value):
|
||||||
|
|
|
@ -98,6 +98,8 @@ fieldTypes = SimpleVocabulary((
|
||||||
FieldType('html', 'html', u'HTML Text'),
|
FieldType('html', 'html', u'HTML Text'),
|
||||||
FieldType('number', 'number', u'Number',
|
FieldType('number', 'number', u'Number',
|
||||||
inputRenderer='input_textline', instanceName='number'),
|
inputRenderer='input_textline', instanceName='number'),
|
||||||
|
FieldType('float', 'float', u'Float',
|
||||||
|
inputRenderer='input_textline', instanceName='float'),
|
||||||
FieldType('date', 'date', u'Date', instanceName='date'),
|
FieldType('date', 'date', u'Date', instanceName='date'),
|
||||||
FieldType('email', 'email', u'E-Mail Address',
|
FieldType('email', 'email', u'E-Mail Address',
|
||||||
displayRenderer='display_email', inputRenderer='input_textline',
|
displayRenderer='display_email', inputRenderer='input_textline',
|
||||||
|
|
Loading…
Add table
Reference in a new issue