imio.helpers 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. imio/helpers/__init__.py +108 -0
  2. imio/helpers/adapters.py +112 -0
  3. imio/helpers/appy_pod.html +3197 -0
  4. imio/helpers/appy_pod.py +42 -0
  5. imio/helpers/barcode.py +32 -0
  6. imio/helpers/batching.py +227 -0
  7. imio/helpers/browser/__init__.py +1 -0
  8. imio/helpers/browser/configure.zcml +67 -0
  9. imio/helpers/browser/container.pt +81 -0
  10. imio/helpers/browser/content.pt +37 -0
  11. imio/helpers/browser/folder_listing.pt +17 -0
  12. imio/helpers/browser/folder_listing_table.pt +36 -0
  13. imio/helpers/browser/ramcache.pt +131 -0
  14. imio/helpers/browser/static/helpers.js +235 -0
  15. imio/helpers/browser/static/listings.js +27 -0
  16. imio/helpers/browser/views.py +102 -0
  17. imio/helpers/cache.py +278 -0
  18. imio/helpers/catalog.py +161 -0
  19. imio/helpers/configure.zcml +120 -0
  20. imio/helpers/content.py +756 -0
  21. imio/helpers/converters.py +22 -0
  22. imio/helpers/date.py +188 -0
  23. imio/helpers/emailer.py +280 -0
  24. imio/helpers/events.py +38 -0
  25. imio/helpers/events.zcml +26 -0
  26. imio/helpers/fancytree/__init__.py +0 -0
  27. imio/helpers/fancytree/configure.zcml +12 -0
  28. imio/helpers/fancytree/fancytree.js +19 -0
  29. imio/helpers/fancytree/fancytree.pt +30 -0
  30. imio/helpers/fancytree/views.py +73 -0
  31. imio/helpers/imageNotFound.jpg +0 -0
  32. imio/helpers/interfaces.py +19 -0
  33. imio/helpers/locales/fr/LC_MESSAGES/imio.helpers.po +80 -0
  34. imio/helpers/locales/imio.helpers.pot +83 -0
  35. imio/helpers/locales/manual.pot +30 -0
  36. imio/helpers/locales/update.sh +24 -0
  37. imio/helpers/patches.py +123 -0
  38. imio/helpers/path.py +9 -0
  39. imio/helpers/pdf.py +122 -0
  40. imio/helpers/profiles/default/browserlayer.xml +6 -0
  41. imio/helpers/profiles/default/jsregistry.xml +12 -0
  42. imio/helpers/profiles/default/metadata.xml +6 -0
  43. imio/helpers/profiles/testing/metadata.xml +8 -0
  44. imio/helpers/profiles/testing/types/testingtype.xml +87 -0
  45. imio/helpers/profiles/testing/types.xml +5 -0
  46. imio/helpers/ram.py +99 -0
  47. imio/helpers/security.py +217 -0
  48. imio/helpers/setup.py +127 -0
  49. imio/helpers/test_helpers.py +90 -0
  50. imio/helpers/testing.py +115 -0
  51. imio/helpers/testing.zcml +28 -0
  52. imio/helpers/tests/__init__.py +0 -0
  53. imio/helpers/tests/barcode_python2_zint_60x60_278bytes.png +0 -0
  54. imio/helpers/tests/barcode_python3_zint_60x60_156bytes.png +0 -0
  55. imio/helpers/tests/dot.gif +0 -0
  56. imio/helpers/tests/indexes.py +19 -0
  57. imio/helpers/tests/test_appy_pod.py +44 -0
  58. imio/helpers/tests/test_barcode.py +26 -0
  59. imio/helpers/tests/test_batching.py +240 -0
  60. imio/helpers/tests/test_cache.py +509 -0
  61. imio/helpers/tests/test_catalog.py +248 -0
  62. imio/helpers/tests/test_content.py +506 -0
  63. imio/helpers/tests/test_converters.py +41 -0
  64. imio/helpers/tests/test_date.py +65 -0
  65. imio/helpers/tests/test_email.py +200 -0
  66. imio/helpers/tests/test_fancytree.py +95 -0
  67. imio/helpers/tests/test_path.py +16 -0
  68. imio/helpers/tests/test_security.py +102 -0
  69. imio/helpers/tests/test_setup.py +100 -0
  70. imio/helpers/tests/test_testing.py +16 -0
  71. imio/helpers/tests/test_transmogrifier.py +184 -0
  72. imio/helpers/tests/test_vocabularies.py +81 -0
  73. imio/helpers/tests/test_workflow.py +101 -0
  74. imio/helpers/tests/test_xhtml.py +942 -0
  75. imio/helpers/tests/utils.py +32 -0
  76. imio/helpers/tests/vocabularies.py +22 -0
  77. imio/helpers/transmogrifier.py +269 -0
  78. imio/helpers/utils.py +28 -0
  79. imio/helpers/vocabularies.py +105 -0
  80. imio/helpers/workflow.py +124 -0
  81. imio/helpers/xhtml.py +802 -0
  82. imio.helpers-1.0.0-py3.11-nspkg.pth +1 -0
  83. imio.helpers-1.0.0.dist-info/METADATA +1350 -0
  84. imio.helpers-1.0.0.dist-info/RECORD +88 -0
  85. imio.helpers-1.0.0.dist-info/WHEEL +5 -0
  86. imio.helpers-1.0.0.dist-info/entry_points.txt +2 -0
  87. imio.helpers-1.0.0.dist-info/namespace_packages.txt +1 -0
  88. imio.helpers-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,108 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from datetime import date
4
+ from datetime import datetime
5
+ from imio.helpers.cache import get_cachekey_volatile
6
+ from plone import api
7
+ from plone.memoize import ram as pmram
8
+ from Products.PlonePAS.plugins.role import GroupAwareRoleManager
9
+ from Products.PlonePAS.tools.groups import GroupsTool
10
+ from Products.PluggableAuthService.PluggableAuthService import PluggableAuthService
11
+ from zope.globalrequest import getRequest
12
+ from zope.i18nmessageid import MessageFactory
13
+
14
+ import logging
15
+ import os
16
+
17
+
18
+ _ = MessageFactory("imio.helpers")
19
+ logger = logging.getLogger("imio.helpers")
20
+
21
+ HAS_PLONE_4 = api.env.plone_version().startswith("4")
22
+ HAS_PLONE_5 = api.env.plone_version().startswith("5")
23
+ HAS_PLONE_5_1 = api.env.plone_version() > "5.1"
24
+ HAS_PLONE_5_2 = api.env.plone_version() > "5.2"
25
+ HAS_PLONE_5_AND_MORE = int(api.env.plone_version()[0]) >= 5
26
+ PLONE_MAJOR_VERSION = int(api.env.plone_version()[0])
27
+
28
+ EMPTY_TITLE = "No value"
29
+ EMPTY_STRING = "__empty_string__"
30
+ EMPTY_DATE = date(1950, 1, 1)
31
+ EMPTY_DATETIME = datetime(1950, 1, 1, 12, 0)
32
+
33
+
34
+ def GroupsTool__getGroupsForPrincipal_cachekey(method, self, principal):
35
+ req = getRequest()
36
+ if req is None:
37
+ raise pmram.DontCache
38
+ date = get_cachekey_volatile("_users_groups_value")
39
+ return date, principal and principal.getId()
40
+
41
+
42
+ def GroupAwareRoleManager__getRolesForPrincipal_cachekey(method, self, principal, request=None):
43
+ req = request or getRequest()
44
+ # if req is None:
45
+ # raise pmram.DontCache
46
+ date = get_cachekey_volatile("_users_groups_value")
47
+ return (
48
+ date,
49
+ principal and principal.getId(),
50
+ repr(req),
51
+ req and (req.get("__ignore_direct_roles__", False), req.get("__ignore_group_roles__", False)) or (None, None),
52
+ )
53
+
54
+
55
+ def PluggableAuthService__getGroupsForPrincipal_cachekey(method, self, principal, request=None, **kwargs):
56
+ req = request or getRequest()
57
+ if req is None:
58
+ raise pmram.DontCache
59
+ try:
60
+ date = get_cachekey_volatile("_users_groups_value")
61
+ except api.portal.CannotGetPortalError:
62
+ raise pmram.DontCache
63
+ return date, principal and principal.getId()
64
+
65
+
66
+ def PluggableAuthService__findUser_cachekey(method, self, plugins, user_id, name=None, request=None):
67
+ req = request or getRequest()
68
+ if req is None:
69
+ raise pmram.DontCache
70
+ try:
71
+ date = get_cachekey_volatile("_users_groups_value")
72
+ except api.portal.CannotGetPortalError:
73
+ raise pmram.DontCache
74
+ return date, repr(plugins), user_id, name, str(req and req._debug or "")
75
+
76
+
77
+ def PluggableAuthService__verifyUser_cachekey(method, self, plugins, user_id=None, login=None):
78
+ req = getRequest()
79
+ if req is None:
80
+ raise pmram.DontCache
81
+
82
+ date = get_cachekey_volatile("_users_groups_value")
83
+ return date, repr(plugins), user_id, login
84
+
85
+
86
+ def GroupsTool_getGroupById_cachekey(method, self, group_id):
87
+ req = getRequest()
88
+ if req is None:
89
+ raise pmram.DontCache
90
+
91
+ date = get_cachekey_volatile("_users_groups_value")
92
+ return date, group_id
93
+
94
+
95
+ if os.getenv("decorate_acl_methods", "Nope") in ("True", "true"):
96
+ logger.info("DECORATING various acl related methods with cache")
97
+ decorator = pmram.cache(GroupsTool__getGroupsForPrincipal_cachekey)
98
+ GroupsTool.getGroupsForPrincipal = decorator(GroupsTool.getGroupsForPrincipal)
99
+ decorator = pmram.cache(GroupAwareRoleManager__getRolesForPrincipal_cachekey)
100
+ GroupAwareRoleManager.getRolesForPrincipal = decorator(GroupAwareRoleManager.getRolesForPrincipal)
101
+ decorator = pmram.cache(PluggableAuthService__getGroupsForPrincipal_cachekey)
102
+ PluggableAuthService._getGroupsForPrincipal = decorator(PluggableAuthService._getGroupsForPrincipal)
103
+ # decorator = pmram.cache(PluggableAuthService__findUser_cachekey)
104
+ # PluggableAuthService._findUser = decorator(PluggableAuthService._findUser)
105
+ # decorator = pmram.cache(PluggableAuthService__verifyUser_cachekey)
106
+ # PluggableAuthService._verifyUser = decorator(PluggableAuthService._verifyUser)
107
+ decorator = pmram.cache(GroupsTool_getGroupById_cachekey)
108
+ GroupsTool.getGroupById = decorator(GroupsTool.getGroupById)
@@ -0,0 +1,112 @@
1
+ # -*- coding: utf-8 -*-
2
+ from plone import api
3
+ from z3c.form.interfaces import IContextAware
4
+ from z3c.form.interfaces import IDataManager
5
+ from z3c.form.term import MissingTermsMixin
6
+ from zope.component import getMultiAdapter
7
+
8
+
9
+ class ListContainedDexterityObjectsForDisplayAdapter(object):
10
+ """ Return the dexterity objects contained, moreover the returned
11
+ elements are renderable for display.
12
+ element.context is the contained object
13
+ element.widgets are the renderable widgets of the object
14
+ """
15
+
16
+ def __init__(self, context):
17
+ self.context = context
18
+
19
+ def listContainedObjects(self, portal_types=(), widgets_to_render=(), b_start=0, b_size=30):
20
+ """ Return a list of renderable objects.
21
+ If p_portal_types is given, filter on portal_type in the catalog query.
22
+ If p_widgets_to_render is given, only render given fields/widgets."""
23
+ res = []
24
+ params = {}
25
+ params['path'] = {'query': '/'.join(self.context.getPhysicalPath()),
26
+ 'depth': 1}
27
+ params['sort_on'] = 'getObjPositionInParent'
28
+ # make sure we only list dexterity objects
29
+ params['object_provides'] = 'plone.dexterity.interfaces.IDexterityContent'
30
+
31
+ if portal_types:
32
+ params['portal_type'] = portal_types
33
+ request = self.context.REQUEST
34
+ i = 0
35
+ catalog = api.portal.get_tool('portal_catalog')
36
+ for brain in catalog(**params):
37
+ # manage the batch to avoid rendering elements that are not shown
38
+ # manage elements before currently shown ones...
39
+ # and manage elements after currently shown ones
40
+ if b_start and i < b_start or \
41
+ i > (b_start + b_size):
42
+ i = i + 1
43
+ res.append(None)
44
+ continue
45
+
46
+ obj = brain.getObject()
47
+ renderedAction = getMultiAdapter((obj, request), name='view')
48
+ renderedAction.updateFieldsFromSchemata()
49
+ for field in renderedAction.fields:
50
+ if widgets_to_render and field not in widgets_to_render:
51
+ renderedAction.fields = renderedAction.fields.omit(field)
52
+ renderedAction.updateWidgets()
53
+ res.append(renderedAction)
54
+ i = i + 1
55
+ return res
56
+
57
+
58
+ class MissingTerms(MissingTermsMixin):
59
+ """Base MissingTerms adapter to be used in local package."""
60
+
61
+ complete_voc = NotImplemented
62
+ field = NotImplemented
63
+ widget = NotImplemented
64
+
65
+ def getTerm(self, value):
66
+ try:
67
+ return super(MissingTermsMixin, self).getTerm(value) # noqa
68
+ except LookupError:
69
+ try:
70
+ return self.complete_voc().getTerm(value)
71
+ except LookupError:
72
+ pass
73
+ if IContextAware.providedBy(self.widget) and not self.widget.ignoreContext:
74
+ cur_value = getMultiAdapter((self.widget.context, self.field), IDataManager).query()
75
+ if cur_value == value:
76
+ return self._makeMissingTerm(value)
77
+ raise
78
+
79
+ def getTermByToken(self, token):
80
+ try:
81
+ return super(MissingTermsMixin, self).getTermByToken(token) # noqa
82
+ except LookupError:
83
+ try:
84
+ return self.complete_voc().getTermByToken(token)
85
+ except LookupError:
86
+ pass
87
+ if IContextAware.providedBy(self.widget) and not self.widget.ignoreContext:
88
+ value = getMultiAdapter((self.widget.context, self.field), IDataManager).query()
89
+ term = self._makeMissingTerm(value)
90
+ if term.token == token:
91
+ return term
92
+ raise LookupError(token)
93
+
94
+
95
+ try:
96
+ from z3c.table.column import LinkColumn
97
+ from html import escape # noqa
98
+
99
+ class NoEscapeLinkColumn(LinkColumn):
100
+ """Do not escape link content (made in z3c.table >= 2.1.1)"""
101
+
102
+ def renderCell(self, item):
103
+ # setup a tag
104
+ return '<a href="%s"%s%s%s>%s</a>' % (
105
+ escape(self.getLinkURL(item)),
106
+ self.getLinkTarget(item),
107
+ self.getLinkCSS(item),
108
+ self.getLinkTitle(item), # internally escaped
109
+ self.getLinkContent(item), # originally escaped
110
+ )
111
+ except ImportError:
112
+ pass