Question

Some basic info

I have a Plone 3.2.1 site, which has a sub folder named prod. There is also a PloneFormGen form named upload, which has a custom script adapter that creates a custom content type (slight modification of the 'Collection' type) and places it in the aforementioned prod folder.

The prod folder has a content rule configured, which has the following conditions:

  • Type == "My Custom Type"
  • State == "Private"

If those conditions are met, it will send me an email saying there is a new content type awaiting my review.

The issue

When using a custom script adapter to create content types, it seems the content rules are bypassed or ignored. Of course manually creating a "My Custom Type" via the "Add new..." menu executes the rule as expected.

My thoughts

As far as I can see I only have 3 options

  1. install uwosh.pfg.d2c
    • This would be ideal but seems to break my installation (client1 refuses to load after this is added to buildout, it complains about a permission issue, it also seems to cause the same issue on a vanilla Plone 4.3 install)
  2. Write something in my script that can talk to Plone's mailhost and send a custom email
  3. Find a way to execute a content rule in my script

Number 3 on this list is where I want to go, although I can't find much information on it, leading me to think it might be quite complicated.

Question summary

Is it possible to execute an already existing content rule using a PloneFormGen custom script adapter? If it is possible, does anyone have documentation or an example of it?

Script Adapter script if you need to see it:

from DateTime import DateTime

target = context.prod

form = request.form

uid = str(DateTime().millis())

target.invokeFactory("My Custom Type", id=uid, title=form['title-1'])

obj = target[uid]

obj.setFormat('text/plain')
obj.setTitle(form['title-1'])
obj.setDescription(form['description-1'])
obj.setText(form['main-information'])
obj.setCustcode(form['customer-code'])
obj.setProdcode(form['product-code'])
obj.setMsector(form['market-sector'])  
obj.setProdcat(form['product-category'])
obj.setOrderdate(form['order-date'])
obj.setSalesrep("rep: " + form['sales-rep'])
obj.setKeywords(form['keywords-1'])
obj.setSubject(form['product-code'])

criteria = obj.addCriterion('Type', 'ATPortalTypeCriterion')
criteria.setValue("Image")

criteria = obj.addCriterion('Subject','ATSimpleStringCriterion')
criteria.setValue(form['product-code'])

obj.reindexObject()

I am still working on this so the question may be modified as I progress through this issue. Although any help or insight would be greatly appreciated.

Edit #1

I was on the Plone chat room and someone suggested I look into ObjectAddedEvent. This is probably what I am looking for although I am unable to import those modules via a custom script adapter and would like to avoid having to write a script that resides on the file system.

Was it helpful?

Solution

https://pypi.python.org/pypi/uwosh.pfg.d2c/2.4.1 was just released and should fix the permission issue you described.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top