Limit one content item for each member in a folder on Plone 4

I created my own Archetypes content type called "Résumé" and would like to apply a restriction that allows a member to add only one element of this type inside the folder. It would be even better to redirect the participant to the page for editing his or her article if it already exists in this folder.

How can I apply this restriction and provide this additional functionality?

+7
source share
3 answers

A solution to this utility for Plone 3 can be found in eestec.base. We did this by overriding createObject.cpy and adding a special check for this.

The code is in the collective SVN, http://dev.plone.org/collective/browser/eestec.base/trunk/eestec/base/skins/eestec_base_templates/createObject.cpy , lines 20-32.

+5
source

Well, this is a kind of validation restriction, so maybe add a validator to the header field that doesn't really care about the name, but validates the user, etc.? (I think the field validator has passed enough information to remove this, if not, overriding the post_validate method or listening for the corresponding event should work.)

If you try this, keep in mind that post_validate is already called during user editing (i.e. when focus is moved from the field).

+2
source

I don't know if this is better, but you can connect to def at_post_create_script from the base object when creating and manage_beforeDelete when deleting.

eg:

 from Products.ATContentTypes.lib import constraintypes class YourContentype(folder.ATFolder) [...] def at_post_create(self): origin = aq_parent(aq_inner(self)) origin.setConstrainTypesMode(constraintypes.ENABLED) # enable constrain types org_types = origin.getLocallyAllowedTypes() # returns an immutable tuple new_types = [x for x in org_types if x! = self.portal_type] # filter tuple into a list origin.setLocallyAllowedTypes(new_types) def manage_beforeDelete(self, item, container) BaseObject.manage_beforeDelete(self, item, container) # from baseObject self._v_cp_refs = None # from baseObject origin = aq_parent(aq_inner(self)) origin.setConstrainTypesMode(constraintypes.ENABLED) # enable constrain types org_types = origin.getLocallyAllowedTypes() # returns an immutable tuple new_types = [x for x in org_types].append(self.portal_type) origin.setLocallyAllowedTypes(new_types) 

Note. There is also a method called setImmediatelyAddableTypes() , which you can learn. Note II: This does not tolerate content migration.

+1
source

All Articles