Exemple #1
0
 def _write_generated_js(self):
     global_js = generate_global_file().encode('utf-8')
     user_js = generate_user_file().encode('utf-8')
     i18n_js = u"window.TRANSLATIONS = {};".format(generate_i18n_file(session.lang)).encode('utf-8')
     gen_path = os.path.join(self._content_dir, 'assets')
     self._zip_file.writestr(os.path.join(gen_path, 'js-vars', 'global.js'), global_js)
     self._zip_file.writestr(os.path.join(gen_path, 'js-vars', 'user.js'), user_js)
     self._zip_file.writestr(os.path.join(gen_path, 'i18n', session.lang + '.js'), i18n_js)
Exemple #2
0
 def _write_generated_js(self):
     global_js = generate_global_file()
     user_js = generate_user_file()
     i18n_js = "window.TRANSLATIONS = {};".format(generate_i18n_file(session.lang))
     react_i18n_js = "window.REACT_TRANSLATIONS = {};".format(generate_i18n_file(session.lang, react=True))
     gen_path = os.path.join(self._content_dir, 'assets')
     self._zip_file.writestr(os.path.join(gen_path, 'js-vars', 'global.js'), global_js)
     self._zip_file.writestr(os.path.join(gen_path, 'js-vars', 'user.js'), user_js)
     self._zip_file.writestr(os.path.join(gen_path, 'i18n', session.lang + '.js'), i18n_js)
     self._zip_file.writestr(os.path.join(gen_path, 'i18n', session.lang + '-react.js'), react_i18n_js)
Exemple #3
0
def js_vars_global():
    """
    Provides a JS file with global definitions (all users)
    Useful for server-wide config options, URLs, etc...
    """
    cache_file = os.path.join(config.CACHE_DIR, 'assets_global_{}.js'.format(config.hash))

    if not os.path.exists(cache_file):
        data = generate_global_file()
        with open(cache_file, 'wb') as f:
            f.write(data)

    return send_file('global.js', cache_file, mimetype='application/javascript', no_cache=False, conditional=True)
Exemple #4
0
def js_vars_global():
    """
    Provides a JS file with global definitions (all users)
    Useful for server-wide config options, URLs, etc...
    """
    cache_file = os.path.join(config.CACHE_DIR, 'assets_global_{}_{}.js'.format(indico.__version__, config.hash))

    if config.DEBUG or not os.path.exists(cache_file):
        data = generate_global_file()
        with open(cache_file, 'wb') as f:
            f.write(data)

    return send_file('global.js', cache_file, mimetype='application/javascript', no_cache=False, conditional=True)
Exemple #5
0
def js_vars_global():
    """
    Provides a JS file with global definitions (all users)
    Useful for server-wide config options, URLs, etc...
    """
    config = Config.getInstance()
    config_hash = crc32(repr(make_hashable(sorted(config._configVars.items()))))
    cache_file = os.path.join(config.getXMLCacheDir(), 'assets_global_{}.js'.format(config_hash))

    if not os.path.exists(cache_file):
        data = generate_global_file(config)
        with open(cache_file, 'wb') as f:
            f.write(data)

    return send_file('global.js', cache_file,
                     mimetype='application/x-javascript', no_cache=False, conditional=True)