[Python-modules-commits] [django-sitetree] 03/09: Import django-sitetree_1.8.0+dfsg.orig.tar.gz

Michael Fladischer fladi at moszumanska.debian.org
Thu Jul 13 13:37:11 UTC 2017


This is an automated email from the git hooks/post-receive script.

fladi pushed a commit to branch master
in repository django-sitetree.

commit d2459a9b3307ba081db6e460a9a6f0973b53e9ee
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Thu Jul 13 14:55:48 2017 +0200

    Import django-sitetree_1.8.0+dfsg.orig.tar.gz
---
 .travis.yml                         |  7 +++++++
 AUTHORS                             |  1 +
 CHANGELOG                           |  6 ++++++
 docs/source/i18n.rst                |  4 ++--
 docs/source/tags.rst                | 12 ++++++++++++
 setup.py                            |  1 +
 sitetree/__init__.py                |  2 +-
 sitetree/sitetreeapp.py             |  5 +++--
 sitetree/templatetags/sitetree.py   |  4 ++--
 sitetree/tests/conftest.py          | 24 +++++++++++++++++++-----
 sitetree/tests/test_templatetags.py | 20 ++++++++++++++++++++
 tox.ini                             |  5 +++--
 12 files changed, 77 insertions(+), 14 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 751e85a..59d8238 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,14 @@
 language: python
 
 python:
+  - 3.6
   - 3.5
   - 3.4
   - 3.3
   - 2.7
 
 env:
+  - DJANGO="Django>=1.11,<1.12"
   - DJANGO="Django>=1.10,<1.11"
   - DJANGO="Django>=1.9,<1.10"
   - DJANGO="Django>=1.8.6,<1.9"
@@ -20,10 +22,15 @@ script: coverage run -a --source=sitetree setup.py test
 matrix:
 
   exclude:
+   - python: 3.6
+     env: DJANGO="Django>=1.7,<1.8"
+
    - python: 3.5
      env: DJANGO="Django>=1.7,<1.8"
 
    - python: 3.3
+     env: DJANGO="Django>=1.11,<1.12"
+   - python: 3.3
      env: DJANGO="Django>=1.10,<1.11"
    - python: 3.3
      env: DJANGO="Django>=1.9,<1.10"
diff --git a/AUTHORS b/AUTHORS
index 2852226..eefafda 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -37,6 +37,7 @@ Vitaliy Ivanov <https://github.com/vit-ivanov>
 Sergey Maranchuk <https://github.com/slav0nic>
 Martey Dodoo <https://github.com/martey>
 Michał Suszko <https://github.com/msuszko>
+Piter Vergara <https://github.com/pitervergara>
 
 
 Translators
diff --git a/CHANGELOG b/CHANGELOG
index 96f4ea1..0c2b07b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,12 @@ django-sitetree changelog
 =========================
 
 
+v1.8.0
+------
++ IMPORTANT: i18n trees now support full lang names (e.g. de-ch, pt-br), update your i18n trees aliases.
++ Django 1.11 compatibility improvements.
+
+
 v1.7.0
 ------
 * IMPORTANT: Caching reworked.
diff --git a/docs/source/i18n.rst b/docs/source/i18n.rst
index e2216fe..64902dd 100644
--- a/docs/source/i18n.rst
+++ b/docs/source/i18n.rst
@@ -31,11 +31,11 @@ Example:
     register_i18n_trees(['my_tree', 'my_another_tree'])
 
     # After that you need to create trees for languages supported
-    # in your project, e.g.: `my_tree_en`, `my_tree_ru`.
+    # in your project, e.g.: `my_tree_en`, `my_tree_ru`, `my_tree_pt-br`.
 
     # Then when we address ``my_tree`` from a template django-sitetree will render
     # an appropriate tree for locale currently active in your project.
     # See ``activate`` function from ``django.utils.translation``
-    # and https://docs.djangoproject.com/en/dev/topics/i18n/internationalization
+    # and https://docs.djangoproject.com/en/dev/topics/i18n/
     # for more information.
 
diff --git a/docs/source/tags.rst b/docs/source/tags.rst
index b85c49f..8ecdcb7 100644
--- a/docs/source/tags.rst
+++ b/docs/source/tags.rst
@@ -174,6 +174,18 @@ Usage example::
 This command renders current page description from tree named 'mytree'.
 
 
+.. _tag-page-hint:
+
+sitetree_page_hint
+------------------
+
+This tag is similar to `sitetree_page_description`, but it uses data from  tree item `hint` field instead of a `description` fields.
+
+Usage example::
+
+  {% sitetree_page_hint from "mytree" %}
+
+
 
 .. _tag-ignore-errors:
 
diff --git a/setup.py b/setup.py
index 507e68d..4bc99df 100755
--- a/setup.py
+++ b/setup.py
@@ -43,5 +43,6 @@ setup(
         'Programming Language :: Python :: 3.3',
         'Programming Language :: Python :: 3.4',
         'Programming Language :: Python :: 3.5',
+        'Programming Language :: Python :: 3.6',
     ],
 )
diff --git a/sitetree/__init__.py b/sitetree/__init__.py
index ae3dfcc..fde7f45 100644
--- a/sitetree/__init__.py
+++ b/sitetree/__init__.py
@@ -1,4 +1,4 @@
-VERSION = (1, 7, 0)
+VERSION = (1, 8, 0)
 
 
 default_app_config = 'sitetree.config.SitetreeConfig'
\ No newline at end of file
diff --git a/sitetree/sitetreeapp.py b/sitetree/sitetreeapp.py
index 90e9e95..dec2f89 100644
--- a/sitetree/sitetreeapp.py
+++ b/sitetree/sitetreeapp.py
@@ -60,6 +60,7 @@ _THREAD_LOCAL = local()
 _THREAD_SITETREE = 'sitetree'
 
 _URL_TAG_NEW_STYLE = VERSION >= (1, 5, 0)
+_CONTEXT_FLATTEN = VERSION >= (1, 11)
 
 _UNSET = set()  # Sentinel
 
@@ -388,7 +389,7 @@ class SiteTree(object):
         if alias not in _I18N_TREES:
             return alias
 
-        current_language_code = self.current_lang.replace('_', '-').split('-')[0]
+        current_language_code = self.current_lang
         i18n_tree_alias = '%s_%s' % (alias, current_language_code)
         trees_count = self.cache.get_entry('tree_aliases', i18n_tree_alias)
 
@@ -958,7 +959,7 @@ class SiteTree(object):
 
         context.push()
         context['sitetree_items'] = tree_items
-        rendered = my_template.render(context)
+        rendered = my_template.render(context.flatten() if _CONTEXT_FLATTEN else context)
         context.pop()
 
         return rendered
diff --git a/sitetree/templatetags/sitetree.py b/sitetree/templatetags/sitetree.py
index 706b5a5..75cb623 100644
--- a/sitetree/templatetags/sitetree.py
+++ b/sitetree/templatetags/sitetree.py
@@ -2,7 +2,7 @@ from django import template
 from django.template.loader import get_template
 from django.template.base import FilterExpression
 
-from ..sitetreeapp import get_sitetree
+from ..sitetreeapp import get_sitetree, _CONTEXT_FLATTEN
 
 
 register = template.Library()
@@ -301,7 +301,7 @@ def render(context, tree_items, use_template):
     if isinstance(use_template, FilterExpression):
         use_template = use_template.resolve(context)
 
-    content = get_template(use_template).render(context)
+    content = get_template(use_template).render(context.flatten() if _CONTEXT_FLATTEN else context)
     context.pop()
 
     return content
diff --git a/sitetree/tests/conftest.py b/sitetree/tests/conftest.py
index 1593092..55acfac 100644
--- a/sitetree/tests/conftest.py
+++ b/sitetree/tests/conftest.py
@@ -9,7 +9,7 @@ import pytest
 from django.http import HttpRequest
 from django.conf import settings, global_settings
 from django import VERSION
-from django.template.context import Context
+from django.template.context import Context, RenderContext
 from django.template.base import Template
 
 
@@ -75,8 +75,13 @@ class MockRequest(HttpRequest):
 
 
 def contribute_to_context(context, current_app=''):
-    context.template = mock.MagicMock()
-    context.template.engine.string_if_invalid = ''
+    template = mock.MagicMock()
+    template.engine.string_if_invalid = ''
+
+    context.template = template
+
+    if VERSION >= (1, 11):
+        context.render_context = RenderContext()
 
     if VERSION >= (1, 10):
         match = mock.MagicMock()
@@ -178,10 +183,19 @@ def render_template_tag():
     """
     def render(tag_library, tag_str, context=None):
         context = context or {}
-        context = Context(context)
+
+        if not isinstance(context, Context):
+            context = Context(context)
+
         contribute_to_context(context)
         string = '{%% load %s %%}{%% %s %%}' % (tag_library, tag_str)
-        return Template(string).render(context)
+        template = Template(string)
+
+        if VERSION >= (1, 11):
+            # Prevent "TypeError: 'NoneType' object is not iterable" in  get_exception_info
+            template.nodelist[1].token.position = (0, 0)
+
+        return template.render(context)
     return render
 
 
diff --git a/sitetree/tests/test_templatetags.py b/sitetree/tests/test_templatetags.py
index f480853..594c9eb 100644
--- a/sitetree/tests/test_templatetags.py
+++ b/sitetree/tests/test_templatetags.py
@@ -42,6 +42,14 @@ def test_i18n(build_tree, render_template_tag, mock_template_context):
         {'alias': 'i18tree_ru'},
         [{'title': 'Заголовок', 'url': '/url_ru/'}],
     )
+    build_tree(
+        {'alias': 'i18tree_pt-br'},
+        [{'title': 'Meu Título', 'url': '/url_pt-br/'}],
+    )
+    build_tree(
+        {'alias': 'i18tree_zh-hans'},
+        [{'title': '我蒂特', 'url': '/url_zh-hans/'}],
+    )
     register_i18n_trees(['i18tree'])
 
     activate('en')
@@ -56,6 +64,18 @@ def test_i18n(build_tree, render_template_tag, mock_template_context):
     assert '/url_ru/' in result
     assert 'Заголовок' in result
 
+    activate('pt-br')
+    result = render_template_tag('sitetree', 'sitetree_tree from "i18tree"', mock_template_context())
+
+    assert '/url_pt-br/' in result
+    assert 'Meu Título' in result
+
+    activate('zh-hans')
+    result = render_template_tag('sitetree', 'sitetree_tree from "i18tree"', mock_template_context())
+
+    assert '/url_zh-hans/' in result
+    assert '我蒂特' in result
+
     deactivate_all()
 
 
diff --git a/tox.ini b/tox.ini
index 1091c5b..595a850 100644
--- a/tox.ini
+++ b/tox.ini
@@ -3,8 +3,8 @@ install_command = pip install {opts} {packages}
 skip_missing_interpreters = True
 
 envlist =
-    py{27,32,33,34}-django{17,18,19,110}
-    py{35}-django{18,19,110}
+    py{27,32,33,34}-django{17,18,19,110,111}
+    py{35,36}-django{18,19,110,111}
 
 
 [testenv]
@@ -17,3 +17,4 @@ deps =
     django18: Django>=1.8,<1.9
     django19: Django>=1.9,<1.10
     django110: Django>=1.10,<1.11
+    django111: Django>=1.11,<1.12

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/django-sitetree.git



More information about the Python-modules-commits mailing list