Example #1
0
def retrieve_template(template_id):
    request = get_current_request()
    if is_github_remote_enabled(request):
        template_slug = template_id
        variables = json.loads(
            get_github_repo(request).get_file_contents('/' + template_slug + '.defaults').decoded_content.decode())
    else:
        template_db = Template.objects.get(pk=int(template_id))
        template_slug = template_db.slug

        variables = {var["name"]: var["initial"] for var in parse_vars(template_db.variables)}

    engine = DjangoTemplates(
            {
                'NAME': 'mail',
                'APP_DIRS': False,
                'DIRS': [],
                'OPTIONS': {
                    'loaders': [
                        'events.loaders.MyLoader',
                    ],
                },
            })
    template = engine.get_template(template_slug)
    return template, variables
Example #2
0
 def test_dirs_pathlib(self):
     engine = DjangoTemplates({
         'DIRS':
         [Path(__file__).parent / 'templates' / 'template_backends'],
         'APP_DIRS':
         False,
         'NAME':
         'django',
         'OPTIONS': {},
     })
     template = engine.get_template('hello.html')
     self.assertEqual(template.render({'name': 'Joe'}), 'Hello Joe!\n')
Example #3
0
 def test_dirs_pathlib(self):
     engine = DjangoTemplates({
         "DIRS":
         [Path(__file__).parent / "templates" / "template_backends"],
         "APP_DIRS":
         False,
         "NAME":
         "django",
         "OPTIONS": {},
     })
     template = engine.get_template("hello.html")
     self.assertEqual(template.render({"name": "Joe"}), "Hello Joe!\n")