Skip to content

Commit

Permalink
Merge pull request #90 from ral-facilities/89_use_json
Browse files Browse the repository at this point in the history
Correct response types
  • Loading branch information
keiranjprice101 authored Oct 14, 2019
2 parents 6ae5616 + d5f0e31 commit 5b1f878
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions common/models/db_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import enum

from datetime import datetime
from sqlalchemy import Index, Column, BigInteger, String, DateTime, ForeignKey, Integer, Float, FetchedValue, \
TypeDecorator
TypeDecorator, Boolean
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy.orm.collections import InstrumentedList
Expand Down Expand Up @@ -48,7 +49,8 @@ def to_dict(self):
"""
dictionary = {}
for column in self.__table__.columns:
dictionary[column.name] = str(getattr(self, column.name))
attribute = getattr(self, column.name)
dictionary[column.name] = str(attribute) if isinstance(attribute, datetime) else attribute
return dictionary

def to_nested_dict(self, includes):
Expand Down Expand Up @@ -318,7 +320,7 @@ class DATASET(Base, EntityHelper):
)

ID = Column(BigInteger, primary_key=True)
COMPLETE = Column(Integer, nullable=False, server_default=FetchedValue())
COMPLETE = Column(Boolean, nullable=False, server_default=FetchedValue())
CREATE_ID = Column(String(255), nullable=False)
CREATE_TIME = Column(DateTime, nullable=False)
DESCRIPTION = Column(String(255))
Expand Down Expand Up @@ -640,15 +642,15 @@ class ValueTypeEnum(enum.Enum):
STRING = 2

ID = Column(BigInteger, primary_key=True)
APPLICABLETODATACOLLECTION = Column(Integer, server_default=FetchedValue())
APPLICABLETODATAFILE = Column(Integer, server_default=FetchedValue())
APPLICABLETODATASET = Column(Integer, server_default=FetchedValue())
APPLICABLETOINVESTIGATION = Column(Integer, server_default=FetchedValue())
APPLICABLETOSAMPLE = Column(Integer, server_default=FetchedValue())
APPLICABLETODATACOLLECTION = Column(Boolean, server_default=FetchedValue())
APPLICABLETODATAFILE = Column(Boolean, server_default=FetchedValue())
APPLICABLETODATASET = Column(Boolean, server_default=FetchedValue())
APPLICABLETOINVESTIGATION = Column(Boolean, server_default=FetchedValue())
APPLICABLETOSAMPLE = Column(Boolean, server_default=FetchedValue())
CREATE_ID = Column(String(255), nullable=False)
CREATE_TIME = Column(DateTime, nullable=False)
DESCRIPTION = Column(String(255))
ENFORCED = Column(Integer, server_default=FetchedValue())
ENFORCED = Column(Boolean, server_default=FetchedValue())
MAXIMUMNUMERICVALUE = Column(Float(asdecimal=True))
MINIMUMNUMERICVALUE = Column(Float(asdecimal=True))
MOD_ID = Column(String(255), nullable=False)
Expand All @@ -657,7 +659,7 @@ class ValueTypeEnum(enum.Enum):
UNITS = Column(String(255), nullable=False)
UNITSFULLNAME = Column(String(255))
VALUETYPE = Column(EnumAsInteger(ValueTypeEnum), nullable=False)
VERIFIED = Column(Integer, server_default=FetchedValue())
VERIFIED = Column(Boolean, server_default=FetchedValue())
FACILITY_ID = Column(ForeignKey('FACILITY.ID'), nullable=False)

FACILITY = relationship('FACILITY', primaryjoin='PARAMETERTYPE.FACILITY_ID == FACILITY.ID',
Expand Down

0 comments on commit 5b1f878

Please sign in to comment.