def test_asset_spec_missing_file(self):
        from webassets import Bundle
        from webassets.exceptions import BundleError

        self.create_files({
                'dotted/__init__.py': '',
                'dotted/package/__init__.py': '',
                'dotted/package/name/__init__.py': ''})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)

        with self.assertRaises(BundleError) as cm:
            bundle.urls(self.env)

        assert cm.exception.args[0].message == '{0!r} does not exist'.format(
                self.tempdir+'/dotted/package/name/static/zing.css')
    def test_asset_spec_missing_file(self):
        from webassets import Bundle
        from webassets.exceptions import BundleError

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': ''})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)

        with self.assertRaises(BundleError) as cm:
            bundle.urls(self.env)

        fname = self.tempdir+'/dotted/package/name/static/zing.css'
        assert str(cm.exception.message) == ("'%s' does not exist" % (fname,))
Beispiel #3
0
    def test_asset_spec_missing_file(self):
        from webassets import Bundle
        from webassets.exceptions import BundleError

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': ''})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)

        with self.assertRaises(BundleError) as cm:
            bundle.urls(self.env)

        fname = self.tempdir+'/dotted/package/name/static/zing.css'
        assert str(cm.exception.message) == ("'%s' does not exist" % (fname,))
Beispiel #4
0
    def test_asset_spec_missing_package(self):
        from webassets import Bundle
        from webassets.exceptions import BundleError

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.rabbits:static/zing.css'
        bundle = Bundle(asset_spec)

        with self.assertRaises(BundleError) as cm:
            bundle.urls(self.env)

        assert cm.exception.args[0].message == 'No module named rabbits'
    def test_asset_spec_missing_package(self):
        from webassets import Bundle
        from webassets.exceptions import BundleError

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.rabbits:static/zing.css'
        bundle = Bundle(asset_spec)

        with self.assertRaises(BundleError) as cm:
            bundle.urls(self.env)

        assert cm.exception.args[0].message == 'No module named rabbits'
Beispiel #6
0
    def test_asset_spec_missing_file(self):
        from webassets import Bundle
        from webassets.exceptions import BundleError

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': ''
        })
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)

        with self.assertRaises(BundleError) as cm:
            bundle.urls(self.env)

        assert cm.exception.args[0].message == '{0!r} does not exist'.format(
            self.tempdir + '/dotted/package/name/static/zing.css')
    def test_asset_spec_no_static_view(self):
        from webassets import Bundle
        from webassets.exceptions import BundleError

        self.create_files({
                'dotted/__init__.py': '',
                'dotted/package/__init__.py': '',
                'dotted/package/name/__init__.py': '',
                'dotted/package/name/static/zing.css':
                '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)

        with self.assertRaises(BundleError) as cm:
            bundle.urls(self.env)

        assert cm.exception.args[0].message == 'No static URL definition matching '+asset_spec
Beispiel #8
0
def assets(request, *args, **kwargs):
    env = get_webassets_env_from_request(request)

    result = []

    for f in args:
        try:
            result.append(env[f])
        except KeyError:
            result.append(f)

    bundle = Bundle(*result, **kwargs)
    if USING_WEBASSETS_CONTEXT:
        with bundle.bind(env):
            urls = bundle.urls()
    else:
        urls = bundle.urls(env=env)

    return urls
def assets(request, *args, **kwargs):
    env = get_webassets_env_from_request(request)

    result = []

    for f in args:
        try:
            result.append(env[f])
        except KeyError:
            result.append(f)

    bundle = Bundle(*result, **kwargs)
    if USING_WEBASSETS_CONTEXT:
        with bundle.bind(env):
            urls = bundle.urls()
    else:  # pragma: no cover
        urls = bundle.urls(env=env)

    return urls
Beispiel #10
0
    def test_asset_spec_no_static_view(self):
        from webassets import Bundle
        from webassets.exceptions import BundleError

        self.create_files({
            'dotted/__init__.py':
            '',
            'dotted/package/__init__.py':
            '',
            'dotted/package/name/__init__.py':
            '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'
        })
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)

        with self.assertRaises(BundleError) as cm:
            bundle.urls(self.env)

        assert cm.exception.args[
            0].message == 'No static URL definition matching ' + asset_spec
Beispiel #11
0
def assets(request, *args, **kwargs):
    env = get_webassets_env_from_request(request)

    result = []

    for f in args:
        try:
            result.append(env[f])
        except KeyError:
            result.append(f)

    bundle = Bundle(*result, **kwargs)
    urls = bundle.urls(env=env)

    return urls
def assets(request, *args, **kwargs):
    env = get_webassets_env_from_request(request)

    result = []

    for f in args:
        try:
            result.append(env[f])
        except KeyError:
            result.append(f)

    bundle = Bundle(*result, **kwargs)
    urls = bundle.urls(env=env)

    return urls
    def test_asset_spec_is_resolved(self):
        from webassets import Bundle

        self.create_files({
                'dotted/__init__.py': '',
                'dotted/package/__init__.py': '',
                'dotted/package/name/__init__.py': '',
                'dotted/package/name/static/zing.css':
                '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec, output='gen/zung.css')

        urls = bundle.urls(self.env)
        assert urls == ['/static/gen/zung.css']
        assert file(self.tempdir+urls[0]).read() == '* { text-decoration: underline }'
    def test_assec_spec_globbing(self):
        from webassets import Bundle

        self.create_files({
            'static/__init__.py': '',
            'static/zing.css': '* { text-decoration: underline }',
            'static/zang.css': '* { text-decoration: underline }'
        })
        asset_spec = 'static:z*ng.css'
        bundle = Bundle(asset_spec)

        urls = bundle.urls(self.env)
        assert len(urls) == 2
        assert 'http://example.com/static/zing.css' in urls
        assert 'http://example.com/static/zang.css' in urls
Beispiel #15
0
    def test_asset_spec_source_is_resolved(self):
        from webassets import Bundle

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec, output='gen/zung.css')

        urls = bundle.urls(self.env)
        assert urls == ['http://example.com/static/gen/zung.css']
        urls[0] = urls[0][len(self.request.application_url):]
        assert file(self.tempdir+urls[0]).read() == '* { text-decoration: underline }'
    def test_asset_spec_passthru_uses_static_url(self):
        from webassets import Bundle

        self.create_files({
                'dotted/__init__.py': '',
                'dotted/package/__init__.py': '',
                'dotted/package/name/__init__.py': '',
                'dotted/package/name/static/zing.css':
                '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)
        self.request.static_url = Mock(return_value='http://example.com/foo/')

        urls = bundle.urls(self.env)
        self.request.static_url.assert_called_with(asset_spec)
        assert urls == ['http://example.com/foo/']
    def test_url(self, base_url, static_view, webasset, expected):
        """
        Test final urls

        Special notes on the parametrized variables:
        - expected file, if it ends in o.css, it setups output in the bundle
        - static_view set to manual changes also the base_dir to /mypkg instead
          of /static
        """
        from webassets import Bundle

        expected = self.format_expected(expected, webasset)
        params = {} if not 'o.css' in expected else {'output': 'o.css'}
        bundle = Bundle(webasset, **params)
        res = bundle.urls(self.build_env(base_url, static_view))
        assert [expected] == res
    def test_asset_spec_globbing(self):
        from webassets import Bundle

        self.create_files({
            'static/__init__.py': '',
            'static/zing.css':
            '* { text-decoration: underline }',
            'static/zang.css':
            '* { text-decoration: underline }'})
        asset_spec = 'static:z*ng.css'
        bundle = Bundle(asset_spec)

        urls = bundle.urls(self.env)
        assert len(urls) == 2
        assert 'http://example.com/static/zing.css' in urls
        assert 'http://example.com/static/zang.css' in urls
Beispiel #19
0
    def test_url(self, base_url, static_view, webasset, expected):
        """
        Test final urls

        Special notes on the parametrized variables:
        - expected file, if it ends in o.css, it setups output in the bundle
        - static_view set to manual changes also the base_dir to /mypkg instead
          of /static
        """
        from webassets import Bundle

        expected = self.format_expected(expected, webasset)
        params = {} if not 'o.css' in expected else {'output': 'o.css'}
        bundle = Bundle(webasset, **params)
        res = bundle.urls(self.build_env(base_url, static_view))
        assert [expected] == res
    def test_asset_spec_output_is_resolved(self):
        from webassets import Bundle

        self.create_files({
            'static/__init__.py': '',
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec, output='static:zung.css')

        urls = bundle.urls(self.env)
        assert urls == ['http://example.com/static/zung.css']
        urls[0] = urls[0][len(self.request.application_url):]
        assert file(self.tempdir+urls[0]).read() == '* { text-decoration: underline }'
    def test_asset_spec_load_path_and_mapping(self):
        from webassets import Bundle

        asset_path = self.tempdir + '/dotted/package/name/static/'
        self.env.append_path(asset_path, 'http://static.example.com')

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec, output=asset_spec.replace('zing', 'zung'))

        urls = bundle.urls(self.env)
        assert urls == ['http://static.example.com/zung.css']
Beispiel #22
0
    def test_asset_spec_load_path_and_mapping(self):
        from webassets import Bundle

        asset_path = self.tempdir + '/dotted/package/name/static/'
        self.env.append_path(asset_path, 'http://static.example.com')

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec, output=asset_spec.replace('zing', 'zung'))

        urls = bundle.urls(self.env)
        assert urls == ['http://static.example.com/zung.css']
Beispiel #23
0
    def test_asset_spec_passthru_uses_static_url(self):
        from webassets import Bundle
        from pyramid.path import AssetResolver

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)
        self.request.static_url = Mock(return_value='http://example.com/foo/')

        urls = bundle.urls(self.env)
        path = AssetResolver(None).resolve(asset_spec).abspath()
        self.request.static_url.assert_called_with(path)
        assert urls == ['http://example.com/foo/']
    def test_asset_spec_no_static_view(self):
        from webassets import Bundle

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)

        # webassets will copy the file into a place that it can generate
        # a url for
        urls = bundle.urls(self.env)
        domain = 'http://example.com/static/webassets-external/'

        assert domain in urls[0]
        assert len(urls) == 1
Beispiel #25
0
    def test_asset_spec_no_static_view(self):
        from webassets import Bundle

        self.create_files({
            'dotted/__init__.py': '',
            'dotted/package/__init__.py': '',
            'dotted/package/name/__init__.py': '',
            'dotted/package/name/static/zing.css':
            '* { text-decoration: underline }'})
        asset_spec = 'dotted.package.name:static/zing.css'
        bundle = Bundle(asset_spec)

        # webassets will copy the file into a place that it can generate
        # a url for
        urls = bundle.urls(self.env)
        domain = 'http://example.com/static/webassets-external/'

        assert domain in urls[0]
        assert len(urls) == 1
Beispiel #26
0
def compressFile(f, webFilters):
    filePath = os.path.join(webFolder, f)
    baseName = os.path.basename(filePath)
    prefix = f[0:len(f) - len(baseName)]
    fn = os.path.splitext(baseName)
    newFileName = fn[0] + '.%(version)s' + fn[1]
    env = Environment("")
    env.auto_build = False
    env.url_expire = True
    tmpFile = os.path.join(tempFolder, newFileName)
    env.url_mapping = {tempFolder: ''}
    bundle = Bundle(filePath, filters=webFilters, output=tmpFile)
    env.add(bundle)
    bundle.build()
    vfn = bundle.urls()[0][1:]
    if (vfn.index("?") > 0):
        vfn = vfn[0:vfn.index("?")]

    #print(prefix, vfn)
    zf.write(os.path.join(tempFolder, vfn), prefix + vfn)
    return prefix + vfn
Beispiel #27
0
def _render_assets(tokens, env):
    #pylint:disable=too-many-locals
    # Construct a bundle with the given options
    output = None
    filters = None
    depends = None
    bundle_kwargs = {
        'output': output,
        'filters': filters,
        'debug': False,  # because of `Bundle.iterbuild`, this is useless.
        'depends': depends,
    }

    # Resolve bundle names.
    files = []
    state = None
    buffered_tokens = []
    for token in tokens:
        if state is None:
            if token[1] == 'block_begin':
                state = STATE_BLOCK_BEGIN
        elif state == STATE_BLOCK_BEGIN:
            if token[1] == 'name':
                # nothing to be done?
                pass
            elif token[1] == 'string':
                files = [token[2][1:-1]] # removes '"'.
            if token[1] == 'block_end':
                state = STATE_BLOCK_CONTENT
        elif state == STATE_BLOCK_CONTENT:
            if token[1] == 'block_begin':
                state = None
            else:
                buffered_tokens += [token]

    content = ''.join([token[2] for token in buffered_tokens]).strip()

    urls = []
    bundle_names = []
    for fname in files:
        try:
            bundle = env[fname]
            debug = bundle.config.get('debug')
            bundle.config.update({'debug': False})
            with bundle.bind(env):
                urls += bundle.urls()
            bundle.config.update({'debug': debug})
        except KeyError:
            bundle_names.append(fname)

    if bundle_names:
        bundle = Bundle(*bundle_names, **bundle_kwargs)
        # Retrieve urls (this may or may not cause a build)
        with bundle.bind(env):
            urls += bundle.urls()

    # For each url, execute the content of this template tag (represented
    # by the macro ```caller`` given to use by Jinja2).
    result = content
    for url in urls:
        look = re.match(r'(.*)({{\s*ASSET_URL.*}})(.*)', content)
        if look:
            parts = urlparse(url)
            url = urlunparse((parts.scheme, parts.netloc, parts.path,
                None, None, None))
            result = look.group(1) + url + look.group(3)
        else:
            result = content
    return result
Beispiel #28
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    authn_policy = AuthTktAuthenticationPolicy('sosecret', callback=groupfinder, hashalg='sha512',
                                               timeout=60 * 60 * 24 * 7)  ## Change it
    authz_policy = ACLAuthorizationPolicy()
    config = Configurator(settings=settings, root_factory='main_page.models.RootFactory')
    config.include('pyramid_mailer')
    config.include('pyramid_mako')
    config.registry['mailer'] = Mailer.from_settings(settings)
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    #config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('assets', 'assets', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('install', '/install')
    config.add_route('radio', '/radio')

    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.add_route('register', '/register')
    config.add_route('forgot_password', '/forgot-password')
    config.add_route('activate_account', '/activate-account')

    config.add_route('zastepstwa', '/zastepstwa')
    config.add_renderer('jsonp', JSONP(param_name='callback'))

    config.add_route('api', '/api')
    config.add_route('jsonp_mobile_login', '/api/jsonp/mobile_login')

    config.add_route('jsonp_system_info', '/api/jsonp/system_info')

    config.add_route('admin_home', '/admin')
    config.add_route('admin', '/admin/{page}')
    config.add_route('admin_pp', '/admin/{pp}/{page}')

    config.add_route('admin_log_years_groups', '/admin/log/years/groups/{year}')
    config.add_route('admin_log_years_groups_students', '/admin/log/years/groups/{year}/{group}')
    config.add_route('admin_log_timetables', '/admin/log/timetables')
    config.add_route('admin_log_timetables_edit', '/admin/log/timetables/{id}')

    config.add_route('admin_substitutions', '/admin/substitutions')
    config.add_route('admin_substitutions_add', '/admin/substitutions/add')
    config.add_route('admin_substitutions_view', '/admin/substitutions_view/{id}')
    config.add_route('admin_substitutions_edit', '/admin/substitutions_edit/{id}')
    config.add_route('admin_substitutions_del', '/admin/substitutions_del/{id}')

    config.add_route('account_folders', '/account/folders')
    config.add_route('account_entries', '/account/entries')
    config.add_route('account_presentations', '/account/presentations')
    config.add_route('account_tasks_sets', '/account/tasks-sets')
    config.add_route('account_questions_sets', '/account/questions-sets')
    config.add_route('account_other', '/account/other')
    config.add_route('account', '/account')
    config.add_route('phone_app', '/account/phone')

    config.add_route('support_ask', '/support/ticket-new')
    config.add_route('support_ask_ticket', '/support/ticket-{id}')
    config.add_route('support_faq', '/support/faq')

    config.add_route('gallery_list', '/gallery')
    config.add_route('gallery', '/gallery/{id}')

    config.add_route('syllabus', '/syllabus')
    config.add_route('syllabus_year', '/syllabus/{year}')
    config.add_route('syllabus_profile', '/syllabus/{year}/{profile}')
    config.add_route('syllabus_extension', '/syllabus/{year}/{profile}/{extension}')
    config.add_route('competitions', '/competitions/{path_name}')

    config.add_route('file_upload', '/file-upload')

    config.add_route('connection', '/connection')

    config.add_route('loading', '/loading')
    config.add_route('entries', '/entries')
    config.add_route('entry_save', '/entry/save')
    config.add_route('page', '/p/{id}')
    config.add_route('user', '/u/{id}')
    config.add_route('entry', '/entry/{id}')
    config.add_route('folder', '/folder/{id}')
    config.add_route('presentations', '/presentations')
    config.add_route('presentation', '/presentation/{id}')
    config.add_route('set', '/set/{id}')

    config.add_route('lucky', '/sis/lucky')
    config.add_route('sis_home', '/sis')
    config.add_route('sis_about', '/sis/about')
    config.add_route('schedule', '/sis/schedule')
    config.add_route('map', '/map')
    config.add_route('socketio', 'socket.io/*remaining')


    #    config.add_route('anki_sync_meta', '/syncmeta')
    #    config.add_route('anki_sync_upload', '/syncupload')
    #    config.add_route('sync_media_list', '/syncmediaList')
    #    config.add_route('sync_remove', '/syncremove')
    #    config.add_route('sync_files', '/syncfiles')
    #    config.add_route('sync_host_key', '/synchostKey')
    #    config.add_route('sync_download', '/syncdownload')

    config.add_route('joomla', '/joomla')
    config.add_route('confirm', '/confirm')

    config.add_route('easy_link', '/{link}')

    wa_env = get_webassets_env(config)
    for x in os.walk("main_page/static/src/"):
        for y in x:
            for z in y:
                if z[-7:] == ".min.js":
                    name = x[0][21:] + "/" + z
                    b = Bundle("src/" + name, output=name, filters=['closure_js'])
                    wa_env.register(name+"h", b)
                    print b.urls()
                if z[-3:] == ".js":
                    name = x[0][21:] + "/" + z
                    b = Bundle("src/" + name, output=name[:-3] + ".min.js", filters=['closure_js'])
                    wa_env.register(name, b)
                    print b.urls()
    for x in os.walk("main_page/static/src/"):
        for y in x:
            for z in y:
                if z[-4:] == ".css":
                    name = x[0][21:] + "/" + z
                    b = Bundle("src/" + name, output=name[:-4] + ".min.css")
                    wa_env.register(name, b)
                    print b.urls()
    #, filters=['cssmin']
        #scroll_up_css=Bundle("libs/scrollup/themes/pill.css")
    #scroll_up_js=Bundle("libs/scrollup/jquery.scrollUp.min.js","js/scroll_up.js")

    #diagrams=Bundle("libs/raphael/raphael-min.js","libs/jquery.browser/jquery.browser.js","js/diagrams.js")
    #noisy_js=Bundle("js/noisy.js")
    #content_js=Bundle("js/content.js") ## bonzo (?)
    #content_css=Bundle("css/content.css","css/entries.css")
    #spoiler_js=Bundle("libs/spoiler/spoiler.js","js/spoiler.js")

    #easteregg_js=Bundle('libs/easter/easter.js')  #easter_egg
    #gravity = Bundle('libs/easter/gravity/jGravity.js')  #does not work properly

    #c_css = Bundle(scroll_up_css, owl_css, content_css, social_css, raptor_css, output='gen/content.min.css',  debug=False)

    #r_js = Bundle(cookie_js, bootstrap_js, owl_js, time_js, fit_vids_js, flickr_js, base_js, holder_js, progression_js, 'js/form_login.js', output='gen/main.min.js', debug=False)
    #r_css =  Bundle(bootstrap_css, cookie_css, owl_css, base_css,progression_css, output='gen/main.min.css', debug=False)

    config.include('pyramid_rewrite')
    config.add_rewrite_rule(r'/(?P<path>.*)/', r'/%(path)s')
    config.scan()
    return config.make_wsgi_app()
Beispiel #29
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    authn_policy = AuthTktAuthenticationPolicy('sosecret',
                                               callback=groupfinder,
                                               hashalg='sha512',
                                               timeout=60 * 60 * 24 *
                                               7)  ## Change it
    authz_policy = ACLAuthorizationPolicy()
    config = Configurator(settings=settings,
                          root_factory='main_page.models.RootFactory')
    config.include('pyramid_mailer')
    config.include('pyramid_mako')
    config.registry['mailer'] = Mailer.from_settings(settings)
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    #config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('assets', 'assets', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('install', '/install')
    config.add_route('radio', '/radio')

    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.add_route('register', '/register')
    config.add_route('forgot_password', '/forgot-password')
    config.add_route('activate_account', '/activate-account')

    config.add_route('zastepstwa', '/zastepstwa')
    config.add_renderer('jsonp', JSONP(param_name='callback'))

    config.add_route('api', '/api')
    config.add_route('jsonp_mobile_login', '/api/jsonp/mobile_login')

    config.add_route('jsonp_system_info', '/api/jsonp/system_info')

    config.add_route('admin_home', '/admin')
    config.add_route('admin', '/admin/{page}')
    config.add_route('admin_pp', '/admin/{pp}/{page}')

    config.add_route('admin_log_years_groups',
                     '/admin/log/years/groups/{year}')
    config.add_route('admin_log_years_groups_students',
                     '/admin/log/years/groups/{year}/{group}')
    config.add_route('admin_log_timetables', '/admin/log/timetables')
    config.add_route('admin_log_timetables_edit', '/admin/log/timetables/{id}')

    config.add_route('admin_substitutions', '/admin/substitutions')
    config.add_route('admin_substitutions_add', '/admin/substitutions/add')
    config.add_route('admin_substitutions_view',
                     '/admin/substitutions_view/{id}')
    config.add_route('admin_substitutions_edit',
                     '/admin/substitutions_edit/{id}')
    config.add_route('admin_substitutions_del',
                     '/admin/substitutions_del/{id}')

    config.add_route('account_folders', '/account/folders')
    config.add_route('account_entries', '/account/entries')
    config.add_route('account_presentations', '/account/presentations')
    config.add_route('account_tasks_sets', '/account/tasks-sets')
    config.add_route('account_questions_sets', '/account/questions-sets')
    config.add_route('account_other', '/account/other')
    config.add_route('account', '/account')
    config.add_route('phone_app', '/account/phone')

    config.add_route('support_ask', '/support/ticket-new')
    config.add_route('support_ask_ticket', '/support/ticket-{id}')
    config.add_route('support_faq', '/support/faq')

    config.add_route('gallery_list', '/gallery')
    config.add_route('gallery', '/gallery/{id}')

    config.add_route('syllabus', '/syllabus')
    config.add_route('syllabus_year', '/syllabus/{year}')
    config.add_route('syllabus_profile', '/syllabus/{year}/{profile}')
    config.add_route('syllabus_extension',
                     '/syllabus/{year}/{profile}/{extension}')
    config.add_route('competitions', '/competitions/{path_name}')

    config.add_route('file_upload', '/file-upload')

    config.add_route('connection', '/connection')

    config.add_route('loading', '/loading')
    config.add_route('entries', '/entries')
    config.add_route('entry_save', '/entry/save')
    config.add_route('page', '/p/{id}')
    config.add_route('user', '/u/{id}')
    config.add_route('entry', '/entry/{id}')
    config.add_route('folder', '/folder/{id}')
    config.add_route('presentations', '/presentations')
    config.add_route('presentation', '/presentation/{id}')
    config.add_route('set', '/set/{id}')

    config.add_route('lucky', '/sis/lucky')
    config.add_route('sis_home', '/sis')
    config.add_route('sis_about', '/sis/about')
    config.add_route('schedule', '/sis/schedule')
    config.add_route('map', '/map')
    config.add_route('socketio', 'socket.io/*remaining')

    #    config.add_route('anki_sync_meta', '/syncmeta')
    #    config.add_route('anki_sync_upload', '/syncupload')
    #    config.add_route('sync_media_list', '/syncmediaList')
    #    config.add_route('sync_remove', '/syncremove')
    #    config.add_route('sync_files', '/syncfiles')
    #    config.add_route('sync_host_key', '/synchostKey')
    #    config.add_route('sync_download', '/syncdownload')

    config.add_route('joomla', '/joomla')
    config.add_route('confirm', '/confirm')

    config.add_route('easy_link', '/{link}')

    wa_env = get_webassets_env(config)
    for x in os.walk("main_page/static/src/"):
        for y in x:
            for z in y:
                if z[-7:] == ".min.js":
                    name = x[0][21:] + "/" + z
                    b = Bundle("src/" + name,
                               output=name,
                               filters=['closure_js'])
                    wa_env.register(name + "h", b)
                    print b.urls()
                if z[-3:] == ".js":
                    name = x[0][21:] + "/" + z
                    b = Bundle("src/" + name,
                               output=name[:-3] + ".min.js",
                               filters=['closure_js'])
                    wa_env.register(name, b)
                    print b.urls()
    for x in os.walk("main_page/static/src/"):
        for y in x:
            for z in y:
                if z[-4:] == ".css":
                    name = x[0][21:] + "/" + z
                    b = Bundle("src/" + name, output=name[:-4] + ".min.css")
                    wa_env.register(name, b)
                    print b.urls()
    #, filters=['cssmin']
    #scroll_up_css=Bundle("libs/scrollup/themes/pill.css")
    #scroll_up_js=Bundle("libs/scrollup/jquery.scrollUp.min.js","js/scroll_up.js")

    #diagrams=Bundle("libs/raphael/raphael-min.js","libs/jquery.browser/jquery.browser.js","js/diagrams.js")
    #noisy_js=Bundle("js/noisy.js")
    #content_js=Bundle("js/content.js") ## bonzo (?)
    #content_css=Bundle("css/content.css","css/entries.css")
    #spoiler_js=Bundle("libs/spoiler/spoiler.js","js/spoiler.js")

    #easteregg_js=Bundle('libs/easter/easter.js')  #easter_egg
    #gravity = Bundle('libs/easter/gravity/jGravity.js')  #does not work properly

    #c_css = Bundle(scroll_up_css, owl_css, content_css, social_css, raptor_css, output='gen/content.min.css',  debug=False)

    #r_js = Bundle(cookie_js, bootstrap_js, owl_js, time_js, fit_vids_js, flickr_js, base_js, holder_js, progression_js, 'js/form_login.js', output='gen/main.min.js', debug=False)
    #r_css =  Bundle(bootstrap_css, cookie_css, owl_css, base_css,progression_css, output='gen/main.min.css', debug=False)

    config.include('pyramid_rewrite')
    config.add_rewrite_rule(r'/(?P<path>.*)/', r'/%(path)s')
    config.scan()
    return config.make_wsgi_app()
Beispiel #30
0
 def _get_assets(request, *args, **kwargs):
     bundle = Bundle(*args, **kwargs)
     with bundle.bind(env):
         urls = bundle.urls()
     return urls
Beispiel #31
0
                   'js/app.js',
                   filters='uglifyjs',
                   output='js/electris-footer.min.js')

css = Bundle('bootstrap/css/bootstrap.min.css',
             'bootstrap/css/bootstrap-responsive.min.css',
             'css/template.css',
             'css/app.css',
             'css/sponsorship.css',
             filters='yui_css',
             output='css/electris.min.css')

static.register('js_header', header_js)
static.register('js_footer', footer_js)
static.register('css', css)

header_js.urls()
footer_js.urls()
css.urls()

import logging
from webassets.script import CommandLineEnvironment

# Setup a logger
log = logging.getLogger('webassets')
log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)

cmdenv = CommandLineEnvironment(static, log)
cmdenv.watch()
Beispiel #32
0
    filters='uglifyjs',
    output='js/electris-footer.min.js')

css = Bundle(
    'bootstrap/css/bootstrap.min.css',
    'bootstrap/css/bootstrap-responsive.min.css',
    'css/template.css',
    'css/app.css',
    'css/sponsorship.css',
    filters='yui_css',
    output='css/electris.min.css')

static.register('js_header', header_js)
static.register('js_footer', footer_js)
static.register('css', css)

header_js.urls()
footer_js.urls()
css.urls()

import logging
from webassets.script import CommandLineEnvironment

# Setup a logger
log = logging.getLogger('webassets')
log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)

cmdenv = CommandLineEnvironment(static, log)
cmdenv.watch()
def _render_assets(tokens, env):
    #pylint:disable=too-many-locals
    # Construct a bundle with the given options
    output = None
    filters = None
    depends = None
    bundle_kwargs = {
        'output': output,
        'filters': filters,
        'debug': False,  # because of `Bundle.iterbuild`, this is useless.
        'depends': depends,
    }

    # Resolve bundle names.
    files = []
    state = None
    buffered_tokens = []
    for token in tokens:
        if state is None:
            if token[1] == 'block_begin':
                state = STATE_BLOCK_BEGIN
        elif state == STATE_BLOCK_BEGIN:
            if token[1] == 'name':
                # nothing to be done?
                pass
            elif token[1] == 'string':
                files = [token[2][1:-1]] # removes '"'.
            if token[1] == 'block_end':
                state = STATE_BLOCK_CONTENT
        elif state == STATE_BLOCK_CONTENT:
            if token[1] == 'block_begin':
                state = None
            else:
                buffered_tokens += [token]

    content = ''.join([token[2] for token in buffered_tokens]).strip()

    urls = []
    bundle_names = []
    for fname in files:
        try:
            bundle = env[fname]
            debug = bundle.config.get('debug')
            bundle.config.update({'debug': False})
            with bundle.bind(env):
                urls += bundle.urls()
            bundle.config.update({'debug': debug})
        except KeyError:
            bundle_names.append(fname)

    if bundle_names:
        bundle = Bundle(*bundle_names, **bundle_kwargs)
        # Retrieve urls (this may or may not cause a build)
        with bundle.bind(env):
            urls += bundle.urls()

    # For each url, execute the content of this template tag (represented
    # by the macro ```caller`` given to use by Jinja2).
    result = content
    for url in urls:
        look = re.match(r'(.*)({{\s*ASSET_URL.*}})(.*)', content)
        if look:
            parts = urlparse(url)
            url = urlunparse((parts.scheme, parts.netloc, parts.path,
                None, None, None))
            result = look.group(1) + url + look.group(3)
        else:
            result = content
    return result