def setUp(self): self.config = testing.setUp() from sqlalchemy import create_engine engine = create_engine('sqlite://') from .models import ( Base, MyModel, ) DBSession.configure(bind=engine)
def setUp(self): self.config = testing.setUp() from sqlalchemy import create_engine engine = create_engine('sqlite://') from .models import ( Base, MyModel, ) DBSession.configure(bind=engine) Base.metadata.create_all(engine) with transaction.manager: model = MyModel(name='one', value=55) DBSession.add(model)
def main(argv=sys.argv): if len(argv) < 2: usage(argv) config_uri = argv[1] options = parse_vars(argv[2:]) setup_logging(config_uri) settings = get_appsettings(config_uri, options=options) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) Base.metadata.create_all(engine) with transaction.manager: model = MyModel(name='one', value=1) DBSession.add(model) populate_usergroups(DBSession)
def my_view(request): try: one = DBSession.query(MyModel).filter(MyModel.name == 'one').first() except DBAPIError: return Response(conn_err_msg, content_type='text/plain', status_int=500) return {'one': one, 'project': 'paella'}
def populate_images(imagedir='images'): import os if not os.path.isdir(imagedir): print "No Images to populate" return session = DBSession() from trumpet.managers.admin.images import ImageManager im = ImageManager(session) for basename in os.listdir(imagedir): filename = os.path.join(imagedir, basename) imgfile = file(filename) im.add_image(basename, imgfile)
def populate_sitetext(directory): session = DBSession() import os if not os.path.isdir(directory): print "No Images to populate" return extension = '.md' elength = len(extension) pages = list() for basename in os.listdir(directory): if basename.endswith(extension): filename = os.path.join(directory, basename) if os.path.isfile(filename): content = file(filename).read() name = os.path.basename(filename[:-elength]) pages.append((name, content)) try: with transaction.manager: for name, content in pages: page = SiteText(name, content) page.type = 'wiki' session.add(page) except IntegrityError: session.rollback()
def tearDown(self): DBSession.remove() testing.tearDown()