Add grouping attribute to numeric widgets
issue10731 review355501002
This commit is contained in:
1 parent
238d207c77
commit
62e6c8090d
4 files changed
+16
-8
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Support grouping attribute
|
||||
* Support monetary and symbol field attributes
|
||||
* Support digits from relation field
|
||||
* Allow PYSON Expression as key for PYSON In with dict object
|
||||
|
||||
@@ -413,7 +413,7 @@ class FloatField(Field):
|
||||
super(FloatField, self).set_client(record, value,
|
||||
force_change=force_change)
|
||||
|
||||
def get_client(self, record, factor=1):
|
||||
def get_client(self, record, factor=1, grouping=True):
|
||||
value = record.value.get(self.name)
|
||||
if value is not None:
|
||||
digits = self.digits(record, factor=factor)
|
||||
@@ -422,10 +422,13 @@ class FloatField(Field):
|
||||
d = Decimal(repr(d))
|
||||
if digits:
|
||||
p = int(digits[1])
|
||||
elif d == d.to_integral_value():
|
||||
p = 0
|
||||
else:
|
||||
p = -int(d.as_tuple().exponent)
|
||||
monetary = self.attrs.get('monetary', False)
|
||||
return locale.localize('{0:.{1}f}'.format(d, p), True, monetary)
|
||||
return locale.localize(
|
||||
'{0:.{1}f}'.format(d, p), grouping, monetary)
|
||||
else:
|
||||
return ''
|
||||
|
||||
@@ -443,9 +446,9 @@ class NumericField(FloatField):
|
||||
return super(NumericField, self).set_client(record, value,
|
||||
force_change=force_change, factor=Decimal(str(factor)))
|
||||
|
||||
def get_client(self, record, factor=1):
|
||||
def get_client(self, record, factor=1, grouping=True):
|
||||
return super(NumericField, self).get_client(record,
|
||||
factor=Decimal(str(factor)))
|
||||
factor=Decimal(str(factor)), grouping=grouping)
|
||||
|
||||
|
||||
class IntegerField(FloatField):
|
||||
@@ -461,8 +464,9 @@ class IntegerField(FloatField):
|
||||
return super(IntegerField, self).set_client(record, value,
|
||||
force_change=force_change, factor=int(factor))
|
||||
|
||||
def get_client(self, record, factor=1):
|
||||
return super(IntegerField, self).get_client(record, factor=int(factor))
|
||||
def get_client(self, record, factor=1, grouping=True):
|
||||
return super(IntegerField, self).get_client(
|
||||
record, factor=int(factor), grouping=grouping)
|
||||
|
||||
|
||||
class BooleanField(Field):
|
||||
|
||||
@@ -26,6 +26,7 @@ class Integer(Widget):
|
||||
self.symbol_start, expand=False, fill=False, padding=1)
|
||||
self.widget.pack_start(self.entry, expand=False, fill=False, padding=0)
|
||||
self.factor = float(attrs.get('factor', 1))
|
||||
self.grouping = bool(int(attrs.get('grouping', 1)))
|
||||
if self.symbol:
|
||||
self.symbol_end = Gtk.Entry(editable=False)
|
||||
self.widget.pack_start(
|
||||
@@ -49,7 +50,8 @@ class Integer(Widget):
|
||||
if not self.field:
|
||||
value = ''
|
||||
else:
|
||||
value = self.field.get_client(self.record, factor=self.factor)
|
||||
value = self.field.get_client(
|
||||
self.record, factor=self.factor, grouping=self.grouping)
|
||||
return value
|
||||
|
||||
@property
|
||||
|
||||
@@ -371,6 +371,7 @@ class Int(GenericText):
|
||||
super(Int, self).__init__(view, attrs, renderer=renderer)
|
||||
self.factor = float(attrs.get('factor', 1))
|
||||
self.symbol = attrs.get('symbol')
|
||||
self.grouping = bool(int(attrs.get('grouping', 1)))
|
||||
if self.symbol:
|
||||
self.renderer_prefix = Symbol(view, attrs, 0)
|
||||
self.renderer_suffix = Symbol(view, attrs, 1)
|
||||
@@ -391,7 +392,7 @@ class Int(GenericText):
|
||||
if not record:
|
||||
return ''
|
||||
return record[self.attrs['name']].get_client(
|
||||
record, factor=self.factor)
|
||||
record, factor=self.factor, grouping=self.grouping)
|
||||
|
||||
def value_from_text(self, record, text, callback=None):
|
||||
field = record[self.attrs['name']]
|
||||
|
||||
Reference in new issue
Block a user