""" Paramecio2fm is a series of wrappers for Flask, mako and others and construct a simple headless cms. Copyright (C) 2023 Antonio de la Rosa Caballero This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . """ from paramecio2.libraries.db.corefields import DecimalField class PercentField(DecimalField): """Field used for save percent values from 0 to 100.""" 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