def _to_python(self, value): from formbar.converters import to_manytoone, to_integer rel = self._sa_property.mapper.class_ if value in ("", None): return None value = to_integer(value) db = self._form._dbsession selected = getattr(self._form._item, self.name) return to_manytoone(rel, value, db, selected)
def deserialize(value, datatype): """Very simple helper function which returns a python version of the given serialized value.""" if datatype in ["varchar", "text"]: return value elif value in ["", None]: return None elif datatype == "integer": return converters.to_integer(value) elif datatype == "float": return converters.to_float(value) elif datatype == "datetime": # Interval fields are implemented as DATETIME # See http://docs.sqlalchemy.org/en/latest/core/type_basics.html#sqlalchemy.types.Interval # Check if we have a interval here iv = re.compile(u"^\d{1,2}:\d{1,2}:\d{1,2}") if iv.match(value): t = datetime.datetime.strptime(value, "%H:%M:%S") return datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second) # We need the configured timezone to convert the datetime into # the correct timezone. if get_current_registry().settings: timezone = get_current_registry().settings.get("app.timezone") else: timezone = None return converters.to_datetime(value, locale=None, timezone=timezone) elif datatype == "date": return converters.to_date(value) elif re_char_match.match(datatype): # UUID return value elif datatype == "blob": return base64.b64decode(value) elif datatype == "boolean": # In case of imports from a JSON file the value is already of # type boolean. if isinstance(value, bool): return value else: converters.to_boolean(value) else: raise TypeError("{} is not supported".format(datatype))
def _to_python(self, value): from formbar.converters import to_integer if isinstance(value, list): return [to_integer(e) for e in value] return to_integer(value)
def _to_python(self, value): from formbar.converters import to_integer return to_integer(value)