How to make a dexterity reference field? - plone

Using Plone 4.3 (from https://raw.github.com/plock/pins/master/plone-4-3) and trying to make a reference field between two dexterity contents: from IConsumibleEntry to IConsumibleItem.
If I'm understand correctly, I have to add a RelationChoice into IConsumibleEntry with a ObjPathSourceBinder and then all related IConsumibleItem will appear in the add form. I'm following http://docs.plone.org/external/plone.app.dexterity/docs/advanced/references.html so I did:
from mypackage.consumibles.consumible_item import IConsumibleItem
class IConsumibleEntry(form.Schema, IImageScaleTraversable):
item = RelationChoice(
title=_(u"Item"),
source=ObjPathSourceBinder(object_provides=IConsumibleItem.__identifier__),
required=True,
)
I run plone and created several IConsumibleItem instances, but when I try to create an IConsumibleEntry, there's nothing to chose for the 'item' field.
I tried using other expressions for ObjPathSourceBinder, like chosing by content type, but I still can't get any reference to IConsumibleItem instances.
What else is needed to do to get reference fields populated? Is in needed to modify IConsumibleItem? What am I missing?
Thanks in advance.

Related

Sonata bundle editable date field

Sonat admin bundle allow to edit only text fields and boolean, i would like to know if there a way to override sonata make it edit datetime/date fields.
Thank you in advance!
At this time , they only support scalar types :
Theses types accept an editable parameter to edit the value from within the list action. This is currently limited to scalar types (text, integer, url...).
https://sonata-project.org/bundles/admin/master/doc/reference/field_types.html
I guess to have to digg more into the documentation to get it working. ( See how scalar types are dealt with and try to write similar logic )
Not sure in which version they added this (can't find it in the change log), but in admin bundle 3.8.0 adding 'editable' => true' to a date field in a list makes it editable alright. The value becomes underlined with a dashed line and clicking it opens a jQuery date selector.

I need to edit a existing form in plone

I've never used plone but I need to edit a form to add a field. I've already looked everywhere but I can't find anything to do this, is there portal_type?
It's a big problem we have on my company, last programmer ran away and left us with Plone :\
Thanks.
Look at your URL, find the Name View, the last Part of url, e.g /fileupload-form
Search with grep on the Commandline in your Productfolder to the Name, you can find a Browserview with the Name 'fileupload-form'
Look at the Definition in the zcml-File you can find the Classdefinition of View/Form
Search the Interface of Form, it could be defined like:
class IMyForm(form.Schema):
""" Define form fields """
name = schema.TextLine(
title=u"Your name",
)
add a new Field of Type NamedBlobFile or NamedFile, look in the Documentation Example

Converting Archetype Content to Folderish

I have an archetype content type that previously was not folderish. Now I have set it as folderish. What attribute or properties need to be changed so that any data created before can be migrated?
I have read the following documents:
Generic Setup Upgrade Steps
Converting one Content Type into another
I followed the above tutorial on upgrade steps but I do not know which attribute or properties to change.
You could use Products.contentmigration. See it's doc to find out how to use it, it shouldn't be too difficult: just define your CustomQueryWalker and the mapping between your two content types. In order to find out what field you have to map, just put a pdb somewhere in the content's view and inspect the content schema.
similar question here: Migrating from (now obsolete) custom ATImage content type
i stumbled accross the same issue when trying to migrate non-folderish types to folderish ones based on: http://pypi.python.org/pypi/collective.folderishtypes
that helped: on a context to convert, call ##migrate-btrees view [1] to initialize the btree structure [2]. I assume your new Archetype content is plone.app.folder based.
[1] defined in: plone.app.folder.migration.BTreeMigrationView.
[2] Main work is done by: Products.BtreeFolder2.BTreeFolder2Base._initBtrees.

Why does my content object not show up in the portal_catalog?

I am trying to implement a basic Zope2 content type directly without using dexterity or Archetypes because I need this to be extremely lean.
from OFS.SimpleItem import SimpleItem
from Products.ZCatalog.CatalogPathAwareness import CatalogAware
from persistent.list import PersistentList
class Doculite(SimpleItem, CatalogAware):
""" implement our class """
meta_type = 'Doculite'
def __init__(self, id, title="No title", desc=''):
self.id = id
self.title = title
self.desc = desc
self.tags = PersistentList()
self.default_catalog = 'portal_catalog'
def add_tags(self, tags):
self.tags.extend(tags)
def Subject(self):
return self.tags
def indexObject(self):
self.reindex_object()
From an external method I am doing this:
def doit(self):
pc = self.portal_catalog
res1 = pc.searchResults()
o1 = self['doc1']
o1.add_tags(['test1', 'test2'])
o1.reindex_object()
res2 = pc.searchResults()
return 'Done'
I clear the catalog and run my external method. My object does not get into the catalog. But from the indexes tab, when I browse the Subject index, I can see my content item listed with the values. Both res1 and res2 and empty.
Why is my content item not showing up inside the searchResuts() of the catalog?
Plone is a full-fat content management system, if you're after something lean it's probably not the right choice (perhaps try Pyramid.)
For your content type to be a full part of a Plone site it has to fulfil a number of requirements across the Zope2, CMF and Plone layers. plone.app.content.item.Item is about the simplest base class you can get for a content item for a Plone site, though a simpler base class in itself will not really make instances of your content type any more 'lean' - an instance of a class in Python is basically just a dict and a pointer to it's class.
Most of the work on a page view will be rendering the various user interface features of a site. Rendering the schema based add/edit forms of frameworks like Archetypes and Dexterity is also relatively expensive.
I'd spend a little time profiling your application using one of the supported content type systems before putting time into building your own.
In order to see your objects in the "Catalog" tab of the portal_catalog your objects need to have a "getPhysicalPath()" method that returns a tuple representing their path (ex. ('','Plone','myobject')).
Also try to use this:
from Products.CMFCore.CMFCatalogAware import CMFCatalogAware
as base class.
You need to register your type with the catalog multiplexer. Look at the configuration in the zmi -> archetypes_tool.
I'm not sure, but you may also need a portal_type registration also...
Like Lawrence said though, you're better off just using one of the current content type frameworks if you want to be able to catalog your data with plone's portal catalog. If you can deal with a separate catalog, take a look at repoze.catalog.
Plone needs every content object to provide an "allowedRolesAndUsers" index to return the object in searchResults.
There is probably a zcml snippet that will enable this for my content type. But I was able to get things working by adding another method as follows:
def allowedRolesAndUsers(self):
return ['Manager', 'Authenticated', 'Anonymous']
CatalogAware will be removed in Zope 4 and then can't be used any more.
cf https://github.com/zopefoundation/Products.ZCatalog/issues/26

How do I prevent a content type from appearing in collections?

How do I prevent a specific content type from appearing in collections (smart folders) site wide in Plone 3? I've looked for relevant options in portal_types and the types and search control panel (turning off the content type for searching doesn't seem to have an effect on collections).
Specific situation: I recently installed plone.app.discussion on a Plone 3.3.5 installation and now comments appear in all the collections. We want to remove them from the collections.
Thanks.
Portal Types criterion is based on plone.app.vocabularies.ReallyUserFriendlyTypes, a vocabulary factory defined in http://svn.plone.org/svn/plone/plone.app.vocabularies/trunk/plone/app/vocabularies/types.py.
If you patch BAD_TYPES by adding discussion comments you'll exclude them from Collections, but you'll also hide them from anywhere this vocabulary factory is used. As far as I know they are also used in contentrules and search control panel.
You can patch BAD_TYPES by adding these lines into __init__.py file of a custom package:
def initialize(context):
"""Initializer called when used as a Zope 2 product."""
from plone.app.vocabularies import types
types.BAD_TYPES = types.BAD_TYPES + ('Discussion Item',)
If you don't have too many collections, the simplest solution might be to add criteria to exclude comments. You can easily get a list of all your collections:
http://your-site/search?portal_type%3Alist=Topic
If you have a lot of collections, you might need to write some custom code to do this. It doesn't have to be a product or anything serious, just some code you can run to add an 'exclude comments' criteria to existing collections. I would start by looking around line 507 of http://svn.plone.org/svn/collective/Products.ATContentTypes/branches/1.3/Products/ATContentTypes/tests/test_criteria.py
You can add criteria to your collections stating which content types you want to display. You can not (without patching/hacking) choose which to exclude.
I.e collections have can have type whitelilsts not blacklists.

Resources