A finder to search/select portal objects for Plone
Ajax popup to browse and select plone contents, suitable to any plone.formilb form (portlets, control panels, …)
This code is an extraction with some refactoring, of PloneArticle explorer used for referencables proxies.
The intent is to make it usable in various situations:
This work has been started at Ingeniweb in 2007 by Christophe Bosse (for the jQuery code) and Jean-Mat Grimaldi (everything else) for PloneArticle product.
Plone add-ons developers only
This is a component for Plone add-ons developers. Do not expect to add anything more in yous site if you install only this component to your Zope instance.
A reference widget for zope3 forms (zope.app.form) is provided with this product.
The widget can be used to store objects references in a sequence field.
Example of use in a portlet form for a Tuple field named target_contents:
from collective.plonefinder.widgets.referencewidget import FinderSelectWidget target_contents = schema.Tuple(title=u"Browse for contents", description=(u"Choose contents to display " u"with a plone finder window."), default=() ) form_fields['target_contents'].custom_widget = FinderSelectWidget
You can use the FinderSelectWidget with some properties set using the update method in your AddForm or EditForm. In example for a portlet AddForm:
class AddForm(base.AddForm): """Portlet add form. """ form_fields = form.Fields(IReferencesPortlet) form_fields['targets'].custom_widget = FinderSelectWidget label = u"Add References Portlet" def update(self): super(AddForm, self).update() self.widgets['targets'].typeview = 'image' self.widgets['targets'].forcecloseoninsert = 1 def create(self, data): return Assignment(**data)
If you want, you can also pass a context as base for the widget, to get the current or parent folder open in the finder. Example in a portlet using the update method:
assignment = aq_parent(aq_inner(self.context)) self.widgets['targets'].base = aq_parent(aq_inner(assignment))
There are also two customized widgets for files and images. Look at the code to create your own specific widget.
Example of code for files referencing with files upload support:
from collective.plonefinder.widgets.referencewidget import FinderSelectFileWidget target_files = schema.Tuple(title=u"Browse for images", description=(u"Choose files to display " u"with a plone finder window. " u"You can upload new files."), default=() ) form_fields['target_files'].custom_widget = FinderSelectFileWidget
Example of code for images referencing with images upload support:
from collective.plonefinder.widgets.referencewidget import FinderSelectImageWidget target_images = schema.Tuple (title=u"Browse for images", description=(u"Choose images to display " u"with a plone finder window. " u"You can select different image sizes. " u"You can upload new images."), default= () ) form_fields['target_images'].custom_widget = FinderSelectImageWidget
Note that in this last case the data store image uid and image thumb size like this:
'%s/%s' % (image.UID(), thumb_size_extension)
thumb_size_extension could be 'image_thumb' or 'image_preview' …
So use something like this to display a referenced image:
uid, variant = data.split('/') '<img src="%s/resolveuid/%s/%s" />' % (portal_url, uid, variant)
|finderlabel||_(u'Browse for contents')||Customize the title of the Browser window. i.e. "Find the pictures"|
|moveuplabel||_(u'Move up')||Label associated with the up arrow widget that raises the order of the reference. i.e. "Increase priority".|
|movedownlabel||_(u'Move down')||Label associated with the down arrow widget that lowers the order of the reference. i.e. "Decrease priority".|
|deleteentrylabel||_(u'Remove item')||Label associated with the “Remove from list” widget. i.e. "Remove this video".|
|types||() # All types||List of selectable portal types to show in the selection panel. i.e. ['Document']|
|typeview||'file'||Possible values are 'file', 'image' and 'selection'. Tuning on selection panel layout.|
|imagetypes||('Image', 'News Item')||Sequence of portal types that can handle images (see Todo)|
|selectiontype||'uid'||Selected items are returned to the application (form) as UIDs. Other possible value is 'url'.|
|showsearchbox||True||Do we show the searchbox?|
|allowupload||False||Do we enable upload files through our widget if the user has appropriate permission? See Uploadding in custom folderish type|
|openuploadwidgetdefault||False||Do we display the upload widget by default?|
|allowaddfolder||False||Do we enable adding new folders through our widget if the user has appropriate permission?|
|allowimagesizeselection||False||If the image has multiple sizes, do we enable the selection of a particular size? (See the above note)|
|forcecloseoninsert||False||Do we close the finder when an element is selected?|
|base||None||The folderish object used as root of the finder when opening. None means the Plone site. Note that by nature, this attribute cannot be set statically, in a FinderSelectWidget personal subclass for example as other can be. See the example in simple customizations on how to change the widget base attribute dynamically from the form class code.|
See collective.ckeditor package as example.
If you want to let the plone finder users upload files in your custom or third party folderish content types, you need to mark these types with the IFinderUploadCapable marker interface. As in this self-speaking ZCML sample:
<class class="my.content.folderish.MyFolderish"> <implements interface="collective.plonefinder.browser.interfaces.IFinderUploadCapable" /> </class>
Out of the box, collective.plonefinder enables upload in the Plone site itself as well as in ATFolder and ATBTreeFolder.
Any contribution is welcome, contact email@example.com.
Add formlib FinderImageWidget; use with
# in interface class picture = schema.TextLine(title=_(u'Picture'), description=_(u'Optional picture'), required=False) # in form class form_fields['picture'].custom_widget = FinderImageWidget