Added moneyfield and percentfield

This commit is contained in:
Antonio de la Rosa 2017-06-22 02:49:57 +02:00
parent 52d5e3e133
commit 35b0eda95a
2 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,26 @@
from paramecio.cromosoma.corefields import FloatField
from decimal import Decimal, getcontext
from locale import format
getcontext().prec=2
class MoneyField(FloatField):
def __init__(self, name, required=False):
super().__init__(name, 11, required)
def check(self, value):
value=Decimal(value)
return value
def show_formatted(self, value):
return format('%.2f', Decimal(value), grouping=True)
@staticmethod
def format_money(value):
return format('%.2f', Decimal(value), grouping=True)

View file

@ -0,0 +1,22 @@
from paramecio.cromosoma.corefields import IntegerField
class PercentField(IntegerField):
def __init__(self, name, required=False):
super().__init__(name, 2, required)
def check(self, value):
try:
value=int(value)
if value<0:
value=0
if value>100:
value=100
except:
value=0
return value