massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
This commit is contained in:
parent
d50412c7f7
commit
6a6f15707a
1 changed files with 9945 additions and 9945 deletions
|
|
@ -162,7 +162,7 @@ class TemplateLoader(jinja2.BaseLoader):
|
|||
return TemplateData(site, theme, template_path)
|
||||
|
||||
@staticmethod
|
||||
def getSitesAndThemes(
|
||||
def get_sites_and_themes(
|
||||
site: str,
|
||||
theme: str,
|
||||
settings: Optional[dict] = None,
|
||||
|
|
@ -205,7 +205,7 @@ class TemplateLoader(jinja2.BaseLoader):
|
|||
raise exceptions.InternalError(
|
||||
"_get_template_f must not be used with absolute path")
|
||||
settings = self.sites_themes[site][theme]['settings']
|
||||
for site_to_check, theme_to_check in self.getSitesAndThemes(
|
||||
for site_to_check, theme_to_check in self.get_sites_and_themes(
|
||||
site, theme, settings):
|
||||
try:
|
||||
base_path = self.sites_paths[site_to_check]
|
||||
|
|
@ -328,12 +328,12 @@ class ScriptsHandler(object):
|
|||
scripts = []
|
||||
tpl = "<script src={src} {attribute}></script>"
|
||||
for library, attribute in self.scripts:
|
||||
library_path = self.renderer.getStaticPath(self.template_data, library)
|
||||
library_path = self.renderer.get_static_path(self.template_data, library)
|
||||
if library_path is None:
|
||||
log.warning(_("Can't find {libary} javascript library").format(
|
||||
library=library))
|
||||
continue
|
||||
path = self.renderer.getFrontURL(library_path)
|
||||
path = self.renderer.get_front_url(library_path)
|
||||
scripts.append(tpl.format(src=quoteattr(path), attribute=attribute))
|
||||
return safe("\n".join(scripts))
|
||||
|
||||
|
|
@ -377,11 +377,11 @@ class Renderer(object):
|
|||
}
|
||||
self.sites_themes = {
|
||||
}
|
||||
conf = config.parseMainConf()
|
||||
public_sites = config.getConfig(conf, None, "sites_path_public_dict", {})
|
||||
conf = config.parse_main_conf()
|
||||
public_sites = config.config_get(conf, None, "sites_path_public_dict", {})
|
||||
sites_data = [public_sites]
|
||||
if private:
|
||||
private_sites = config.getConfig(conf, None, "sites_path_private_dict", {})
|
||||
private_sites = config.config_get(conf, None, "sites_path_private_dict", {})
|
||||
sites_data.append(private_sites)
|
||||
for sites in sites_data:
|
||||
normalised = {}
|
||||
|
|
@ -459,7 +459,7 @@ class Renderer(object):
|
|||
self.env._template_data = None
|
||||
self._locale_str = C.DEFAULT_LOCALE
|
||||
self._locale = Locale.parse(self._locale_str)
|
||||
self.installTranslations()
|
||||
self.install_translations()
|
||||
|
||||
# we want to have access to SàT constants in templates
|
||||
self.env.globals["C"] = C
|
||||
|
|
@ -490,7 +490,7 @@ class Renderer(object):
|
|||
"default": lambda o: o.to_json() if hasattr(o, "to_json") else None
|
||||
}
|
||||
|
||||
def getFrontURL(self, template_data, path=None):
|
||||
def get_front_url(self, template_data, path=None):
|
||||
"""Give front URL (i.e. URL seen by end-user) of a path
|
||||
|
||||
@param template_data[TemplateData]: data of current template
|
||||
|
|
@ -500,7 +500,7 @@ class Renderer(object):
|
|||
return self.env.filters["front_url"]({"template_data": template_data},
|
||||
path or template_data.path)
|
||||
|
||||
def installTranslations(self):
|
||||
def install_translations(self):
|
||||
# TODO: support multi translation
|
||||
# for now, only translations in sat_templates are handled
|
||||
self.translations = {}
|
||||
|
|
@ -546,7 +546,7 @@ class Renderer(object):
|
|||
key=lambda l: l.language_name.lower()))
|
||||
|
||||
|
||||
def setLocale(self, locale_str):
|
||||
def set_locale(self, locale_str):
|
||||
"""set current locale
|
||||
|
||||
change current translation locale and self self._locale and self._locale_str
|
||||
|
|
@ -582,7 +582,7 @@ class Renderer(object):
|
|||
self._locale = locale
|
||||
self._locale_str = locale_str
|
||||
|
||||
def getThemeAndRoot(self, template):
|
||||
def get_theme_and_root(self, template):
|
||||
"""retrieve theme and root dir of a given template
|
||||
|
||||
@param template(unicode): template to parse
|
||||
|
|
@ -600,13 +600,13 @@ class Renderer(object):
|
|||
raise exceptions.NotFound
|
||||
return theme, os.path.join(site_root_dir, C.TEMPLATE_TPL_DIR, theme)
|
||||
|
||||
def getThemesData(self, site_name):
|
||||
def get_themes_data(self, site_name):
|
||||
try:
|
||||
return self.sites_themes[site_name]
|
||||
except KeyError:
|
||||
raise exceptions.NotFound(f"no theme found for {site_name}")
|
||||
|
||||
def getStaticPath(
|
||||
def get_static_path(
|
||||
self,
|
||||
template_data: TemplateData,
|
||||
filename: str,
|
||||
|
|
@ -640,7 +640,7 @@ class Renderer(object):
|
|||
else:
|
||||
return None
|
||||
|
||||
sites_and_themes = TemplateLoader.getSitesAndThemes(template_data.site,
|
||||
sites_and_themes = TemplateLoader.get_sites_and_themes(template_data.site,
|
||||
template_data.theme,
|
||||
settings)
|
||||
for site, theme in sites_and_themes:
|
||||
|
|
@ -653,7 +653,7 @@ class Renderer(object):
|
|||
|
||||
return None
|
||||
|
||||
def _appendCSSPaths(
|
||||
def _append_css_paths(
|
||||
self,
|
||||
template_data: TemplateData,
|
||||
css_files: list,
|
||||
|
|
@ -669,16 +669,16 @@ class Renderer(object):
|
|||
with "_noscript" suffix
|
||||
"""
|
||||
name = name_root + ".css"
|
||||
css_path = self.getStaticPath(template_data, name, settings)
|
||||
css_path = self.get_static_path(template_data, name, settings)
|
||||
if css_path is not None:
|
||||
css_files.append(self.getFrontURL(css_path))
|
||||
css_files.append(self.get_front_url(css_path))
|
||||
noscript_name = name_root + "_noscript.css"
|
||||
noscript_path = self.getStaticPath(
|
||||
noscript_path = self.get_static_path(
|
||||
template_data, noscript_name, settings)
|
||||
if noscript_path is not None:
|
||||
css_files_noscript.append(self.getFrontURL(noscript_path))
|
||||
css_files_noscript.append(self.get_front_url(noscript_path))
|
||||
|
||||
def getCSSFiles(self, template_data):
|
||||
def get_css_files(self, template_data):
|
||||
"""Retrieve CSS files to use according template_data
|
||||
|
||||
For each element of the path, a .css file is looked for in /static, and returned
|
||||
|
|
@ -719,17 +719,17 @@ class Renderer(object):
|
|||
else:
|
||||
settings = self.sites_themes[site][template_data.theme]['settings']
|
||||
|
||||
css_path = self.getStaticPath(template_data, 'fonts.css', settings)
|
||||
css_path = self.get_static_path(template_data, 'fonts.css', settings)
|
||||
if css_path is not None:
|
||||
css_files.append(self.getFrontURL(css_path))
|
||||
css_files.append(self.get_front_url(css_path))
|
||||
|
||||
for name_root in ('styles', 'styles_extra', 'highlight'):
|
||||
self._appendCSSPaths(
|
||||
self._append_css_paths(
|
||||
template_data, css_files, css_files_noscript, name_root, settings)
|
||||
|
||||
for idx in range(len(path_elems)):
|
||||
name_root = "_".join(path_elems[:idx+1])
|
||||
self._appendCSSPaths(
|
||||
self._append_css_paths(
|
||||
template_data, css_files, css_files_noscript, name_root, settings)
|
||||
|
||||
return css_files, css_files_noscript
|
||||
|
|
@ -1024,7 +1024,7 @@ class Renderer(object):
|
|||
template_source = self.env.get_template(template)
|
||||
|
||||
if css_files is None:
|
||||
css_files, css_files_noscript = self.getCSSFiles(template_data)
|
||||
css_files, css_files_noscript = self.get_css_files(template_data)
|
||||
else:
|
||||
css_files_noscript = []
|
||||
|
||||
|
|
@ -1045,7 +1045,7 @@ class Renderer(object):
|
|||
kwargs["css_content" + suffix] = "\n".join(css_contents)
|
||||
|
||||
scripts_handler = ScriptsHandler(self, template_data)
|
||||
self.setLocale(locale)
|
||||
self.set_locale(locale)
|
||||
|
||||
# XXX: theme used in template arguments is the requested theme, which may differ
|
||||
# from actual theme if the template doesn't exist in the requested theme.
|
||||
|
|
|
|||
Loading…
Reference in a new issue