Skip to content

Commit

Permalink
[fc] Repository: plone.app.dexterity
Browse files Browse the repository at this point in the history
Branch: refs/heads/master
Date: 2020-04-15T08:19:25+02:00
Author: Timo Stollenwerk (tisto) <stollenwerk@kitconcept.com>
Commit: plone/plone.app.dexterity@bac0225

Make sure getNextItem/getPreviousItem return None if position can not be looked up.

Files changed:
A news/308.bugfix
M plone/app/dexterity/behaviors/nextprevious.py
Repository: plone.app.dexterity

Branch: refs/heads/master
Date: 2020-04-15T11:14:57+02:00
Author: Timo Stollenwerk (tisto) <stollenwerk@kitconcept.com>
Commit: plone/plone.app.dexterity@92634f4

Remove check from getPreviousItem

Files changed:
M plone/app/dexterity/behaviors/nextprevious.py
Repository: plone.app.dexterity

Branch: refs/heads/master
Date: 2020-04-15T12:06:48+02:00
Author: Timo Stollenwerk (tisto) <stollenwerk@kitconcept.com>
Commit: plone/plone.app.dexterity@52a568e

Do not bail out if pos == 0.

Files changed:
M plone/app/dexterity/behaviors/nextprevious.py
Repository: plone.app.dexterity

Branch: refs/heads/master
Date: 2020-04-15T14:41:43+02:00
Author: Timo Stollenwerk (tisto) <tisto@users.noreply.github.com>
Commit: plone/plone.app.dexterity@2123921

Update 308.bugfix

Files changed:
M news/308.bugfix
Repository: plone.app.dexterity

Branch: refs/heads/master
Date: 2020-04-15T17:59:20+02:00
Author: Timo Stollenwerk (tisto) <tisto@users.noreply.github.com>
Commit: plone/plone.app.dexterity@df14b2e

Merge pull request #309 from plone/fix-308

Make sure getNextItem/getPreviousItem return None if position can not…

Files changed:
A news/308.bugfix
M plone/app/dexterity/behaviors/nextprevious.py
  • Loading branch information
tisto committed Apr 15, 2020
1 parent d72d256 commit 67d0b38
Showing 1 changed file with 60 additions and 23 deletions.
83 changes: 60 additions & 23 deletions last_commit.txt
@@ -1,42 +1,79 @@
Repository: plone.memoize
Repository: plone.app.dexterity


Branch: refs/heads/master
Date: 2020-04-11T16:43:46+02:00
Author: ale-rt (ale-rt) <alessandro.pisa@gmail.com>
Commit: https://github.com/plone/plone.memoize/commit/1c2963997942db9028c90a688af42eff44238b30
Date: 2020-04-15T08:19:25+02:00
Author: Timo Stollenwerk (tisto) <stollenwerk@kitconcept.com>
Commit: https://github.com/plone/plone.app.dexterity/commit/bac022545f46223c67259d35730b00035ef256e1

Use the global request
Make sure getNextItem/getPreviousItem return None if position can not be looked up.

Use the zope global request if available as a fallback if the context does not have it
Files changed:
A news/308.bugfix
M plone/app/dexterity/behaviors/nextprevious.py

b'diff --git a/news/308.bugfix b/news/308.bugfix\nnew file mode 100644\nindex 0000000..48f9c30\n--- /dev/null\n+++ b/news/308.bugfix\n@@ -0,0 +1 @@\n+Make sure getNextItem/getPreviousItem return None if position can not be looked up. [timo]\n\\ No newline at end of file\ndiff --git a/plone/app/dexterity/behaviors/nextprevious.py b/plone/app/dexterity/behaviors/nextprevious.py\nindex 30c63e3..3a203d8 100644\n--- a/plone/app/dexterity/behaviors/nextprevious.py\n+++ b/plone/app/dexterity/behaviors/nextprevious.py\n@@ -85,6 +85,8 @@ def getNextItem(self, obj):\n if not self.order:\n return None\n pos = self.context.getObjectPosition(obj.getId())\n+ if not pos:\n+ return None\n for oid in self.order[pos + 1:]:\n data = self.getData(self.context[oid])\n if data:\n@@ -96,6 +98,8 @@ def getPreviousItem(self, obj):\n return None\n order_reversed = list(reversed(self.order))\n pos = order_reversed.index(obj.getId())\n+ if not pos:\n+ return None\n for oid in order_reversed[pos + 1:]:\n data = self.getData(self.context[oid])\n if data:\n'

Repository: plone.app.dexterity


Branch: refs/heads/master
Date: 2020-04-15T11:14:57+02:00
Author: Timo Stollenwerk (tisto) <stollenwerk@kitconcept.com>
Commit: https://github.com/plone/plone.app.dexterity/commit/92634f4cf9bd64ba6ca3a018bbadf6af931fcc02

Remove check from getPreviousItem

Files changed:
M plone/app/dexterity/behaviors/nextprevious.py

b'diff --git a/plone/app/dexterity/behaviors/nextprevious.py b/plone/app/dexterity/behaviors/nextprevious.py\nindex 3a203d8..c3597e6 100644\n--- a/plone/app/dexterity/behaviors/nextprevious.py\n+++ b/plone/app/dexterity/behaviors/nextprevious.py\n@@ -98,8 +98,6 @@ def getPreviousItem(self, obj):\n return None\n order_reversed = list(reversed(self.order))\n pos = order_reversed.index(obj.getId())\n- if not pos:\n- return None\n for oid in order_reversed[pos + 1:]:\n data = self.getData(self.context[oid])\n if data:\n'

Repository: plone.app.dexterity


Branch: refs/heads/master
Date: 2020-04-15T12:06:48+02:00
Author: Timo Stollenwerk (tisto) <stollenwerk@kitconcept.com>
Commit: https://github.com/plone/plone.app.dexterity/commit/52a568ec77eb91d64324336cc2f41fd708864109

Do not bail out if pos == 0.

Files changed:
M plone/app/dexterity/behaviors/nextprevious.py

b'diff --git a/plone/app/dexterity/behaviors/nextprevious.py b/plone/app/dexterity/behaviors/nextprevious.py\nindex c3597e6..79f173d 100644\n--- a/plone/app/dexterity/behaviors/nextprevious.py\n+++ b/plone/app/dexterity/behaviors/nextprevious.py\n@@ -85,7 +85,7 @@ def getNextItem(self, obj):\n if not self.order:\n return None\n pos = self.context.getObjectPosition(obj.getId())\n- if not pos:\n+ if pos is None:\n return None\n for oid in self.order[pos + 1:]:\n data = self.getData(self.context[oid])\n'

Repository: plone.app.dexterity


Branch: refs/heads/master
Date: 2020-04-15T14:41:43+02:00
Author: Timo Stollenwerk (tisto) <tisto@users.noreply.github.com>
Commit: https://github.com/plone/plone.app.dexterity/commit/212392160908c19d351bef424f352e0b6617f73b

Fixes #17
Update 308.bugfix

Files changed:
A news/17.feature
M plone/memoize/view.py
M plone/memoize/view.rst
M setup.py
M news/308.bugfix

b'diff --git a/news/17.feature b/news/17.feature\nnew file mode 100644\nindex 0000000..59ae812\n--- /dev/null\n+++ b/news/17.feature\n@@ -0,0 +1 @@\n+Use the zope global request if available as a fallback if the context does not have it [ale-rt]\ndiff --git a/plone/memoize/view.py b/plone/memoize/view.py\nindex 1c5200d..549df62 100644\n--- a/plone/memoize/view.py\n+++ b/plone/memoize/view.py\n@@ -7,6 +7,14 @@\n from zope.annotation.interfaces import IAnnotations\n \n \n+try:\n+ from zope.globalrequest import getRequest\n+except ImportError:\n+\n+ def getRequest():\n+ return None\n+\n+\n class ViewMemo(object):\n \n key = "plone.memoize"\n@@ -17,9 +25,12 @@ def memogetter(*args, **kwargs):\n instance = args[0]\n \n context = getattr(instance, "context", None)\n- request = getattr(instance, "request", None)\n+ try:\n+ request = instance.request\n+ except AttributeError:\n+ request = getRequest()\n \n- annotations = IAnnotations(request)\n+ annotations = IAnnotations(request, {})\n if self.key not in annotations:\n annotations[self.key] = dict()\n cache = annotations[self.key]\n@@ -52,10 +63,18 @@ def memogetter(*args, **kwargs):\n \n def memoize_contextless(self, func):\n def memogetter(*args, **kwargs):\n- instance = args[0]\n- request = getattr(instance, "request", None)\n \n- annotations = IAnnotations(request)\n+ if args:\n+ instance = args[0]\n+ else:\n+ instance = None\n+\n+ try:\n+ request = instance.request\n+ except AttributeError:\n+ request = getRequest()\n+\n+ annotations = IAnnotations(request, {})\n if self.key not in annotations:\n annotations[self.key] = dict()\n cache = annotations[self.key]\ndiff --git a/plone/memoize/view.rst b/plone/memoize/view.rst\nindex 75da470..e9ad76f 100644\n--- a/plone/memoize/view.rst\n+++ b/plone/memoize/view.rst\n@@ -176,3 +176,72 @@ based on parameters, but not on context::\n >>> print(msg2.getAnotherMsg(\'J.D.\', **{\'raise\':\'roofbeams\'}))\n J.D.: so long, cruel world& raise--roofbeams\n \n+There is also support for using a global request\n+if zope.globalrequest is available.\n+With that you can cache also functions.\n+\n+If the global request is missing nothing changes:\n+\n+ >>> a = "foo"\n+ >>> @view.memoize_contextless\n+ ... def memoized_function():\n+ ... return a\n+ >>> memoized_function()\n+ \'foo\'\n+ >>> a = "bar"\n+ >>> memoized_function()\n+ \'bar\'\n+\n+Now we provide a global request which supports annotations:\n+\n+ >>> from zope.globalrequest import setRequest\n+ >>> from zope.interface import alsoProvides\n+ >>> from zope.annotation import IAttributeAnnotatable\n+ >>> global_request = TestRequest()\n+ >>> alsoProvides(global_request, IAttributeAnnotatable)\n+ >>> setRequest(global_request)\n+\n+With that in place the results are cached:\n+ >>> a = "foo"\n+ >>> memoized_function()\n+ \'foo\'\n+ >>> a = "bar"\n+ >>> memoized_function()\n+ \'foo\'\n+\n+\n+The same is true for an adapter:\n+\n+ >>> class Adapter(object):\n+ ...\n+ ... msg = "foo"\n+ ...\n+ ... def __init__(self, context):\n+ ... self.context = context\n+ ...\n+ ... @view.memoize\n+ ... def context_aware_function(self):\n+ ... return self.msg\n+ ...\n+ ... @view.memoize_contextless\n+ ... def context_unaware_function(self):\n+ ... return self.msg\n+\n+We now instatiate two objects:\n+ >>> instance1 = Adapter(Dummy())\n+ >>> instance2 = Adapter(Dummy())\n+ >>> instance1.context_aware_function()\n+ \'foo\'\n+ >>> instance1.context_unaware_function()\n+ \'foo\'\n+\n+Let\'s verify that the cache depends on the context:\n+ >>> Adapter.msg = "bar"\n+ >>> instance2.context_aware_function()\n+ \'bar\'\n+ >>> instance1.context_unaware_function()\n+ \'foo\'\n+\n+Still instance1 is not aware of the change:\n+ >>> instance1.context_aware_function()\n+ \'foo\'\ndiff --git a/setup.py b/setup.py\nindex be8e128..b4a624c 100644\n--- a/setup.py\n+++ b/setup.py\n@@ -50,7 +50,9 @@ def read(*rnames):\n include_package_data=True,\n zip_safe=False,\n test_suite="plone.memoize.tests.test_suite",\n- extras_require=dict(test=["zope.configuration", "zope.publisher",]),\n+ extras_require=dict(\n+ test=["zope.configuration", "zope.globalrequest", "zope.publisher",]\n+ ),\n install_requires=[\n "setuptools",\n "six",\n'
b'diff --git a/news/308.bugfix b/news/308.bugfix\nindex 48f9c30..e40168e 100644\n--- a/news/308.bugfix\n+++ b/news/308.bugfix\n@@ -1 +1 @@\n-Make sure getNextItem/getPreviousItem return None if position can not be looked up. [timo]\n\\ No newline at end of file\n+Make sure getNextItem function returns None if position can not be looked up. [timo]\n'

Repository: plone.memoize
Repository: plone.app.dexterity


Branch: refs/heads/master
Date: 2020-04-11T23:16:20+02:00
Author: Alessandro Pisa (ale-rt) <alessandro.pisa@gmail.com>
Commit: https://github.com/plone/plone.memoize/commit/f378dc665252fc1801eee70c51bec511b5dbf872
Date: 2020-04-15T17:59:20+02:00
Author: Timo Stollenwerk (tisto) <tisto@users.noreply.github.com>
Commit: https://github.com/plone/plone.app.dexterity/commit/df14b2e4261aae4249263ce0d2b4703269773abb

Merge pull request #22 from plone/17-use-global-request
Merge pull request #309 from plone/fix-308

Use the global request
Make sure getNextItem/getPreviousItem return None if position can not…

Files changed:
A news/17.feature
M plone/memoize/view.py
M plone/memoize/view.rst
M setup.py
A news/308.bugfix
M plone/app/dexterity/behaviors/nextprevious.py

b'diff --git a/news/17.feature b/news/17.feature\nnew file mode 100644\nindex 0000000..59ae812\n--- /dev/null\n+++ b/news/17.feature\n@@ -0,0 +1 @@\n+Use the zope global request if available as a fallback if the context does not have it [ale-rt]\ndiff --git a/plone/memoize/view.py b/plone/memoize/view.py\nindex 1c5200d..549df62 100644\n--- a/plone/memoize/view.py\n+++ b/plone/memoize/view.py\n@@ -7,6 +7,14 @@\n from zope.annotation.interfaces import IAnnotations\n \n \n+try:\n+ from zope.globalrequest import getRequest\n+except ImportError:\n+\n+ def getRequest():\n+ return None\n+\n+\n class ViewMemo(object):\n \n key = "plone.memoize"\n@@ -17,9 +25,12 @@ def memogetter(*args, **kwargs):\n instance = args[0]\n \n context = getattr(instance, "context", None)\n- request = getattr(instance, "request", None)\n+ try:\n+ request = instance.request\n+ except AttributeError:\n+ request = getRequest()\n \n- annotations = IAnnotations(request)\n+ annotations = IAnnotations(request, {})\n if self.key not in annotations:\n annotations[self.key] = dict()\n cache = annotations[self.key]\n@@ -52,10 +63,18 @@ def memogetter(*args, **kwargs):\n \n def memoize_contextless(self, func):\n def memogetter(*args, **kwargs):\n- instance = args[0]\n- request = getattr(instance, "request", None)\n \n- annotations = IAnnotations(request)\n+ if args:\n+ instance = args[0]\n+ else:\n+ instance = None\n+\n+ try:\n+ request = instance.request\n+ except AttributeError:\n+ request = getRequest()\n+\n+ annotations = IAnnotations(request, {})\n if self.key not in annotations:\n annotations[self.key] = dict()\n cache = annotations[self.key]\ndiff --git a/plone/memoize/view.rst b/plone/memoize/view.rst\nindex 75da470..e9ad76f 100644\n--- a/plone/memoize/view.rst\n+++ b/plone/memoize/view.rst\n@@ -176,3 +176,72 @@ based on parameters, but not on context::\n >>> print(msg2.getAnotherMsg(\'J.D.\', **{\'raise\':\'roofbeams\'}))\n J.D.: so long, cruel world& raise--roofbeams\n \n+There is also support for using a global request\n+if zope.globalrequest is available.\n+With that you can cache also functions.\n+\n+If the global request is missing nothing changes:\n+\n+ >>> a = "foo"\n+ >>> @view.memoize_contextless\n+ ... def memoized_function():\n+ ... return a\n+ >>> memoized_function()\n+ \'foo\'\n+ >>> a = "bar"\n+ >>> memoized_function()\n+ \'bar\'\n+\n+Now we provide a global request which supports annotations:\n+\n+ >>> from zope.globalrequest import setRequest\n+ >>> from zope.interface import alsoProvides\n+ >>> from zope.annotation import IAttributeAnnotatable\n+ >>> global_request = TestRequest()\n+ >>> alsoProvides(global_request, IAttributeAnnotatable)\n+ >>> setRequest(global_request)\n+\n+With that in place the results are cached:\n+ >>> a = "foo"\n+ >>> memoized_function()\n+ \'foo\'\n+ >>> a = "bar"\n+ >>> memoized_function()\n+ \'foo\'\n+\n+\n+The same is true for an adapter:\n+\n+ >>> class Adapter(object):\n+ ...\n+ ... msg = "foo"\n+ ...\n+ ... def __init__(self, context):\n+ ... self.context = context\n+ ...\n+ ... @view.memoize\n+ ... def context_aware_function(self):\n+ ... return self.msg\n+ ...\n+ ... @view.memoize_contextless\n+ ... def context_unaware_function(self):\n+ ... return self.msg\n+\n+We now instatiate two objects:\n+ >>> instance1 = Adapter(Dummy())\n+ >>> instance2 = Adapter(Dummy())\n+ >>> instance1.context_aware_function()\n+ \'foo\'\n+ >>> instance1.context_unaware_function()\n+ \'foo\'\n+\n+Let\'s verify that the cache depends on the context:\n+ >>> Adapter.msg = "bar"\n+ >>> instance2.context_aware_function()\n+ \'bar\'\n+ >>> instance1.context_unaware_function()\n+ \'foo\'\n+\n+Still instance1 is not aware of the change:\n+ >>> instance1.context_aware_function()\n+ \'foo\'\ndiff --git a/setup.py b/setup.py\nindex be8e128..b4a624c 100644\n--- a/setup.py\n+++ b/setup.py\n@@ -50,7 +50,9 @@ def read(*rnames):\n include_package_data=True,\n zip_safe=False,\n test_suite="plone.memoize.tests.test_suite",\n- extras_require=dict(test=["zope.configuration", "zope.publisher",]),\n+ extras_require=dict(\n+ test=["zope.configuration", "zope.globalrequest", "zope.publisher",]\n+ ),\n install_requires=[\n "setuptools",\n "six",\n'
b'diff --git a/news/308.bugfix b/news/308.bugfix\nnew file mode 100644\nindex 0000000..e40168e\n--- /dev/null\n+++ b/news/308.bugfix\n@@ -0,0 +1 @@\n+Make sure getNextItem function returns None if position can not be looked up. [timo]\ndiff --git a/plone/app/dexterity/behaviors/nextprevious.py b/plone/app/dexterity/behaviors/nextprevious.py\nindex 30c63e3..79f173d 100644\n--- a/plone/app/dexterity/behaviors/nextprevious.py\n+++ b/plone/app/dexterity/behaviors/nextprevious.py\n@@ -85,6 +85,8 @@ def getNextItem(self, obj):\n if not self.order:\n return None\n pos = self.context.getObjectPosition(obj.getId())\n+ if pos is None:\n+ return None\n for oid in self.order[pos + 1:]:\n data = self.getData(self.context[oid])\n if data:\n'

0 comments on commit 67d0b38

Please sign in to comment.