From c5995864c63270b385443afa3a17c335f335bf4f Mon Sep 17 00:00:00 2001 From: Francis Reyes Date: Wed, 8 Apr 2015 23:37:23 +1000 Subject: [PATCH 1/3] Fix language-switching issue with containers --- fancypages/templatetags/fp_container_tags.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/fancypages/templatetags/fp_container_tags.py b/fancypages/templatetags/fp_container_tags.py index f2d3282..284db57 100644 --- a/fancypages/templatetags/fp_container_tags.py +++ b/fancypages/templatetags/fp_container_tags.py @@ -60,6 +60,12 @@ def get_object(self, context): def get_container(self, context): Container = get_model('fancypages', 'Container') + + rc = context.render_context[self] + + if 'language_code' not in rc: + rc['language_code'] = self.language_code or get_language() + # check first if the container name refers to a # variable in the context and use it a container try: @@ -73,7 +79,7 @@ def get_container(self, context): try: ctn = Container.get_container_by_name( name=self.container_name.var, obj=self.object, - language_code=self.language_code) + language_code=rc['language_code']) except KeyError: ctn = None return ctn @@ -86,6 +92,11 @@ def render(self, context): we try to retrieve a container based on the variable name using the ``object`` variable in the context. """ + + if self not in context.render_context: + # For the first time the node is rendered in the template + context.render_context[self] = {} + self.object = self.get_object(context) self.container = self.get_container(context) @@ -101,7 +112,7 @@ class FancyContainerNode(ContainerNodeMixin, template.Node): def __init__(self, container_name, language=None): self.container_name = template.Variable(container_name) self.object_name = None - self.language_code = language or get_language() + self.language_code = language class FancyObjectContainerNode(ContainerNodeMixin, template.Node): @@ -109,7 +120,7 @@ class FancyObjectContainerNode(ContainerNodeMixin, template.Node): def __init__(self, container_name, object_name=None, language=None): self.container_name = template.Variable(container_name) self.object_name = template.Variable(object_name or 'object') - self.language_code = language or get_language() + self.language_code = language @register.tag From f1fb6fe32ffa0452870a65fde55dec5dfce40488 Mon Sep 17 00:00:00 2001 From: Francis Reyes Date: Wed, 8 Apr 2015 23:51:02 +1000 Subject: [PATCH 2/3] Keep pep8 happy --- fancypages/templatetags/fp_sitemap_tags.py | 4 ++-- fancypages/utils/__init__.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fancypages/templatetags/fp_sitemap_tags.py b/fancypages/templatetags/fp_sitemap_tags.py index 479f5bf..459a0d9 100644 --- a/fancypages/templatetags/fp_sitemap_tags.py +++ b/fancypages/templatetags/fp_sitemap_tags.py @@ -41,8 +41,8 @@ def get_page_tree(group=None, depth=1, relative_to=None): if relative_to: depth_offset = relative_to.depth pages = pages.filter( - Q(node__path__startswith=relative_to.path) & - ~Q(node__path=relative_to.path)) + Q(node__path__startswith=relative_to.path) & ~Q( + node__path=relative_to.path)) pages = pages.filter(node__depth__lte=(depth + depth_offset)) diff --git a/fancypages/utils/__init__.py b/fancypages/utils/__init__.py index cecd60a..3e925fd 100644 --- a/fancypages/utils/__init__.py +++ b/fancypages/utils/__init__.py @@ -69,7 +69,8 @@ def loaddata(orm, fixture_name): """ from dingus import patch - _get_model = lambda model_identifier: orm[model_identifier] + def _get_model(model_identifier): + return orm.get(model_identifier) with patch('django.core.serializers.python._get_model', _get_model): from django.core.management import call_command From 38db881977fbfe282b7293c517dfab9201ecf1b0 Mon Sep 17 00:00:00 2001 From: Francis Reyes Date: Thu, 9 Apr 2015 10:19:52 +1000 Subject: [PATCH 3/3] Remove Django 1.4 from test matrix, because of conflict with setup.py --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index dda2e67..4fce4ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,9 +18,6 @@ env: - PIP_OPTS="--download-cache $HOME/.pip-cache" matrix: - # Testing against Django 1.4 - - DJANGO="Django>=1.4,<1.5" MODEL_UTILS_VERSION=">2.0" TARGET='test-standalone-fancypages' - - DJANGO="Django>=1.4,<1.5" MODEL_UTILS_VERSION=">2.0" TARGET='test-oscar-fancypages' # Testing against Django 1.5 - DJANGO="Django>=1.5,<1.6" MODEL_UTILS_VERSION="==1.5" TARGET='test-standalone-fancypages'