A webapp/form for people to join pEp coop. Fork of Cultural Commons Collecting Society (C3S) SCE
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SqliteDecimal.py 869B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/python
  2. # the "correct" place for this would be alembic/
  3. # but alembic can't be a package because namespace collision,
  4. # so please leave this here for the time being :/
  5. import sqlalchemy.types as types
  6. class SqliteDecimal(types.TypeDecorator):
  7. """
  8. Type decorator for persisting Decimal (currency values)
  9. TODO: Use standard SQLAlchemy Decimal
  10. when a database is used which supports it.
  11. """
  12. impl = types.String
  13. def load_dialect_impl(self, dialect):
  14. return dialect.type_descriptor(types.VARCHAR(100))
  15. def process_bind_param(self, value, dialect):
  16. if value is not None:
  17. return str(value)
  18. else:
  19. return None
  20. def process_result_value(self, value, dialect):
  21. if value is not None and value != '':
  22. return Decimal(value)
  23. else:
  24. return None