Commit edf164b7 authored by echel0n's avatar echel0n
Browse files

Replaced AttrsDict requirement with class code

parent a750b748
......@@ -6,7 +6,6 @@ appdirs==1.4.4
APScheduler==3.6.3
arrow==0.15.8
asn1crypto==1.4.0
attrdict==2.0.1
attrs==19.3.0
babelfish==0.5.5
beautifulsoup4==4.10.0
......
......@@ -29,7 +29,6 @@ import alembic.script
import sqlalchemy
from alembic.runtime.migration import MigrationContext
from alembic.script import ScriptDirectory
from attrdict import AttrDict
from sqlalchemy import create_engine, event, inspect, MetaData, Index, TypeDecorator
from sqlalchemy.engine import Engine, reflection, Row
from sqlalchemy.exc import OperationalError
......@@ -123,9 +122,18 @@ class ContextSession(sqlalchemy.orm.Session):
class SRDatabaseBase(object):
def as_dict(self):
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
return {c.key: getattr(self, c.key) for c in inspect(self).mapper.column_attrs}
def as_attrdict(self):
class AttrDict:
def __init__(self, in_dict: dict):
assert isinstance(in_dict, dict)
for key, val in in_dict.items():
if isinstance(val, (list, tuple)):
setattr(self, key, [AttrDict(x) if isinstance(x, dict) else x for x in val])
else:
setattr(self, key, AttrDict(val) if isinstance(val, dict) else val)
return AttrDict(self.as_dict())
def update(self, **kwargs):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment