-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
short number type changed to int, added validation and widget for dis…
…playing the information
- Loading branch information
Teppo Naakka
committed
Mar 22, 2013
1 parent
f85da34
commit b551473
Showing
3 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from five import grok | ||
from zope.schema.interfaces import IInt | ||
from z3c.form.widget import FieldWidget | ||
from z3c.form.interfaces import IDataConverter | ||
from z3c.form.browser.text import TextWidget | ||
from z3c.form.converter import IntegerDataConverter | ||
|
||
|
||
class ShortNumberWidget(TextWidget): | ||
""" Widget for displaying short numbers properly """ | ||
|
||
|
||
def ShortNumberFieldWidget(field, request): | ||
return FieldWidget(field, ShortNumberWidget(request)) | ||
|
||
|
||
class ShortNumberDataConverter(IntegerDataConverter, grok.MultiAdapter): | ||
grok.provides(IDataConverter) | ||
grok.adapts(IInt, ShortNumberWidget) | ||
|
||
def toWidgetValue(self, value): | ||
""" Adapts value to widget value without localized formatting """ | ||
|
||
if value is self.field.missing_value: | ||
return u'' | ||
|
||
return unicode(value) |