예제 #1
0
파일: tests.py 프로젝트: pombredanne/paella
 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)
예제 #2
0
파일: tests.py 프로젝트: pombredanne/paella
 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)
예제 #3
0
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)
예제 #4
0
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'}
예제 #5
0
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)
예제 #6
0
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()
예제 #7
0
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'}
예제 #8
0
파일: tests.py 프로젝트: pombredanne/paella
 def tearDown(self):
     DBSession.remove()
     testing.tearDown()