]>
git.datanom.net - pwp.git/blob - app/DB/baseorm.py
3 class QueryException(Exception):
6 class OrmSubject(object, metaclass
=abc
.ABCMeta
):
8 def addObserver(self
, ormObserver
):
12 def removeObserver(self
, ormObserver
):
16 def notify(self
, subject
):
19 class Observer(object, metaclass
=abc
.ABCMeta
):
21 def update(self
, subject
):
24 class BaseOrm(OrmSubject
):
30 def addObserver(self
, ormObserver
):
31 print("Added: {0}".format(ormObserver
))
32 self
.__observers
.append(ormObserver
)
34 def removeObserver(self
, ormObserver
):
35 self
.__observers
.remove(ormObserver
)
37 def notify(self
, object):
38 for observer
in self
.__observers
:
39 observer
.update(object)
42 def query(cls
, **kwargs
):
46 if hasattr(cls
, '__tablename__'):
47 table
= cls
.__tablename
__
50 o
= db
.query(table
, **kwargs
)
51 if table
.lower() == 'user':
53 objects
.append(cls(user
[1], user
[2], user
[3], user
[4], user
[0]))
54 elif table
.lower() == 'portfolio':
56 user
= db
.query('user', id = portfolio
[2])[0]
57 objects
.append(cls(portfolio
[1], user
, portfolio
[3], portfolio
[4], portfolio
[0]))
59 raise QueryException("{0}: Missing at least one query parameter".format(cls
))
67 for k
, v
in self
.__oldValues
.items():
78 self
.__oldValues
['id'] = self
.id
79 except AttributeError:
This page took 0.115304 seconds and 6 git commands to generate.