Skip to content

Commit

Permalink
Merge pull request #344 from PyPlanet/bugfix/342
Browse files Browse the repository at this point in the history
[BUGFIX] Make sure we don't enable auto reload on non debug setups.
  • Loading branch information
tomvlk committed Jun 3, 2017
2 parents ff45697 + dae33ac commit 4847dfd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
32 changes: 23 additions & 9 deletions pyplanet/core/ui/template.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
from jinja2 import Environment, PackageLoader, select_autoescape
from jinja2 import Environment, select_autoescape

from pyplanet.conf import settings
from pyplanet.core.ui.loader import PyPlanetLoader


async def load_template(file):
return Template(file)


class _EnvironmentManager:
def __init__(self):
self._environment = None

@property
def environment(self):
if not self._environment:
self._environment = Environment(
loader=PyPlanetLoader.get_loader(),
autoescape=select_autoescape(['html', 'xml', 'Txt', 'txt', 'ml', 'ms', 'script.txt', 'Script.Txt']),
auto_reload=bool(settings.DEBUG),
)
return self._environment

EnvironmentManager = _EnvironmentManager()


class Template:
"""
Template class manages the template file source and the rendering of it.
Will also take care of the loader of the Jinja2 template engine.
Some notable prefixes:
- core.views: ``pyplanet.views.templates``.
- core.pyplanet: ``pyplanet.apps.core.pyplanet.templates``.
- core.maniaplanet: ``pyplanet.apps.core.pyplanet.templates``.
Expand All @@ -24,12 +42,8 @@ class Template:
"""

def __init__(self, file):

self.file = file
self.env = Environment(
loader=PyPlanetLoader.get_loader(),
autoescape=select_autoescape(['html', 'xml', 'Txt', 'txt', 'ml', 'ms', 'script.txt', 'Script.Txt']),
)
self.env = EnvironmentManager.environment
self.template = self.env.get_template(file)

async def render(self, **data):
Expand Down
5 changes: 5 additions & 0 deletions tests/_scripts/travis_dedicated_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ if [[ ${TOXENV} == *"integration"* ]]; then
else
exit 0
fi
# Check if we should use the second dedicated account instead.
if [[ ${TOXENV} == *"py36-integration"* ]]; then
MP_USER="${MP_USER}2"
fi


BEFORE_PWD=`pwd`
cd "$(dirname "$0")"
Expand Down

0 comments on commit 4847dfd

Please sign in to comment.