Ejemplo n.º 1
0
def includeme(config):
    settings = config.registry.settings

    # add default values for some global settings
    templates_dir = list(filter(
        None, settings.get('templates_dir', '').splitlines()))
    templates_dir.append('pygall:templates')
    settings['mako.directories'] = templates_dir
    if 'photos_dir' not in settings:
        settings['photos_dir'] = 'photos'
    if 'upload_dir' not in settings:
        settings['upload_dir'] = 'upload'
    allow_cdn = asbool(settings.get('allow_cdn', 'false'))
    settings['allow_cdn'] = allow_cdn
    ip.set_dest_dir(settings['photos_dir'])
    mkdir_p(settings['upload_dir'])

    init_security(settings)
    init_resources(settings)

    authentication_policy = AuthTktAuthenticationPolicy(
            settings['authtkt_secret'], callback=groupfinder)
    authorization_policy = ACLAuthorizationPolicy()

    config.add_settings(settings)
    config.set_root_factory(RootFactory)
    config.set_locale_negotiator(default_locale_negotiator)
    config.set_authentication_policy(authentication_policy)
    config.set_authorization_policy(authorization_policy)

    # initialize database
    engine = sqlalchemy.engine_from_config(settings, 'sqlalchemy.')
    sqlahelper.add_engine(engine)
    config.include(pyramid_tm.includeme)

    # formalchemy
    config.include('pyramid_formalchemy')
    config.include('fa.jquery')
    config.formalchemy_admin('admin', package='pygall',
            view='fa.jquery.pyramid.ModelView', factory=FAModelsFactory)

    # i18n
    config.add_translation_dirs('pygall:locale')

    # bind the mako renderer to other file extensions
    config.add_renderer('.mako', mako_renderer_factory)
    config.add_renderer('jsonp', JSONP(param_name='callback'))

    config.include(add_routes)
    config.include(add_views)

    config.scan('pygall')
Ejemplo n.º 2
0
 def test_mkdir_p(self):
     import os
     import shutil
     from tempfile import mkdtemp
     from pygall.lib.helpers import mkdir_p
     tmpdir = mkdtemp(prefix='test_mkdir_p-')
     testpath = os.path.join(tmpdir, 'dummy', 'directory')
     mkdir_p(testpath)
     self.assertTrue(os.path.isdir(testpath))
     # test that no exception is raised if testpath already exists
     mkdir_p(testpath)
     self.assertTrue(os.path.isdir(testpath))
     shutil.rmtree(tmpdir)
     from mock import patch
     with patch('os.makedirs') as mock_makedirs:
         mock_makedirs.side_effect = OSError
         self.assertRaises(OSError, mkdir_p, testpath)