Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
more thoughts on the stored query presenter - can retrieve and write …
Browse files Browse the repository at this point in the history
…the data from and to the meta table.

#36
  • Loading branch information
mfrasca committed Jan 2, 2016
1 parent b12c67b commit c3b9c62
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions bauble/plugins/plants/stored_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
from bauble import db, meta


def get_or_create(session, model, **kwargs):
instance = session.query(model).filter_by(**kwargs).first()
if instance:
return instance
else:
instance = model(**kwargs)
session.add(instance)
session.flush()
return instance


class StoredQueries(object):
def __init__(self):
self.__label = [''] * 11
Expand All @@ -44,10 +55,15 @@ def __repr__(self):
self.page, self.__label[1:], self.__tooltip[1:], self.__query[1:])

def save(self):
ssn = db.Session()
for index in range(1, 11):
obj = get_or_create(ssn, meta.BaubleMeta,
name=u'stqr_%02d' % index)
if self.__label[index] == '':
continue
print 'stqr_%02d' % index, self[index]
ssn.delete(obj)
obj.value = self[index]
ssn.commit()
ssn.close()

def __getitem__(self, index):
return u'%s:%s:%s' % (self.__label[index],
Expand Down

0 comments on commit c3b9c62

Please sign in to comment.