def setup(self): try: new_attrs = {} new_attrs.update(self.attrs) new_attrs.update(self.do_get_dependencies()) self.obj = self.klass(**new_attrs) DBSession.add(self.obj) DBSession.flush() return self.obj except: DBSession.rollback() raise
def add_test_data(options): """ Load a few test points. @@This ought to have a 'from file' flag and data/config driven. """ from loafapp.model import DBSession, Spot from geoalchemy import WKTSpatialElement from loafapp.config.environment import load_environment import transaction eng = sqla.create_engine(get_app_dbstr()) DBSession.configure(bind=eng) wkt = "POINT(-80.3 38.2, -81.03 38.04)" spot1 = Spot(name="My Bike Route", width=6, geom=WKTSpatialElement(wkt)) wkt = "POINT(-79.8 38.5, -80.03 38.2)" spot2 = Spot(name="George Ave", width=8, geom=WKTSpatialElement(wkt)) DBSession.add_all([spot1, spot2]) DBSession.flush() transaction.commit()