Пример #1
0
def populate_groups():
    transaction.begin()
    session = DBSession()
    contacts = [
        ('Clark', 'Kent', '601-555-1212', '*****@*****.**'),
        ('Bruce', 'Wayne', '601-911-2012', '*****@*****.**'),
        ]
                        
    if not session.query(Contact).count():
        with transaction.manager:
            for c in contacts:
                contact = Contact(*c)
                session.add(contact)
Пример #2
0
def populate_ticket_status():
    session = DBSession()
    tslist = ['opened',
              'started',
              'troubleshooting',
              'waiting parts',
              'waiting service',
              'writing code',
              'waiting client',
              'closed']
    with transaction.manager:
        for status in tslist:
            ts = TicketStatusType(status)
            session.add(ts)
Пример #3
0
 def _edit_form_submitted(self, name, page=None):
     edit_page = True
     session = DBSession()
     body = self.request.params['body']
     now = datetime.now()
     if page is None:
         edit_page = False
         page = SiteText(name, body, type='tutwiki')
         page.created = now
     else:
         page.content = body
     page.modified = now
     with transaction.manager:
         session.add(page)
     location = self.url(route='view_page', pagename=name)
     self.response = HTTPFound(location=location)        
Пример #4
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    settings['db.sessionmaker'] = DBSession
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    if True:
        import transaction
        Base.metadata.create_all(engine)
        with transaction.manager:
            model = MyModel(name='one', value=1)
            DBSession.add(model)
            initialize_sql(engine, [populate,
                                    populate_wiki,
                                    populate_feeds])
    session_factory = session_factory_from_settings(settings)
    root_factory = 'trumpet.resources.RootGroupFactory'
    request_factory = 'trumpet.request.AlchemyRequest'
    config = Configurator(settings=settings,
                          root_factory=root_factory,
                          request_factory=request_factory,
                          authentication_policy=authn_policy,
                          authorization_policy=authz_policy,
                          session_factory=session_factory)
    configure_static(config)
                          
    #config.include('pyramid_fanstatic')
    configure_base_layout(config)

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_view('phoebe.views.MainViewer', route_name='home',
                    renderer=basetemplate,
                    layout='base')
    
    configure_login(config)

    #configure_rssviewer(config, '/rssviewer')
    config.add_route('rssviewer', '/rssviewer/{context}/{feed}')
    config.add_view('trumpet.views.rssviewer.MainViewer',
                    route_name='rssviewer', layout='base')

    configure_wiki(config, '/wiki')

    return config.make_wsgi_app()
Пример #5
0
def populate_sitetext(directory):
    session = DBSession()
    import os
    if not os.path.isdir(directory):
        print "No Images to populate"
        return
    extension = '.md'
    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[:-len(extension)])
                pages.append((name, content))
    try:
        with transaction.manager:
            for name, content in pages:
                page = SiteText(name, content)
                page.type = 'tutwiki'
                session.add(page)
    except IntegrityError:
        session.rollback()
Пример #6
0
def populate_portacopy():
    session = DBSession()
    with transaction.manager:
        status = PortaCopyStatus('ready')
        session.add(status)
Пример #7
0
 def _add_new_page(self, name):
     session = DBSession()
     body = self.request.params['body']
     with transaction.manager:
         page = SiteText(name, body, type='tutwiki')
         session.add(page)