Пример #1
0
    def view_page(self):
        pagename = self.request.matchdict['pagename']
        session = DBSession()
        page = session.query(SiteText).filter_by(name=pagename).first()
        if page is None:
            location = self.url(route='add_page', pagename=pagename)
            self.response = HTTPFound(location=location)
            return

        def check(match):
            word = match.group(1)
            exists = session.query(SiteText).filter_by(name=word).all()
            if exists:
                url = self.url(route='view_page', pagename=word)
            else:
                url = self.url(route='add_page', pagename=word)
            return self._anchor(url, word)
        # this is a sad "markup" system
        # good for a tutorial, but needs to be better
        # for actual use.
        content = render_rst(page.content)
        content = wikiwords.sub(check, content)

        edit_url = self.url(route='edit_page', pagename=pagename)
        # We should check the session here
        # this is from tutorial, but we need better
        # solution.
        #logged_in = authenticated_userid(self.request)
        l = self.layout
        l.title = "Wiki: %s" % page.name
        l.header = page.name
        l.content = content
        l.footer = self._anchor(edit_url, "Edit Page")
Пример #2
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
    Base.metadata.create_all(engine)
    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("plum.views.MainViewer", route_name="home", renderer=basetemplate, layout="base")

    configure_login(config)
    configure_rssviewer(config, "/rssviewer")
    configure_wiki(config, "/wiki")

    return config.make_wsgi_app()
Пример #3
0
 def list_pages(self):
     session = DBSession()
     #pages = session.query(Page).all()
     pages = session.query(SiteText).filter_by(type='tutwiki').all()
     pagelist = []
     for page in pages:
         url = self.url(route='view_page', pagename=page.name)
         anchor = self._anchor(url, page.name)
         pagelist.append('<li>%s</li>' % anchor)
     ul = '<ul>%s</ul>' % '\n'.join(pagelist)
     self.layout.content = ul
Пример #4
0
 def edit_page(self):
     name = self.request.matchdict['pagename']
     session = DBSession()
     #page = session.query(Page).filter_by(name=name).one()
     page = session.query(SiteText).filter_by(name=name).one()
     if 'form.submitted' in self.request.params:
         self._edit_form_submitted(name, page=page)
         return
     save_url = self.url(route='edit_page', pagename=name)
     #logged_in = authenticated_userid(self.request)
     self.layout.content = EDIT_PAGE_FORM % (save_url, page.content)
Пример #5
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)
    populate_users()
Пример #6
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
    Base.metadata.create_all(engine)
    initialize_sql(engine, [populate,
                            populate_sitetext,
                            populate_wiki,
                            populate_feeds,
                            populate_ticket_status])
    root_factory = 'trumpet.resources.RootGroupFactory'
    request_factory = 'trumpet.request.AlchemyRequest'
    session_factory = session_factory_from_settings(settings)
    config = Configurator(settings=settings,
                          root_factory=root_factory,
                          request_factory=request_factory,
                          authentication_policy=authn_policy,
                          authorization_policy=authz_policy)
    config.set_session_factory(session_factory)

    configure_static(config)
    configure_base_layout(config)
    
    config.add_static_view('static', 'kermas:static', cache_max_age=3600)

    config.add_route('home', '/')
    add_view(config, 'kermas.views.main.MainViewer', 'home')

    config.add_route('status', '/status/{context}')
    add_view(config, 'kermas.views.eddie.status.StatusViewer', 'status')

    config.add_route('portacopy', '/portacopy/{context}/{id}')
    config.add_view('kermas.views.portacopy.PortaCopyViewer',
                    route_name='portacopy',
                    renderer=basetemplate,
                    layout='base',
                    permission='admin')

    
    configure_login(config)
    configure_admin(config)
    configure_sitecontent(config)

    configure_wiki(config, '/wiki')
    configure_rssviewer(config, '/rssviewer')
    configure_consultant(config)
    
    
    #config.scan()
    return config.make_wsgi_app()
Пример #7
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
    Base.metadata.create_all(engine)
    initialize_sql(engine, [populate, populate_wiki, populate_feeds, populate_images, populate_sitetext])
    session_factory = session_factory_from_settings(settings)
    root_factory = "trumpet.resources.RootGroupFactory"
    request_factory = "trumpet.request.AlchemyRequest"
    # setup authn and authz
    appname = "demo"
    secret = settings["%s.authn.secret" % appname]
    cookie = settings["%s.authn.cookie" % appname]
    timeout = int(settings["%s.authn.timeout" % appname])
    authn_policy, authz_policy = make_authn_authz_policies(
        secret, cookie, callback=authenticate, timeout=timeout, tkt=False
    )

    config = Configurator(
        settings=settings,
        root_factory=root_factory,
        request_factory=request_factory,
        authentication_policy=authn_policy,
        authorization_policy=authz_policy,
        session_factory=session_factory,
    )
    config.include("cornice")
    configure_frontdoor(config)
    configure_static(config)
    configure_base_layout(config)

    config.add_static_view("static", "static", cache_max_age=3600)
    config.add_route("home", "/")
    config.add_view("trumpet.views.frontdoor.FrontDoorView", route_name="home")

    # configure_login(config)
    # configure_rssviewer(config, '/rssviewer')
    # configure_wiki(config, '/wiki')
    # configure_admin(config)
    # configure_sitecontent(config)
    # configure_consultant(config)
    config.scan("trumpet.views.rest.users")
    config.scan("trumpet.views.rest.webview")
    config.scan("trumpet.views.rest.sitecontent")
    config.scan("trumpet.views.rest.simplerss")

    configure_webviews(config)

    return config.make_wsgi_app()
Пример #8
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)
Пример #9
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)
Пример #10
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
    Base.metadata.create_all(engine)
    initialize_sql(engine, [populate,
                            populate_wiki,
                            populate_feeds,
                            populate_images,
                            populate_sitetext,])
    session_factory = session_factory_from_settings(settings)
    root_factory = 'trumpet.resources.RootGroupFactory'
    request_factory = 'trumpet.request.AlchemyRequest'
    # setup authn and authz
    appname = 'demo'
    secret = settings['%s.authn.secret' % appname]
    cookie = settings['%s.authn.cookie' % appname]
    timeout = int(settings['%s.authn.timeout' % appname])
    authn_policy, authz_policy = make_authn_authz_policies(
        secret, cookie, callback=authenticate,
        timeout=timeout, tkt=False)

    config = Configurator(settings=settings,
                          root_factory=root_factory,
                          request_factory=request_factory,
                          authentication_policy=authn_policy,
                          authorization_policy=authz_policy,
                          session_factory=session_factory
                          )
    config.include('cornice')
    configure_base_views(config)
    configure_frontdoor(config)
    
    config.add_route('home', '/')
    config.add_view('trumpet.views.frontdoor.FrontDoorView',
                    route_name='home',)

    config.scan('trumpet.views.rest.base')
    config.scan('trumpet.views.rest.users')
    config.scan('trumpet.views.rest.webview')
    config.scan('trumpet.views.rest.sitecontent')
    config.scan('trumpet.views.rest.simplerss')


    
    return config.make_wsgi_app()
Пример #11
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)        
Пример #12
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()
Пример #13
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()
Пример #14
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    trfsession = make_truffula_session(settings)
    settings['trfdb.sessionmaker'] = trfsession

    settings['github_client'] = make_github_client(settings)
    
    settings['db.usermodel'] = User
    settings['db.sessionmaker'] = DBSession
    config = kotti.base_configure(global_config, **settings)
    engine = engine_from_config(settings, 'sqlalchemy.')
    kotti.resources.initialize_sql(engine)
    settings['db.usernamefield'] = 'username'


    
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
    root_factory = 'trumpet.resources.RootGroupFactory'
    request_factory = 'tenyu.request.TenyuRequest'
    #config = Configurator(settings=settings,
    #                      root_factory=root_factory,
    #                      request_factory=request_factory,
    #                      authentication_policy=authn_policy,
    #                      authorization_policy=authz_policy)
    
    config.include('cornice')
    config.include('pyramid_beaker')
    #config.include('pyramid_celery')
    config.configure_celery(global_config['__file__'])
    
    #config.add_static_view('static', 'static', cache_max_age=3600)
    client_view = 'tenyu.views.client.ClientView'
    config.add_route('home', '/tenyu')
    config.add_route('apps', '/app/{appname}')
    config.add_view(client_view, route_name='home')
    config.add_view(client_view, route_name='apps')
    #config.add_view(client_view, name='login')
    #config.add_view(client_view, name='logout')
    # FIXME - get client view to understand it hit forbidden
    #config.add_view('tenyu.views.client.forbidden_view',
    #                context='pyramid.httpexceptions.HTTPForbidden')
    config.add_view(client_view, name='admin', permission='admin')
    # static assets
    serve_static_assets = False
    if 'serve_static_assets' in settings and settings['serve_static_assets'].lower() == 'true':
        serve_static_assets = True

    if serve_static_assets:
        add_static_views(config, settings)
        
    config.add_route('repos_calendar', '/rest/v0/main/ghub/repocalendar')
    config.add_view('tenyu.views.rest.ghub.RepoCalendarView',
                    route_name='repos_calendar',
                    renderer='json',)
        
    config.scan('tenyu.views.rest.currentuser')
    config.scan('tenyu.views.rest.useradmin')
    config.scan('tenyu.views.rest.sitetext')
    config.scan('tenyu.views.rest.vtstuff')
    config.scan('tenyu.views.rest.wikipages')
    config.scan('tenyu.views.rest.ghub')
    config.scan('tenyu.views.rest.gitannex')
    config.scan('tenyu.views.rest.siteimages')
    config.scan('tenyu.views.rest.webobjects')
    config.scan('tenyu.views.rest.dbadmin')
    config.scan('tenyu.views.rest.celerytasks')

    siteimages_resource = settings['default.siteimages.resource']
    siteimages_path = settings['default.siteimages.directory']
    config.add_static_view('siteimages', path=siteimages_path)
    
    if 'default.vtimages.directory' in settings:
        vrsrc = settings['default.vtimages.resource']
        vpath = settings['default.vtimages.directory']
        config.add_static_view(vrsrc, path=vpath)

    return config.make_wsgi_app()
Пример #15
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)
Пример #16
0
def populate_portacopy():
    session = DBSession()
    with transaction.manager:
        status = PortaCopyStatus('ready')
        session.add(status)
Пример #17
0
#!/usr/bin/env python
import os
import sys

import transaction
from sqlalchemy import engine_from_config
from sqlalchemy.orm import sessionmaker
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound

from trumpet.models.base import Base, DBSession

from david.models.main import Address, Contact, Location
from david.models.main import Client, ClientContact

dburl = "sqlite:///%s/david.sqlite" % os.getcwd()

settings = {"sqlalchemy.url": dburl}
engine = engine_from_config(settings)
DBSession.configure(bind=engine)
Base.metadata.bind = engine
Base.metadata.create_all(engine)


s = DBSession()