[Python-modules-commits] [jinja2-time] 01/03: Import jinja2-time_0.2.0.orig.tar.gz

Vincent Bernat bernat at moszumanska.debian.org
Sat Jun 25 13:58:14 UTC 2016


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

bernat pushed a commit to branch master
in repository jinja2-time.

commit f9710120f6e8d04d60944ababa72261133d421a3
Author: Vincent Bernat <bernat at debian.org>
Date:   Sat Jun 25 15:53:59 2016 +0200

    Import jinja2-time_0.2.0.orig.tar.gz
---
 AUTHORS.rst                      | 13 -----------
 CONTRIBUTORS.rst                 | 21 +++++++++++++++++
 HISTORY.rst                      | 22 +++++++++++++++---
 MANIFEST.in                      |  2 +-
 PKG-INFO                         | 32 +++++++++++++++++++++++++-
 README.rst                       | 30 ++++++++++++++++++++++++
 jinja2_time.egg-info/PKG-INFO    | 32 +++++++++++++++++++++++++-
 jinja2_time.egg-info/SOURCES.txt |  2 +-
 jinja2_time/__init__.py          |  5 ++--
 jinja2_time/jinja2_time.py       | 49 ++++++++++++++++++++++++++++++++--------
 setup.cfg                        |  4 ++--
 setup.py                         |  2 +-
 tests/test_now.py                | 30 ++++++++++++++++++++++++
 13 files changed, 209 insertions(+), 35 deletions(-)

diff --git a/AUTHORS.rst b/AUTHORS.rst
deleted file mode 100644
index 79a7bd8..0000000
--- a/AUTHORS.rst
+++ /dev/null
@@ -1,13 +0,0 @@
-=======
-Credits
-=======
-
-Development Lead
-----------------
-
-* Raphael Pierzina <raphael at hackebrot.de>
-
-Contributors
-------------
-
-None yet. Why not be the first?
diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst
new file mode 100644
index 0000000..e7e3ace
--- /dev/null
+++ b/CONTRIBUTORS.rst
@@ -0,0 +1,21 @@
+=======
+Credits
+=======
+
+Development Lead
+----------------
+
+* Raphael Pierzina (`@hackebrot`_)
+
+Pull Requests and Patches
+-------------------------
+
+* Juan Madurga (`@jlmadurga`_)
+
+Bug Reports and Suggestions
+---------------------------
+
+None yet. Why not be the first?
+
+.. _`@hackebrot`: https://github.com/hackebrot
+.. _`@jlmadurga`: https://github.com/jlmadurga
diff --git a/HISTORY.rst b/HISTORY.rst
index e51dcd7..def3a74 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,7 +3,23 @@
 History
 -------
 
-0.1.0 (2015-12-05)
----------------------
+0.2.0 (2016-06-08)
+------------------
 
-* First release on PyPI.
+Features:
+
+* Relative time offset via ``"{% now 'utc' + 'hours=2,seconds=30' %}"`` or
+  ``-`` to modify the rendered datetime
+
+
+0.1.0 (2015-12-11)
+------------------
+
+First release on PyPI.
+
+Features:
+
+* TimeExtension with a ``now`` tag to get the current time in `jinja2`_
+  templates
+
+.. _`jinja2`: https://github.com/mitsuhiko/jinja2
diff --git a/MANIFEST.in b/MANIFEST.in
index 612633b..cdc7d0d 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,4 +1,4 @@
-include AUTHORS.rst
+include CONTRIBUTORS.rst
 include CONTRIBUTING.rst
 include HISTORY.rst
 include LICENSE
diff --git a/PKG-INFO b/PKG-INFO
index 09a4413..75d1155 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: jinja2-time
-Version: 0.1.0
+Version: 0.2.0
 Summary: Jinja2 Extension for Dates and Times
 Home-page: https://github.com/hackebrot/jinja2-time
 Author: Raphael Pierzina
@@ -99,6 +99,31 @@ Description: ===========
         
             template.render()
         
+        Time Offset
+        ~~~~~~~~~~~
+        
+        **jinja2-time** implements a convenient interface to modify ``now`` by a
+        relative time offset:
+        
+        .. code-block:: python
+        
+            # Examples for now "2015-12-09 23:33:01"
+        
+            # "Thu, 10 Dec 2015 01:33:31"
+            "{% now 'utc' + 'hours=2, seconds=30' %}"
+        
+            # "Wed, 09 Dec 2015 23:22:01"
+            "{% now 'utc' - 'minutes=11' %}"
+        
+            # "07 Dec 2015 23:00:00"
+            "{% now 'utc' - 'days=2, minutes=33, seconds=1', '%d %b %Y %H:%M:%S' %}"
+        
+        Further documentation on the underlying functionality can be found in the
+        `arrow replace docs`_.
+        
+        .. _`arrow replace docs`: http://arrow.readthedocs.io/en/latest/#replace-shift
+        
+        
         Issues
         ------
         
@@ -120,6 +145,11 @@ Description: ===========
         
         Distributed under the terms of the `MIT`_ license, jinja2-time is free and open source software
         
+        .. image:: https://opensource.org/trademarks/osi-certified/web/osi-certified-120x100.png
+           :align: left
+           :alt: OSI certified
+           :target: https://opensource.org/
+        
         .. _`MIT`: http://opensource.org/licenses/MIT
         
 Keywords: jinja2,extension,time
diff --git a/README.rst b/README.rst
index 6aa7a55..387677b 100644
--- a/README.rst
+++ b/README.rst
@@ -91,6 +91,31 @@ It is used as a fallback if you omit the format for ``now``.
 
     template.render()
 
+Time Offset
+~~~~~~~~~~~
+
+**jinja2-time** implements a convenient interface to modify ``now`` by a
+relative time offset:
+
+.. code-block:: python
+
+    # Examples for now "2015-12-09 23:33:01"
+
+    # "Thu, 10 Dec 2015 01:33:31"
+    "{% now 'utc' + 'hours=2, seconds=30' %}"
+
+    # "Wed, 09 Dec 2015 23:22:01"
+    "{% now 'utc' - 'minutes=11' %}"
+
+    # "07 Dec 2015 23:00:00"
+    "{% now 'utc' - 'days=2, minutes=33, seconds=1', '%d %b %Y %H:%M:%S' %}"
+
+Further documentation on the underlying functionality can be found in the
+`arrow replace docs`_.
+
+.. _`arrow replace docs`: http://arrow.readthedocs.io/en/latest/#replace-shift
+
+
 Issues
 ------
 
@@ -112,4 +137,9 @@ License
 
 Distributed under the terms of the `MIT`_ license, jinja2-time is free and open source software
 
+.. image:: https://opensource.org/trademarks/osi-certified/web/osi-certified-120x100.png
+   :align: left
+   :alt: OSI certified
+   :target: https://opensource.org/
+
 .. _`MIT`: http://opensource.org/licenses/MIT
diff --git a/jinja2_time.egg-info/PKG-INFO b/jinja2_time.egg-info/PKG-INFO
index 09a4413..75d1155 100644
--- a/jinja2_time.egg-info/PKG-INFO
+++ b/jinja2_time.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: jinja2-time
-Version: 0.1.0
+Version: 0.2.0
 Summary: Jinja2 Extension for Dates and Times
 Home-page: https://github.com/hackebrot/jinja2-time
 Author: Raphael Pierzina
@@ -99,6 +99,31 @@ Description: ===========
         
             template.render()
         
+        Time Offset
+        ~~~~~~~~~~~
+        
+        **jinja2-time** implements a convenient interface to modify ``now`` by a
+        relative time offset:
+        
+        .. code-block:: python
+        
+            # Examples for now "2015-12-09 23:33:01"
+        
+            # "Thu, 10 Dec 2015 01:33:31"
+            "{% now 'utc' + 'hours=2, seconds=30' %}"
+        
+            # "Wed, 09 Dec 2015 23:22:01"
+            "{% now 'utc' - 'minutes=11' %}"
+        
+            # "07 Dec 2015 23:00:00"
+            "{% now 'utc' - 'days=2, minutes=33, seconds=1', '%d %b %Y %H:%M:%S' %}"
+        
+        Further documentation on the underlying functionality can be found in the
+        `arrow replace docs`_.
+        
+        .. _`arrow replace docs`: http://arrow.readthedocs.io/en/latest/#replace-shift
+        
+        
         Issues
         ------
         
@@ -120,6 +145,11 @@ Description: ===========
         
         Distributed under the terms of the `MIT`_ license, jinja2-time is free and open source software
         
+        .. image:: https://opensource.org/trademarks/osi-certified/web/osi-certified-120x100.png
+           :align: left
+           :alt: OSI certified
+           :target: https://opensource.org/
+        
         .. _`MIT`: http://opensource.org/licenses/MIT
         
 Keywords: jinja2,extension,time
diff --git a/jinja2_time.egg-info/SOURCES.txt b/jinja2_time.egg-info/SOURCES.txt
index d2377b9..4c1f84a 100644
--- a/jinja2_time.egg-info/SOURCES.txt
+++ b/jinja2_time.egg-info/SOURCES.txt
@@ -1,5 +1,5 @@
-AUTHORS.rst
 CONTRIBUTING.rst
+CONTRIBUTORS.rst
 HISTORY.rst
 LICENSE
 MANIFEST.in
diff --git a/jinja2_time/__init__.py b/jinja2_time/__init__.py
index 1947395..d813a7b 100755
--- a/jinja2_time/__init__.py
+++ b/jinja2_time/__init__.py
@@ -1,9 +1,10 @@
 # -*- coding: utf-8 -*-
 
+from .jinja2_time import TimeExtension
+
 __author__ = 'Raphael Pierzina'
 __email__ = 'raphael at hackebrot.de'
-__version__ = '0.1.0'
+__version__ = '0.2.0'
 
-from .jinja2_time import TimeExtension
 
 __all__ = ['TimeExtension']
diff --git a/jinja2_time/jinja2_time.py b/jinja2_time/jinja2_time.py
index 281a151..ce713cb 100755
--- a/jinja2_time/jinja2_time.py
+++ b/jinja2_time/jinja2_time.py
@@ -13,24 +13,53 @@ class TimeExtension(Extension):
         super(TimeExtension, self).__init__(environment)
 
         # add the defaults to the environment
-        environment.extend(
-            datetime_format='%Y-%m-%d',
-        )
+        environment.extend(datetime_format='%Y-%m-%d')
+
+    def _datetime(self, timezone, operator, offset, datetime_format):
+        d = arrow.now(timezone)
+
+        # Parse replace kwargs from offset and include operator
+        replace_params = {}
+        for param in offset.split(','):
+            interval, value = param.split('=')
+            replace_params[interval.strip()] = float(operator + value.strip())
+        d = d.replace(**replace_params)
+
+        if datetime_format is None:
+            datetime_format = self.environment.datetime_format
+        return d.strftime(datetime_format)
 
     def _now(self, timezone, datetime_format):
-        datetime_format = datetime_format or self.environment.datetime_format
+        if datetime_format is None:
+            datetime_format = self.environment.datetime_format
         return arrow.now(timezone).strftime(datetime_format)
 
     def parse(self, parser):
         lineno = next(parser.stream).lineno
 
-        args = [parser.parse_expression()]
+        node = parser.parse_expression()
 
         if parser.stream.skip_if('comma'):
-            args.append(parser.parse_expression())
+            datetime_format = parser.parse_expression()
         else:
-            args.append(nodes.Const(None))
+            datetime_format = nodes.Const(None)
 
-        call = self.call_method('_now', args, lineno=lineno)
-
-        return nodes.Output([call], lineno=lineno)
+        if isinstance(node, nodes.Add):
+            call_method = self.call_method(
+                '_datetime',
+                [node.left, nodes.Const('+'), node.right, datetime_format],
+                lineno=lineno,
+            )
+        elif isinstance(node, nodes.Sub):
+            call_method = self.call_method(
+                '_datetime',
+                [node.left, nodes.Const('-'), node.right, datetime_format],
+                lineno=lineno,
+            )
+        else:
+            call_method = self.call_method(
+                '_now',
+                [node, datetime_format],
+                lineno=lineno,
+            )
+        return nodes.Output([call_method], lineno=lineno)
diff --git a/setup.cfg b/setup.cfg
index d20bcf3..b0136a0 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 0.1.0
+current_version = 0.2.0
 commit = True
 tag = True
 tag_name = {new_version}
@@ -13,6 +13,6 @@ universal = 1
 
 [egg_info]
 tag_build = 
-tag_date = 0
 tag_svn_revision = 0
+tag_date = 0
 
diff --git a/setup.py b/setup.py
index a87af9b..cf26716 100644
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@ def read(fname):
 
 setup(
     name='jinja2-time',
-    version='0.1.0',
+    version='0.2.0',
     author='Raphael Pierzina',
     author_email='raphael at hackebrot.de',
     maintainer='Raphael Pierzina',
diff --git a/tests/test_now.py b/tests/test_now.py
index 52858a0..306bb4e 100644
--- a/tests/test_now.py
+++ b/tests/test_now.py
@@ -49,3 +49,33 @@ def test_environment_datetime_format(environment):
     template = environment.from_string("{% now 'utc' %}")
 
     assert template.render() == "Wed, 09 Dec 2015 23:33:01"
+
+
+def test_add_time(environment):
+    environment.datetime_format = '%a, %d %b %Y %H:%M:%S'
+
+    template = environment.from_string(
+        "{% now 'utc' + 'hours=2,seconds=30' %}"
+    )
+
+    assert template.render() == "Thu, 10 Dec 2015 01:33:31"
+
+
+def test_substract_time(environment):
+    environment.datetime_format = '%a, %d %b %Y %H:%M:%S'
+
+    template = environment.from_string(
+        "{% now 'utc' - 'minutes=11' %}"
+    )
+
+    assert template.render() == "Wed, 09 Dec 2015 23:22:01"
+
+
+def test_offset_with_format(environment):
+    environment.datetime_format = '%d %b %Y %H:%M:%S'
+
+    template = environment.from_string(
+        "{% now 'utc' - 'days=2, minutes=33,seconds=1', '%d %b %Y %H:%M:%S' %}"
+    )
+
+    assert template.render() == "07 Dec 2015 23:00:00"

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



More information about the Python-modules-commits mailing list