7
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-06-01 22:00:48 +00:00

Fix save/render for single files

This commit is contained in:
Régis Behmo 2019-05-21 12:34:29 +02:00
parent 0093198864
commit ebcb08b5eb
4 changed files with 34 additions and 12 deletions

View File

@ -24,6 +24,15 @@ class EnvTests(unittest.TestCase):
"hello world", env.render_str({"name": "world"}, "hello {{ name }}")
)
def test_common_domain(self):
self.assertEqual(
"mydomain.com",
env.render_str(
{"d1": "d1.mydomain.com", "d2": "d2.mydomain.com"},
"{{ d1|common_domain(d2) }}",
),
)
def test_render_str_missing_configuration(self):
self.assertRaises(exceptions.TutorError, env.render_str, {}, "hello {{ name }}")
@ -41,6 +50,12 @@ class EnvTests(unittest.TestCase):
)
def test_render_full(self):
defaults = tutor_config.load_defaults()
with tempfile.TemporaryDirectory() as root:
env.render_full(root, defaults)
def test_render_full_with_https(self):
defaults = tutor_config.load_defaults()
defaults["ACTIVATE_HTTPS"] = True
with tempfile.TemporaryDirectory() as root:
defaults = tutor_config.load_defaults()
env.render_full(root, defaults)

View File

@ -25,7 +25,7 @@ class Renderer:
undefined=jinja2.StrictUndefined,
)
environment.filters["random_string"] = utils.random_string
environment.filters["common_domain"] = utils.random_string
environment.filters["common_domain"] = utils.common_domain
environment.filters["reverse_host"] = utils.reverse_host
environment.globals["TUTOR_VERSION"] = __version__
cls.ENVIRONMENT = environment
@ -68,22 +68,29 @@ def render_full(root, config):
Render the full environment, including version information.
"""
for subdir in ["android", "apps", "k8s", "local", "webui"]:
render_subdir(subdir, root, config)
save_subdir(subdir, root, config)
copy_subdir("build", root)
render_file(config, VERSION_FILENAME)
save_file(VERSION_FILENAME, root, config)
def render_subdir(subdir, root, config):
def save_subdir(subdir, root, config):
"""
Render the templates located in `subdir` and store them with the same
hierarchy at `root`.
"""
for path in walk_templates(subdir):
dst = pathjoin(root, path)
rendered = render_file(config, path)
utils.ensure_file_directory_exists(dst)
with open(dst, "w") as of:
of.write(rendered)
save_file(path, root, config)
def save_file(path, root, config):
"""
Render the template located in `path` and store it with the same hierarchy at `root`.
"""
dst = pathjoin(root, path)
rendered = render_file(config, path)
utils.ensure_file_directory_exists(dst)
with open(dst, "w") as of:
of.write(rendered)
def render_file(config, *path):

View File

@ -33,7 +33,7 @@
"EMAIL_PORT": {{ SMTP_PORT }},
"HTTPS": "{{ "on" if ACTIVATE_HTTPS else "off" }}",
"LANGUAGE_CODE": "{{ LANGUAGE_CODE }}",
{% if ACTIVATE_HTTPS %}"SESSION_COOKIE_DOMAIN": ".{{ lms_cms_common_domain }}",{% endif %}
{% if ACTIVATE_HTTPS %}"SESSION_COOKIE_DOMAIN": ".{{ LMS_HOST|common_domain(CMS_HOST) }}",{% endif %}
"CACHES": {
"default": {
"KEY_PREFIX": "default",

View File

@ -44,7 +44,7 @@
{% endif %}
"LANGUAGE_CODE": "{{ LANGUAGE_CODE }}",
"LOGIN_REDIRECT_WHITELIST": ["{{ CMS_HOST }}", "studio.localhost"],
{% if ACTIVATE_HTTPS %}"SESSION_COOKIE_DOMAIN": ".{{ lms_cms_common_domain }}",{% endif %}
{% if ACTIVATE_HTTPS %}"SESSION_COOKIE_DOMAIN": ".{{ LMS_HOST|common_domain(CMS_HOST) }}",{% endif %}
"CACHES": {
"default": {
"KEY_PREFIX": "default",