[Python-modules-commits] [django-sekizai] 01/05: Import django-sekizai_0.9.0.orig.tar.gz

Michael Fladischer fladi at moszumanska.debian.org
Sat Dec 19 19:51:12 UTC 2015


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

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

commit cbe38b705eb5fecef3bfe58b07dbd1e2904d518d
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Sat Dec 19 20:01:09 2015 +0100

    Import django-sekizai_0.9.0.orig.tar.gz
---
 .travis.yml                           | 19 +++++++++++-
 README.rst                            |  3 +-
 docs/index.rst                        | 29 ++++++++++++++----
 sekizai/__init__.py                   |  2 +-
 sekizai/context_processors.py         |  6 ++--
 sekizai/context_processors.pyi        |  8 +++++
 sekizai/data.py                       | 58 +++++++++++++++++------------------
 sekizai/helpers.py                    | 22 +++++++------
 sekizai/helpers.pyi                   | 29 ++++++++++++++++++
 sekizai/templatetags/sekizai_tags.py  | 16 ++++++----
 sekizai/templatetags/sekizai_tags.pyi |  8 +++++
 sekizai/tests.py                      | 13 ++++++++
 setup.py                              | 33 ++++++++++++--------
 13 files changed, 177 insertions(+), 69 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 446a20b..acd985d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,11 @@
 language: python
+sudo: false
 python:
  - 2.6
  - 2.7
  - 3.3
  - 3.4
+ - 3.5
 env:
  - DJANGO='django>=1.3,<1.4'
  - DJANGO='django>=1.4,<1.5'
@@ -11,8 +13,9 @@ env:
  - DJANGO='django>=1.6,<1.7'
  - DJANGO='django>=1.7,<1.8'
  - DJANGO='django>=1.8,<1.9'
+ - DJANGO='django>=1.9,<1.10'
 install:
- - pip install $DJANGO django-classy-tags pep8
+ - pip install $DJANGO django-classy-tags pep8 backport-collections
 script: python runtests.py
 notifications:
   email: false
@@ -22,11 +25,25 @@ matrix:
       env: DJANGO='django>=1.7,<1.8'
     - python: 2.6
       env: DJANGO='django>=1.8,<1.9'
+    - python: 2.6
+      env: DJANGO='django>=1.9,<1.10'
     - python: 3.3
       env: DJANGO='django>=1.3,<1.4'
     - python: 3.3
       env: DJANGO='django>=1.4,<1.5'
+    - python: 3.3
+      env: DJANGO='django>=1.9,<1.10'
     - python: 3.4
       env: DJANGO='django>=1.3,<1.4'
     - python: 3.4
       env: DJANGO='django>=1.4,<1.5'
+    - python: 3.5
+      env: DJANGO='django>=1.3,<1.4'
+    - python: 3.5
+      env: DJANGO='django>=1.4,<1.5'
+    - python: 3.5
+      env: DJANGO='django>=1.5,<1.6'
+    - python: 3.5
+      env: DJANGO='django>=1.6,<1.7'
+    - python: 3.5
+      env: DJANGO='django>=1.7,<1.8'
diff --git a/README.rst b/README.rst
index 57c07ac..e351ba4 100644
--- a/README.rst
+++ b/README.rst
@@ -17,4 +17,5 @@ There are some issue/restrictions with this implementation due to how the
 django template language works, but if used properly it can be very useful and
 it is the media handling framework for the django CMS (since version 2.2).
 
-.. image:: https://secure.travis-ci.org/ojii/django-sekizai.png?branch=master
+.. image:: https://travis-ci.org/ojii/django-sekizai.svg?branch=master
+    :target: https://travis-ci.org/ojii/django-sekizai
diff --git a/docs/index.rst b/docs/index.rst
index bb82d29..a7e6779 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -31,10 +31,12 @@ sekizai will ignore any duplicate content in a single block.
 Dependencies
 ************
 
-* Python 2.6, 2.7, 3.3 or higher.
-* Django 1.3 or higher.
+* Python 2.6, 2.7, 3.3, 3.4 or 3.5.
+* Django 1.3, 1.4, 1.5, 1.6, 1.7, 1.8 or 1.9.
 * django-classy-tags 0.3.1 or higher.
 
+Python 2.6 requires ``backport_collections``.
+
 
 *****
 Usage
@@ -51,6 +53,9 @@ steps:
     * Put ``sekizai.context_processors.sekizai`` into your
       ``TEMPLATE_CONTEXT_PROCESSORS`` setting and use
       ``django.template.RequestContext`` when rendering your templates.
+    
+    or
+
     * Use ``sekizai.context.SekizaiContext`` when rendering your templates.
 
 
@@ -353,7 +358,7 @@ Your template (``inc.html``) might look like this::
     {% addtoblock "js" %}
     <script type="text/javascript">
     $(document).ready(function(){
-        $('#dynamic-conent-{{ userid }}').do_something();
+        $('#dynamic-content-{{ userid }}').do_something();
     }
     </script>
     {% endaddtoblock %}
@@ -402,18 +407,30 @@ And here's the rendered template::
     <script type="text/javascript" src="{{ MEDIA_URL }}js/libs/mylib.js"></script>
     <script type="text/javascript">
     $(document).ready(function(){
-        $('#dynamic-conent-1').do_something();
+        $('#dynamic-content-1').do_something();
     }
     </script>
     <script type="text/javascript">
     $(document).ready(function(){
-        $('#dynamic-conent-2').do_something();
+        $('#dynamic-content-2').do_something();
     }
     </script>
     <script type="text/javascript">
     $(document).ready(function(){
-        $('#dynamic-conent-3').do_something();
+        $('#dynamic-content-3').do_something();
     }
     </script>
     </body>
     </html>
+
+
+*********
+Changelog
+*********
+
+0.9.0
+=====
+
+* Added Changelog
+* Added support for Django 1.9
+* Added support for Python 3.5
diff --git a/sekizai/__init__.py b/sekizai/__init__.py
index 4ca39e7..e4e49b3 100644
--- a/sekizai/__init__.py
+++ b/sekizai/__init__.py
@@ -1 +1 @@
-__version__ = '0.8.2'
+__version__ = '0.9.0'
diff --git a/sekizai/context_processors.py b/sekizai/context_processors.py
index 97b500e..2c3051f 100644
--- a/sekizai/context_processors.py
+++ b/sekizai/context_processors.py
@@ -1,4 +1,6 @@
-from sekizai.data import SekizaiDictionary
+from collections import defaultdict
+
+from sekizai.data import UniqueSequence
 from sekizai.helpers import get_varname
 
 
@@ -7,4 +9,4 @@ def sekizai(request=None):
     Simple context processor which makes sure that the SekizaiDictionary is
     available in all templates.
     """
-    return {get_varname(): SekizaiDictionary()}
+    return {get_varname(): defaultdict(UniqueSequence)}
diff --git a/sekizai/context_processors.pyi b/sekizai/context_processors.pyi
new file mode 100644
index 0000000..aba0cbb
--- /dev/null
+++ b/sekizai/context_processors.pyi
@@ -0,0 +1,8 @@
+from typing import Dict, Union
+
+from django.http import HttpRequest
+
+from sekizai.data import UniqueSequence
+
+
+def sekizai(request: Union[None, HttpRequest]) -> Dict[str, UniqueSequence]: ...
diff --git a/sekizai/data.py b/sekizai/data.py
index c1b2f82..f652926 100644
--- a/sekizai/data.py
+++ b/sekizai/data.py
@@ -1,33 +1,31 @@
-class SekizaiList(list):
-    """
-    A sekizai namespace in a template.
-    """
-    def __init__(self, namespace):
-        self._namespace = namespace
-        super(SekizaiList, self).__init__()
-
-    def append(self, obj):
-        """
-        When content gets added, run the filters for this namespace.
-        """
-        if obj not in self:
-            super(SekizaiList, self).append(obj)
-
-    def render(self, between='\n'):
-        """
-        When the data get's rendered, run the postprocess filters.
-        """
-        return between.join(self)
-
-
-class SekizaiDictionary(dict):
-    """
-    A dictionary which auto fills itself instead of raising key errors.
-    """
+try:
+    from collections import MutableSequence
+except ImportError:
+    from backport_collections import MutableSequence
+
+
+class UniqueSequence(MutableSequence):
     def __init__(self):
-        super(SekizaiDictionary, self).__init__()
+        self.data = []
+
+    def __contains__(self, item):
+        return item in self.data
+
+    def __iter__(self):
+        return iter(self.data)
 
     def __getitem__(self, item):
-        if item not in self:
-            self[item] = SekizaiList(item)
-        return super(SekizaiDictionary, self).__getitem__(item)
+        return self.data[item]
+
+    def __setitem__(self, key, value):
+        self.data[key] = value
+
+    def __delitem__(self, key):
+        del self.data[key]
+
+    def __len__(self):
+        return len(self.data)
+
+    def insert(self, index, value):
+        if value not in self:
+            self.data.insert(index, value)
diff --git a/sekizai/helpers.py b/sekizai/helpers.py
index 9ed3e32..9678c56 100644
--- a/sekizai/helpers.py
+++ b/sekizai/helpers.py
@@ -1,8 +1,7 @@
 # -*- coding: utf-8 -*-
-from collections import namedtuple
 
 from django.conf import settings
-from django.template.base import VariableNode, Variable, Template
+from django.template.base import VariableNode, Variable, Context, Template
 from django.template.loader import get_template
 from django.template.loader_tags import BlockNode, ExtendsNode
 
@@ -11,12 +10,6 @@ try:
 except ImportError:
     engines = None
 
-if engines is not None:
-    _FAKE_TEMPLATE = (namedtuple('Template', 'engine')(engines.all()[0]))
-    FAKE_CONTEXT = namedtuple('Context', 'template')(_FAKE_TEMPLATE)
-else:
-    FAKE_CONTEXT = {}
-
 
 def _get_nodelist(tpl):
     if isinstance(tpl, Template):
@@ -35,6 +28,15 @@ def is_variable_extend_node(node):
     return False
 
 
+def get_context():
+    if engines is not None:
+        context = Context()
+        context.template = Template('')
+        return context
+    else:
+        return Context()
+
+
 def _extend_blocks(extend_node, blocks):
     """
     Extends the dictionary `blocks` with *new* blocks in the parent node
@@ -43,7 +45,7 @@ def _extend_blocks(extend_node, blocks):
     # we don't support variable extensions
     if is_variable_extend_node(extend_node):
         return
-    parent = extend_node.get_parent(FAKE_CONTEXT)
+    parent = extend_node.get_parent(get_context())
     # Search for new blocks
     for node in _get_nodelist(parent).get_nodes_by_type(BlockNode):
         if node.name not in blocks:
@@ -78,7 +80,7 @@ def _extend_nodelist(extend_node):
     for block in blocks.values():
         found += _scan_namespaces(block.nodelist, block)
 
-    parent_template = extend_node.get_parent(FAKE_CONTEXT)
+    parent_template = extend_node.get_parent(get_context())
     # if this is the topmost template, check for namespaces outside of blocks
     if not _get_nodelist(parent_template).get_nodes_by_type(ExtendsNode):
         found += _scan_namespaces(
diff --git a/sekizai/helpers.pyi b/sekizai/helpers.pyi
new file mode 100644
index 0000000..6f8982c
--- /dev/null
+++ b/sekizai/helpers.pyi
@@ -0,0 +1,29 @@
+from typing import Dict, List, Union
+
+from django.template.base import Template, NodeList, Node, Context
+
+def _get_nodelist(tpl: Template) -> NodeList: ...
+
+def is_variable_extend_node(node: Node) -> bool: ...
+
+def get_context() -> Context: ...
+
+def _extend_blocks(extend_node: Node, blocks: Dict[str, Node]): ...
+
+def _extend_nodelist(extend_node: Node) -> List[str]: ...
+
+def _scan_namespaces(nodelist: NodeList, current_block: Union[None, Node]) -> List[str]: ...
+
+def get_namespaces(template: str) -> List[str]: ...
+
+def validate_template(template: str, namespaces: List[str]) -> bool: ...
+
+def get_varname() -> str: ...
+
+class Watcher:
+    def __init__(self, context: Context) -> None: ...
+
+    @property
+    def data(self) -> dict: ...
+
+    def get_changes(self) -> dict: ...
diff --git a/sekizai/templatetags/sekizai_tags.py b/sekizai/templatetags/sekizai_tags.py
index 0ec80a2..1b4c86f 100644
--- a/sekizai/templatetags/sekizai_tags.py
+++ b/sekizai/templatetags/sekizai_tags.py
@@ -1,9 +1,13 @@
+try:
+    from importlib import import_module
+except ImportError:
+    from django.utils.importlib import import_module
+
 from classytags.arguments import Argument, Flag
 from classytags.core import Tag, Options
 from classytags.parser import Parser
 from django import template
 from django.conf import settings
-from django.utils.importlib import import_module
 
 from sekizai.helpers import get_varname
 
@@ -78,12 +82,12 @@ class RenderBlock(Tag):
             return nodelist.render(context)
         rendered_contents = nodelist.render(context)
         varname = get_varname()
-        data = context[varname][name].render()
+        data = '\n'.join(context[varname][name])
         if postprocessor:
             func = import_processor(postprocessor)
             data = func(context, data, name)
         return '%s\n%s' % (data, rendered_contents)
-register.tag(RenderBlock)
+register.tag('render_block', RenderBlock)
 
 
 class AddData(SekizaiTag):
@@ -98,7 +102,7 @@ class AddData(SekizaiTag):
         varname = get_varname()
         context[varname][key].append(value)
         return ''
-register.tag(AddData)
+register.tag('add_data', AddData)
 
 
 class WithData(SekizaiTag):
@@ -123,7 +127,7 @@ class WithData(SekizaiTag):
         inner_contents = inner_nodelist.render(context)
         context.pop()
         return '%s\n%s' % (inner_contents, rendered_contents)
-register.tag(WithData)
+register.tag('with_data', WithData)
 
 
 class Addtoblock(SekizaiTag):
@@ -147,4 +151,4 @@ class Addtoblock(SekizaiTag):
         varname = get_varname()
         context[varname][name].append(rendered_contents)
         return ""
-register.tag(Addtoblock)
+register.tag('addtoblock', Addtoblock)
diff --git a/sekizai/templatetags/sekizai_tags.pyi b/sekizai/templatetags/sekizai_tags.pyi
new file mode 100644
index 0000000..d607332
--- /dev/null
+++ b/sekizai/templatetags/sekizai_tags.pyi
@@ -0,0 +1,8 @@
+from types import ModuleType
+
+from django.template import Context
+
+
+def validate_context(context: Context) -> bool: ...
+
+def import_processor(import_path: str) -> ModuleType: ...
diff --git a/sekizai/tests.py b/sekizai/tests.py
index b8bf0cb..db401b7 100644
--- a/sekizai/tests.py
+++ b/sekizai/tests.py
@@ -164,6 +164,19 @@ class BitDiff(object):
 
 
 class SekizaiTestCase(TestCase):
+    @classmethod
+    def setUpClass(cls):
+        cls._template_dirs = settings.TEMPLATE_DIRS
+        template_dir = os.path.join(
+            os.path.dirname(__file__),
+            'test_templates'
+        )
+        settings.TEMPLATE_DIRS = list(cls._template_dirs) + [template_dir]
+
+    @classmethod
+    def tearDownClass(cls):
+        settings.TEMPLATE_DIRS = cls._template_dirs
+
     def _render(self, tpl, ctx=None, ctxclass=SekizaiContext):
         ctx = ctx or {}
         return render_to_string(tpl, ctxclass(ctx))
diff --git a/setup.py b/setup.py
index e35db4d..4928d11 100644
--- a/setup.py
+++ b/setup.py
@@ -1,22 +1,30 @@
+import sys
+
 from setuptools import setup, find_packages
 
 version = __import__('sekizai').__version__
 
+
+if sys.hexversion < 0x02070000:
+    EXTRA_INSTALL_REQUIRES = ['backport_collections']
+else:
+    EXTRA_INSTALL_REQUIRES = []
+
 setup(
-    name = 'django-sekizai',
-    version = version,
-    description = 'Django Sekizai',
-    author = 'Jonas Obrist',
-    author_email = 'ojiidotch at gmail.com',
-    url = 'http://github.com/ojii/django-sekizai',
-    packages = find_packages(),
+    name='django-sekizai',
+    version=version,
+    description='Django Sekizai',
+    author='Jonas Obrist',
+    author_email='ojiidotch at gmail.com',
+    url='http://github.com/ojii/django-sekizai',
+    packages=find_packages(),
     zip_safe=False,
     include_package_data=True,
-    install_requires = [
+    install_requires=[
         'django-classy-tags>=0.3.1',
-    ],
-    test_suite = 'runtests.main',
-    classifiers = [
+    ] + EXTRA_INSTALL_REQUIRES,
+    test_suite='runtests.main',
+    classifiers=[
         'Development Status :: 5 - Production/Stable',
         'Environment :: Web Environment',
         'Framework :: Django',
@@ -26,7 +34,8 @@ setup(
         'Programming Language :: Python',
         'Programming Language :: Python :: 2.6',
         'Programming Language :: Python :: 2.7',
-        'Programming Language :: Python :: 3.2',
         'Programming Language :: Python :: 3.3',
+        'Programming Language :: Python :: 3.4',
+        'Programming Language :: Python :: 3.5',
     ]
 )

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



More information about the Python-modules-commits mailing list