Dynamic creation of Content Rules

Hello, everyone.

I'm trying to dynamically create content rules under the hood of some User actions for collective.ifttt addon.
So far we have the success of creating custom content rules using UI but now we need to automate the process with the required configuration using Python code.

Can someone help me, please? I have looked down into few addons (collective.easyform and collective.easytemplate, which popped up from Google and community forum topic search) but nowhere I find a clear implementation of this.

Why don't you check the content rules implementation itself?`



Your task has two subtasks:

  1. create the content rules via Python
  2. trigger this creation automatically

Regarding the first subtask: everything doable via the UI is done with Python code. You just need to locate (and understand) the corresponding code to do it yourself in Python code. Usually, the UI interface is realised via a so called "view". Views are registered in "zcml" files and there associated with a name. It is this name which is used in the url by the UI. This implied that you can search the "*.zcml" files for the name used in the UI url to locate the corresponding zcml registration and from there find the entry point to the implementation. Usually, this provides the important clues to do it yourself.

Regarding the second subtask. If you are lucky, you can register an event subscriber (called "handler") to trigger the operation. Otherwise, you will need to modify a view (typically, you would define an event and "notify" this event in the modified view - and then use the first approach). I do not know collective.ifttt and cannot tell you whether the event subscriber approach will be directly usable.

1 Like

Thanks for the clues. That works :slight_smile:
For the second task, I used button handlers of the form itself to create and configure new content rules.