{"action":"created","issue":{"url":"https://api.github.com/repos/collective/collective.plonetruegallery/issues/45","repository_url":"https://api.github.com/repos/collective/collective.plonetruegallery","labels_url":"https://api.github.com/repos/collective/collective.plonetruegallery/issues/45/labels{/name}","comments_url":"https://api.github.com/repos/collective/collective.plonetruegallery/issues/45/comments","events_url":"https://api.github.com/repos/collective/collective.plonetruegallery/issues/45/events","html_url":"https://github.com/collective/collective.plonetruegallery/issues/45","id":113451178,"number":45,"title":"Issues with dexterity collections and PTG","user":{"login":"volkerjaenisch","id":2539336,"avatar_url":"https://avatars.githubusercontent.com/u/2539336?v=3","gravatar_id":"","url":"https://api.github.com/users/volkerjaenisch","html_url":"https://github.com/volkerjaenisch","followers_url":"https://api.github.com/users/volkerjaenisch/followers","following_url":"https://api.github.com/users/volkerjaenisch/following{/other_user}","gists_url":"https://api.github.com/users/volkerjaenisch/gists{/gist_id}","starred_url":"https://api.github.com/users/volkerjaenisch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/volkerjaenisch/subscriptions","organizations_url":"https://api.github.com/users/volkerjaenisch/orgs","repos_url":"https://api.github.com/users/volkerjaenisch/repos","events_url":"https://api.github.com/users/volkerjaenisch/events{/privacy}","received_events_url":"https://api.github.com/users/volkerjaenisch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2015-10-26T21:05:08Z","updated_at":"2016-12-15T09:13:48Z","closed_at":null,"body":"I noticed some problems with dexterity collections from plone.app.contenttypes in Plone4.3 and Plone5. Namely they do not work anymore.\nThere are four problems:\n1) The collections adapter is bound to plone.app.collections.interfaces.ICollection but dexterity collections have plone.app.contenttypes.interfaces.ICollection as marker interface. So the adapter does not fit the interface.\n2) In dexterity the collections do no longer expose the getRawQuery function.\nSee https://community.plone.org/t/where-is-defined-collection-getrawquery-and-how/1040 .\nThis leads to a stack trace.\n3) If this problem is overcome the wrong image type is used in the query.\n4) And last but not least. The current code does not work with collections collecting subgalleries.\n\nI wrote a replacement to collection.py that fixes most of the problems but does not address all the corner cases. The code is ugly and obtains a monkey patch to change the get_subgalleries function of the basic_adapter. But it may be clear enough to show my intentions. \nAlso the code will not work with ATCollections - which is not a problem because this new adapter can be bound to the dexterity specific plone.app.contenttypes.interfaces.ICollection and live in friendly coexistence with the old adapter for ATCollections.\n\n``` python\nfrom zope.component import adapts, getMultiAdapter\nfrom Products.CMFCore.utils import getToolByName\nfrom collective.plonetruegallery.galleryadapters.basic import \\\n    BasicTopicImageInformationRetriever as BTIIR\nfrom Products.ATContentTypes.interface.image import IImageContent\nfrom plone.app.contenttypes.interfaces import ICollection, IImage\nfrom collective.plonetruegallery.interfaces import IBasicAdapter\nfrom plone.app.querystring import queryparser\nfrom collective.plonetruegallery.interfaces import IGalleryAdapter, IGallery\nimport types\n\ntry:\n    from plone.uuid.interfaces import IUUID\nexcept:\n    def IUUID(_, _2=None):\n        return None\n\n\ntry:\n    from plone.app.contenttypes.behaviors.leadimage import ILeadImage\nexcept ImportError:\n    ILeadImage = None\n\n\nclass BasicCollectionImageInformationRetriever(BTIIR):\n    adapts(ICollection, IBasicAdapter)\n\n    def __init__(self, context, gallery_adapter):\n        self.pm = getToolByName(context, 'portal_membership')\n        self.context = context\n        self.gallery_adapter = gallery_adapter\n\n        def get_subgalleries(self, **kwargs):\n            query = queryparser.parseFormquery(\n            self.gallery, self.gallery.query)\n            catalog = getToolByName(self.gallery, 'portal_catalog')\n            if 'Subject' in kwargs:\n                if not 'Subject' in query:\n                    query.update({'Subject': kwargs['Subject']})\n                else:\n                    query['Subject'] = {'operator': 'and', 'query': [kwargs['Subject']] + query['Subject']['query']}\n\n\n            if not 'object_provides' in query:\n                query.update({'object_provides': IGallery.__identifier__})\n            else:\n                query['object_provides'] = {'operator': 'and', 'query': [IGallery.__identifier__] + query['object_provides']['query']}\n\n\n            results = catalog(query)\n            uid = IUUID(self.gallery, None)\n            if uid is None:\n                uid = self.gallery.UID()\n\n            def afilter(i):\n                \"\"\"prevent same object and multiple nested galleries\"\"\"\n                return i.UID != uid and \\\n                    getMultiAdapter(\n                    (i.getObject(), self.request),\n                    name='plonetruegallery_util'\n                    ).enabled()\n\n            return filter(afilter, results)\n        self.gallery_adapter.get_subgalleries = types.MethodType(get_subgalleries, self.gallery_adapter)\n\n\n    def getImageInformation(self):\n        limit = self.context.limit\n        query = queryparser.parseFormquery(\n            self.context, self.context.query)\n        if ILeadImage:\n            query.update({\n                'object_provides': {\n                    'query': [\n                        IImage.__identifier__,\n                        ILeadImage.__identifier__],\n                    'operator': 'or'\n                }\n            })\n        else:\n            query.update({'object_provides': IImage.__identifier__})\n        query['sort_limit'] = limit\n        catalog = getToolByName(self.context, 'portal_catalog')\n        images = catalog(query)\n        images = images[:limit]\n        return map(self.assemble_image_information, images)\n\n```\n"},"comment":{"url":"https://api.github.com/repos/collective/collective.plonetruegallery/issues/comments/267276149","html_url":"https://github.com/collective/collective.plonetruegallery/issues/45#issuecomment-267276149","issue_url":"https://api.github.com/repos/collective/collective.plonetruegallery/issues/45","id":267276149,"user":{"login":"volkerjaenisch","id":2539336,"avatar_url":"https://avatars.githubusercontent.com/u/2539336?v=3","gravatar_id":"","url":"https://api.github.com/users/volkerjaenisch","html_url":"https://github.com/volkerjaenisch","followers_url":"https://api.github.com/users/volkerjaenisch/followers","following_url":"https://api.github.com/users/volkerjaenisch/following{/other_user}","gists_url":"https://api.github.com/users/volkerjaenisch/gists{/gist_id}","starred_url":"https://api.github.com/users/volkerjaenisch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/volkerjaenisch/subscriptions","organizations_url":"https://api.github.com/users/volkerjaenisch/orgs","repos_url":"https://api.github.com/users/volkerjaenisch/repos","events_url":"https://api.github.com/users/volkerjaenisch/events{/privacy}","received_events_url":"https://api.github.com/users/volkerjaenisch/received_events","type":"User","site_admin":false},"created_at":"2016-12-15T09:13:48Z","updated_at":"2016-12-15T09:13:48Z","body":"Tested with plone.app.collection = 1.1.6, works flawlessly."}}
{"actor":{"display_login":"volkerjaenisch"}}