Skip to content

Commit

Permalink
prettify the sqlalchemy object __repr__ statement, so its not printin…
Browse files Browse the repository at this point in the history
…g all of the objects. much more readable.
  • Loading branch information
stephanie committed May 5, 2017
1 parent d79e8bc commit 9e0fd51
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 49 deletions.
66 changes: 18 additions & 48 deletions odm2api/ODM2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
BigIntegerType = BigIntegerType.with_variant(mysql.BIGINT(), 'mysql')





def is_hex(s):
try:
int(s, base=16)
Expand Down Expand Up @@ -1212,6 +1209,7 @@ class MethodCitations(Base):
RelationshipTypeCV = Column('relationshiptypecv', ForeignKey(CVRelationshipType.Name), nullable=False,
index=True)
CitationID = Column('citationid', ForeignKey(Citations.CitationID), nullable=False)

CitationObj = relationship(Citations)
MethodObj = relationship(Methods)

Expand Down Expand Up @@ -1278,7 +1276,6 @@ class RelatedResults(Base):
# ################################################################################
class PointCoverageResults(Results):


ResultID = Column('resultid', ForeignKey(Results.ResultID), primary_key=True)
ZLocation = Column('zlocation', Float(53))
ZLocationUnitsID = Column('zlocationunitsid', ForeignKey(Units.UnitsID))
Expand All @@ -1296,12 +1293,11 @@ class PointCoverageResults(Results):
IntendedYSpacingUnitsObj = relationship(Units, primaryjoin='PointCoverageResults.IntendedYSpacingUnitsID == Units.UnitsID')
SpatialReferenceObj = relationship(SpatialReferences)
ZLocationUnitsObj = relationship(Units, primaryjoin='PointCoverageResults.ZLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='PointCoverageResults.ResultID == Results.ResultID')
__mapper_args__ = {'polymorphic_identity':'Point coverage'}

__mapper_args__ = {'polymorphic_identity': 'Point coverage'}

class ProfileResults(Results):

class ProfileResults(Results):

ResultID = Column('resultid', ForeignKey(Results.ResultID), primary_key=True)
XLocation = Column('xlocation', Float(53))
Expand All @@ -1321,12 +1317,11 @@ class ProfileResults(Results):
SpatialReferenceObj = relationship(SpatialReferences)
XLocationUnitsObj = relationship(Units, primaryjoin='ProfileResults.XLocationUnitsID == Units.UnitsID')
YLocationUnitsObj = relationship(Units, primaryjoin='ProfileResults.YLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='ProfileResults.ResultID == Results.ResultID')
__mapper_args__ = {'polymorphic_identity':'Profile Coverage'}

__mapper_args__ = {'polymorphic_identity': 'Profile Coverage'}

class CategoricalResults(Results):

class CategoricalResults(Results):

ResultID = Column('resultid', ForeignKey(Results.ResultID), primary_key=True)
XLocation = Column('xlocation', Float(53))
Expand All @@ -1343,8 +1338,7 @@ class CategoricalResults(Results):
YLocationUnitsObj = relationship(Units, primaryjoin='CategoricalResults.YLocationUnitsID == Units.UnitsID')
ZLocationUnitsObj = relationship(Units, primaryjoin='CategoricalResults.ZLocationUnitsID == Units.UnitsID')

# ResultObj = relationship(Results, primaryjoin='CategoricalResults.ResultID == Results.ResultID')
__mapper_args__ = {'polymorphic_identity':'Category coverage'}
__mapper_args__ = {'polymorphic_identity':' Category coverage'}


class TransectResults(Results):
Expand All @@ -1365,12 +1359,11 @@ class TransectResults(Results):
IntendedTransectSpacingUnitsObj = relationship(Units, primaryjoin='TransectResults.IntendedTransectSpacingUnitsID == Units.UnitsID')
SpatialReferenceObj = relationship(SpatialReferences)
ZLocationUnitsObj = relationship(Units, primaryjoin='TransectResults.ZLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='TransectResults.ResultID == Results.ResultID')
__mapper_args__ = {'polymorphic_identity':'Transect Coverage'}

__mapper_args__ = {'polymorphic_identity': 'Transect Coverage'}

class SpectraResults(Results):

class SpectraResults(Results):

ResultID = Column('resultid', ForeignKey(Results.ResultID), primary_key=True)
XLocation = Column('xlocation', Float(53))
Expand All @@ -1390,7 +1383,7 @@ class SpectraResults(Results):
XLocationUnitsObj = relationship(Units, primaryjoin='SpectraResults.XLocationUnitsID == Units.UnitsID')
YLocationUnitsObj = relationship(Units, primaryjoin='SpectraResults.YLocationUnitsID == Units.UnitsID')
ZLocationUnitsObj = relationship(Units, primaryjoin='SpectraResults.ZLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='SpectraResults.ResultID == Results.ResultID')

__mapper_args__ = {'polymorphic_identity':'Spectra coverage'}


Expand All @@ -1409,14 +1402,13 @@ class TimeSeriesResults(Results):
AggregationStatisticCV = Column('aggregationstatisticcv', ForeignKey(CVAggregationStatistic.Name),
nullable=False, index=True)

# ResultObj = relationship(Results)
IntendedTimeSpacingUnitsObj = relationship(Units,
primaryjoin='TimeSeriesResults.IntendedTimeSpacingUnitsID == Units.UnitsID')
primaryjoin='TimeSeriesResults.IntendedTimeSpacingUnitsID == Units.UnitsID')
SpatialReferenceObj = relationship(SpatialReferences)
XLocationUnitsObj = relationship(Units, primaryjoin='TimeSeriesResults.XLocationUnitsID == Units.UnitsID')
YLocationUnitsObj = relationship(Units, primaryjoin='TimeSeriesResults.YLocationUnitsID == Units.UnitsID')
ZLocationUnitsObj = relationship(Units, primaryjoin='TimeSeriesResults.ZLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='TimeSeriesResults.ResultID == Results.ResultID')

__mapper_args__ = {'polymorphic_identity':'Time series coverage'}


Expand All @@ -1440,13 +1432,12 @@ class SectionResults(Results):
IntendedZSpacingUnitsObj = relationship(Units, primaryjoin='SectionResults.IntendedZSpacingUnitsID == Units.UnitsID')
SpatialReferenceObj = relationship(SpatialReferences)
YLocationUnitsObj = relationship(Units, primaryjoin='SectionResults.YLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='SectionResults.ResultID == Results.ResultID')

__mapper_args__ = {'polymorphic_identity':'Section coverage'}


class TrajectoryResults(Results):


ResultID = Column('resultid', ForeignKey(Results.ResultID), primary_key=True)
SpatialReferenceID = Column('spatialreferenceid', ForeignKey(SpatialReferences.SpatialReferenceID))
IntendedTrajectorySpacing = Column('intendedtrajectoryspacing', Float(53))
Expand All @@ -1460,13 +1451,12 @@ class TrajectoryResults(Results):
IntendedTrajectorySpacingUnitsObj = relationship(Units,
primaryjoin='TrajectoryResults.IntendedTrajectorySpacingUnitsID == Units.UnitsID')
SpatialReferenceObj = relationship(SpatialReferences)
# ResultObj = relationship(Results, primaryjoin='TrajectoryResults.ResultID == Results.ResultID')

__mapper_args__ = {'polymorphic_identity':'Trajectory coverage'}


class MeasurementResults(Results):


ResultID = Column('resultid', ForeignKey(Results.ResultID), primary_key=True)
XLocation = Column('xlocation', Float(53))
XLocationUnitsID = Column('xlocationunitsid', ForeignKey(Units.UnitsID))
Expand All @@ -1488,7 +1478,7 @@ class MeasurementResults(Results):
XLocationUnitsObj = relationship(Units, primaryjoin='MeasurementResults.XLocationUnitsID == Units.UnitsID')
YLocationUnitsObj = relationship(Units, primaryjoin='MeasurementResults.YLocationUnitsID == Units.UnitsID')
ZLocationUnitsObj = relationship(Units, primaryjoin='MeasurementResults.ZLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='MeasurementResults.ResultID == Results.ResultID')

__mapper_args__ = {'polymorphic_identity':'Measurement'}


Expand Down Expand Up @@ -1517,7 +1507,6 @@ class MeasurementResultValues(Base):

class PointCoverageResultValues(Base):


ValueID = Column('valueid', BigIntegerType, primary_key=True)
ResultID = Column('resultid', ForeignKey(PointCoverageResults.ResultID), nullable=False)
DataValue = Column('datavalue', BigInteger, nullable=False)
Expand Down Expand Up @@ -1634,7 +1623,6 @@ def list_repr(self):

class TrajectoryResultValues(Base):


ValueID = Column('valueid', BigIntegerType, primary_key=True)
ResultID = Column('resultid', ForeignKey(TrajectoryResults.ResultID), nullable=False)
DataValue = Column('datavalue', Float(53), nullable=False)
Expand Down Expand Up @@ -1665,7 +1653,6 @@ class TrajectoryResultValues(Base):

class TransectResultValues(Base):


ValueID = Column('valueid', BigIntegerType, primary_key=True)
ResultID = Column('resultid', ForeignKey(TransectResults.ResultID), nullable=False)
DataValue = Column('datavalue', Float(53), nullable=False)
Expand Down Expand Up @@ -1695,7 +1682,6 @@ class TransectResultValues(Base):

class CategoricalResultValueAnnotations(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ValueID = Column('valueid', BigInteger, ForeignKey(CategoricalResultValues.ValueID), nullable=False)
AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False)
Expand All @@ -1706,7 +1692,6 @@ class CategoricalResultValueAnnotations(Base):

class MeasurementResultValueAnnotations(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ValueID = Column('valueid', BigInteger, ForeignKey(MeasurementResultValues.ValueID), nullable=False)
AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False)
Expand All @@ -1717,7 +1702,6 @@ class MeasurementResultValueAnnotations(Base):

class PointCoverageResultValueAnnotations(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ValueID = Column('valueid', BigInteger, ForeignKey(PointCoverageResultValues.ValueID), nullable=False)
AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False)
Expand All @@ -1738,7 +1722,6 @@ class ProfileResultValueAnnotations(Base):

class SectionResultValueAnnotations(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ValueID = Column('valueid', BigInteger, ForeignKey(SectionResultValues.ValueID), nullable=False)
AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False)
Expand All @@ -1749,7 +1732,6 @@ class SectionResultValueAnnotations(Base):

class SpectraResultValueAnnotations(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ValueID = Column('valueid', BigInteger, ForeignKey(SpectraResultValues.ValueID), nullable=False)
AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False)
Expand All @@ -1760,7 +1742,6 @@ class SpectraResultValueAnnotations(Base):

class TimeSeriesResultValueAnnotations(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ValueID = Column('valueid', BigInteger, ForeignKey(TimeSeriesResultValues.ValueID), nullable=False)
AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False)
Expand Down Expand Up @@ -1792,28 +1773,19 @@ class TransectResultValueAnnotations(Base):
def _changeSchema(schema):
import inspect
import sys
#get a list of all of the classes in the module
# get a list of all of the classes in the module
clsmembers = inspect.getmembers(sys.modules[__name__],
lambda member: inspect.isclass(member) and member.__module__ == __name__)

for name, Tbl in clsmembers:
import sqlalchemy.ext.declarative.api as api

if isinstance(Tbl, api.DeclarativeMeta):
#check to see if the schema is already set correctly
if Tbl.__table__.schema ==schema:
# check to see if the schema is already set correctly
if Tbl.__table__.schema == schema:
return
Tbl.__table__.schema = schema
Tbl.__table_args__["schema"]=schema


# def _changeSchema(schema):
# # check to see if the schema is already set correctly
# # if Base.__table__.schema == schema:
# # return
# # Base.__table__.schema = schema
# Base.__table_args__["schema"] = schema
# print schema
Tbl.__table_args__["schema"]= schema


def _getSchema(engine):
Expand All @@ -1830,8 +1802,6 @@ def _getSchema(engine):
def setSchema(engine):

s = _getSchema(engine)
# if s is None:
# s = ''
_changeSchema(s)


6 changes: 5 additions & 1 deletion odm2api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def __eq__(self, other):
return self.__dict__ == other.__dict__

def __repr__(self):
return "<%s(%s)>" % (self.__class__.__name__, str(self.__dict__))
valuedict = self.__dict__.copy()
for v in valuedict.keys():
if "obj" in v.lower():
del valuedict[v]
return "<%s(%s)>" % (self.__class__.__name__, str(valuedict))


from sqlalchemy.ext.declarative import declarative_base
Expand Down

0 comments on commit 9e0fd51

Please sign in to comment.