Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with dexterity collections and PTG #45

Open
volkerjaenisch opened this issue Oct 26, 2015 · 18 comments
Open

Issues with dexterity collections and PTG #45

volkerjaenisch opened this issue Oct 26, 2015 · 18 comments

Comments

@volkerjaenisch
Copy link

I noticed some problems with dexterity collections from plone.app.contenttypes in Plone4.3 and Plone5. Namely they do not work anymore.
There are four problems:

  1. 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.
  2. In dexterity the collections do no longer expose the getRawQuery function.
    See https://community.plone.org/t/where-is-defined-collection-getrawquery-and-how/1040 .
    This leads to a stack trace.
  3. If this problem is overcome the wrong image type is used in the query.
  4. And last but not least. The current code does not work with collections collecting subgalleries.

I 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.
Also 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.

from zope.component import adapts, getMultiAdapter
from Products.CMFCore.utils import getToolByName
from collective.plonetruegallery.galleryadapters.basic import \
    BasicTopicImageInformationRetriever as BTIIR
from Products.ATContentTypes.interface.image import IImageContent
from plone.app.contenttypes.interfaces import ICollection, IImage
from collective.plonetruegallery.interfaces import IBasicAdapter
from plone.app.querystring import queryparser
from collective.plonetruegallery.interfaces import IGalleryAdapter, IGallery
import types

try:
    from plone.uuid.interfaces import IUUID
except:
    def IUUID(_, _2=None):
        return None


try:
    from plone.app.contenttypes.behaviors.leadimage import ILeadImage
except ImportError:
    ILeadImage = None


class BasicCollectionImageInformationRetriever(BTIIR):
    adapts(ICollection, IBasicAdapter)

    def __init__(self, context, gallery_adapter):
        self.pm = getToolByName(context, 'portal_membership')
        self.context = context
        self.gallery_adapter = gallery_adapter

        def get_subgalleries(self, **kwargs):
            query = queryparser.parseFormquery(
            self.gallery, self.gallery.query)
            catalog = getToolByName(self.gallery, 'portal_catalog')
            if 'Subject' in kwargs:
                if not 'Subject' in query:
                    query.update({'Subject': kwargs['Subject']})
                else:
                    query['Subject'] = {'operator': 'and', 'query': [kwargs['Subject']] + query['Subject']['query']}


            if not 'object_provides' in query:
                query.update({'object_provides': IGallery.__identifier__})
            else:
                query['object_provides'] = {'operator': 'and', 'query': [IGallery.__identifier__] + query['object_provides']['query']}


            results = catalog(query)
            uid = IUUID(self.gallery, None)
            if uid is None:
                uid = self.gallery.UID()

            def afilter(i):
                """prevent same object and multiple nested galleries"""
                return i.UID != uid and \
                    getMultiAdapter(
                    (i.getObject(), self.request),
                    name='plonetruegallery_util'
                    ).enabled()

            return filter(afilter, results)
        self.gallery_adapter.get_subgalleries = types.MethodType(get_subgalleries, self.gallery_adapter)


    def getImageInformation(self):
        limit = self.context.limit
        query = queryparser.parseFormquery(
            self.context, self.context.query)
        if ILeadImage:
            query.update({
                'object_provides': {
                    'query': [
                        IImage.__identifier__,
                        ILeadImage.__identifier__],
                    'operator': 'or'
                }
            })
        else:
            query.update({'object_provides': IImage.__identifier__})
        query['sort_limit'] = limit
        catalog = getToolByName(self.context, 'portal_catalog')
        images = catalog(query)
        images = images[:limit]
        return map(self.assemble_image_information, images)
@mactrash
Copy link

mactrash commented Dec 13, 2016

May I know how to use this file? @volkerjaenisch

@volkerjaenisch
Copy link
Author

Just install collective.plonetruegallery . Then replace the collection.py file that lives in this package with the code shown above.

@mactrash
Copy link

@volkerjaenisch

Thanks for your reply, I am very new to this...

Do you mean after replay the file then I can use the gallery view in plone 5 collection?

@volkerjaenisch
Copy link
Author

volkerjaenisch commented Dec 14, 2016

Yes. We are using PTG with collections in Plone 5. You only need to replace this one file. If you get into problems feel free to ask.

@mactrash
Copy link

@volkerjaenisch I have follow the step you mentioned, buy the PTG gallery view still not show up in the selection list of my collections... any idea?

@volkerjaenisch
Copy link
Author

The alternative is to use my fork of PTG:
https://github.com/volkerjaenisch/collective.plonetruegallery

  • Check out or download the repository to zeoserver/src/collective.plonetruegallery
  • Alter your buildout.cfg file: Add
    develop =
    src/collective.plonetruegallery
  • run ./bin/buildout
  • restart your plone

@mactrash
Copy link

@volkerjaenisch thanks for your help

I try your method and now with collective.plonetruegallery 3.4.7.dev0 but there is no gallery view in the collection ... do i missed something my plone is Plone 5.0.6rc1 (5016) do I need to active "Archetypes Content Types for Plone" ?

@mactrash
Copy link

mactrash commented Dec 15, 2016

@volkerjaenisch and my plone.app.collection = 1.1.6
is that same as yours

@volkerjaenisch
Copy link
Author

The Version number 1.1.6 should not be an issue.
Please check the configuration for collections:
/dexterity-types/Collection/@@behaviors

The entry:
Plone True Gallery
Enable Plone True Gallery support
has to be enabled.

@volkerjaenisch
Copy link
Author

Tested with plone.app.collection = 1.1.6, works flawlessly.

@mactrash
Copy link

@volkerjaenisch

Thanks
Gallery view now show up in the collector and can be select but it got a error as below.

Traceback (innermost last):
Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module collective.plonetruegallery.browser.views.galleryview, line 29, in call
Module Products.Five.browser.pagetemplatefile, line 125, in call
Module Products.Five.browser.pagetemplatefile, line 59, in call
Module zope.pagetemplate.pagetemplate, line 132, in pt_render
Module five.pt.engine, line 98, in call
Module z3c.pt.pagetemplate, line 163, in render
Module chameleon.zpt.template, line 261, in render
Module chameleon.template, line 191, in render
Module chameleon.template, line 171, in render
Module d0e9d24677fac041b6f34863811f414d.py, line 459, in render
Module e3bbe0aa01b667bbf022121054b66185.py, line 1223, in render_master
Module e3bbe0aa01b667bbf022121054b66185.py, line 420, in render_content
Module d0e9d24677fac041b6f34863811f414d.py, line 447, in __fill_content_core
Module d0e9d24677fac041b6f34863811f414d.py, line 95, in render_content_core
Module collective.plonetruegallery.galleryadapters.base, line 100, in number_of_images
Module plone.memoize.instance, line 51, in memogetter
Module collective.plonetruegallery.galleryadapters.basic, line 155, in cooked_images
Module collective.plonetruegallery.galleryadapters.basic, line 142, in retrieve_images
Module zope.component._api, line 109, in getMultiAdapter
ComponentLookupError: ((<Collection at /test/test>, <collective.plonetruegallery.galleryadapters.basic.BasicAdapter object at 0x7f775d31b1d0>), , u'')

  • Expression: "python: view.adapter.number_of_images == 0"
  • Filename: ... ctive/plonetruegallery/browser/views/templates/layout.pt
  • Location: (line 22: col 45)
  • Source: ... :condition="python: view.adapter.number_of_images == 0">
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  • Arguments: repeat: {...} (0)
    template: <ViewPageTemplateFile - at 0x7f775c3ee810>
    views: <ViewMapper - at 0x7f775d31ba90>
    modules: <instance - at 0x24c6128>
    args: <tuple - at 0x7f7770417050>
    here: <ImplicitAcquisitionWrapper test at 0x917b690>
    user: <ImplicitAcquisitionWrapper - at 0x917bb40>
    loop: {...} (0)
    nothing: <NoneType - at 0x783160>
    container: <ImplicitAcquisitionWrapper test at 0x917b690>
    request: <instance - at 0x7f775d961200>
    wrapped_repeat: <SafeMapping - at 0x7f775d892470>
    traverse_subpath: <list - at 0x7f775d95b098>
    default: <object - at 0x7f77703dac00>
    context: <ImplicitAcquisitionWrapper test at 0x917b690>
    view: <SimpleViewClass from /opt/plone/buildout-cache/eggs/collective.plonetruegallery-3.4.7-py2.7.egg/collective/plonetruegallery/browser/views/templates/layout.pt galleryview at 0x7f775c959cd0>
    translate: <function translate at 0x7f775c937140>
    root: <ImplicitAcquisitionWrapper Zope at 0x7463d20>
    options: {...} (0)
    target_language: <NoneType - at 0x783160>

@volkerjaenisch
Copy link
Author

Are you sure that you have only images (Type Image) and No PDF-Files etc. in the collection?
Have you any Images in the collection?

@mactrash
Copy link

Yes, 1 jpg can show with Album view.

@volkerjaenisch
Copy link
Author

volkerjaenisch commented Dec 15, 2016

Can you please make sure that the alternative collectiv.plonetruegallery is really used:

  • Deinstall the collectiv.plonetruegallery package via
    <your plone url>/prefs_install_products_form
  • Stop Plone
  • Make sure there is no folder zeocluster/../buildout-cache/eggs/collective.plonetruegallery
  • run bin/buildout
  • Make sure there is no folder zeocluster/../buildout-cache/eggs/collective.plonetruegallery
    If there is your buildout is not correct. Post your buildout.cfg here
  • If there is no such folder
  • Start Plone
  • Install the collectiv.plonetruegallery package via /prefs_install_products_form

@mactrash
Copy link

Ok here is the result,

I don't know why it error and not build

sudo -u plone_buildout bin/buildout
Develop: '/opt/plone/zinstance/src/collective.plonetruegallery'
warning: no files found matching '.rst'
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching 'buildout.cfg'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'travis.cfg'
warning: no previously-included files matching '
.pyc' found anywhere in distribution
Uninstalling precompiler.
Uninstalling zopepy.
Uninstalling instance.

@volkerjaenisch
Copy link
Author

You have to enter the virtual environment first.
in zeoserver dir:
source bin/activate
./bin/buildout

If this fails please post the complete output

@mactrash
Copy link

@volkerjaenisch

It is working now, thanks alot.

@volkerjaenisch
Copy link
Author

you are welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants