database float hack

master
informatic 2020-04-07 20:04:46 +02:00
parent 6b0366ca9e
commit f19a6bbf03
1 changed files with 5 additions and 0 deletions

View File

@ -5,6 +5,7 @@ from wtforms import TextAreaField
from formity.models import FaceshieldRequest, RequestChange, Status, PostalCode, ExternalUser
from spaceauth import current_user
import enum
import decimal
from sqlalchemy import inspect, func
from sqlalchemy.orm import class_mapper
from sqlalchemy.orm.attributes import get_history
@ -24,6 +25,10 @@ def get_diff(target, blacklist=['created', 'updated']):
if isinstance(state_before[attr.key], enum.Enum):
state_before[attr.key] = state_before[attr.key].name
state_after[attr.key] = getattr(target, attr.key)
if isinstance(state_before[attr.key], decimal.Decimal):
state_before[attr.key] = float(state_before[attr.key])
if isinstance(state_after[attr.key], decimal.Decimal):
state_after[attr.key] = float(state_after[attr.key])
if state_after[attr.key] == state_before[attr.key] or (state_after[attr.key] in ['', None] and state_before[attr.key] in ['', None]):
state_after.pop(attr.key)