Skip to main content

Getting Control panel for the add-on

Last time I was able to finish things up with registering and deregistering the add-on in the plone site, so that when ever I activate my add-on from the ZMI on plone instance, it registered the default profile of my add-on, also it register the browserlayer of the add-on. So this things goes well and also there were some issues related to the versions which have been solved lately.

What's Next ?

After the registration of add-on we need to create a view on plone site so that when ever we click on the add-on we can get some page and configure our add-on from plone site. There are default configuration for the transform script already there and we can customize the configuration. So for that we have to create a control panel for our add-on so that user can get a platform to customize the configuration.

There were 2 ways to create a control panel :-

1) Either to overwrite the old cntrol panel of PortalTransform safe_html.
2) Or to create a separate control panel for our new safe_html add-on.

I choose the 2nd way to create a control panel and created a separate control panel for the add-on.

How to create a control panel in plone add-on ?

For creating control panel in plone add-on we have to
1) Create a schema for control pane.
2) register the control panel schema.
3) Create permissions for registering control panel.

Lets start with 1st step,

Create a Schema for control panel

We will create the schema for the control panel in a file, where we will define FilterTagSchema which will contain space for nasty tags, stripped tags and custom tags. Similarly we will create IFilterAttributeSchema, IFilterEditorSchema and Finally in IFilterSchema we will include all the above mentioned classes.  After that we will create FilterControlPanelForm which will allow the above defined schema on the plone site.

Here is the snippet for FIlterControlForm :-

class FilterControlPanelForm(controlpanel.RegistryEditForm):

    id = "FilterControlPanel"
    label = _("SAFE HTML Filter settings")
    description = _("Plone filters HTML tags that are considered security "
                    "risks. Be aware of the implications before making "
                    "changes below. By default only tags defined in XHTML "
                    "are permitted. In particular, to allow 'embed' as a tag "
                    "you must both remove it from 'Nasty tags' and add it to "
                    "'Custom tags'. Although the form will update "
                    "immediately to show any changes you make, your changes "
                    "are not saved until you press the 'Save' button.")
    form_name = _("HTML Filter settings")
    schema = IFilterSchema
    schema_prefix = "plone"

    def updateFields(self):
        super(FilterControlPanelForm, self).updateFields()

Observer here we used schema for the filter control form as IFilterSchema which further includes all the classes as mentioned above.

Now finally we will wrap the control panel form and this will help us to get our control panel on plone site.

Register the Control panel 

This was just the first step, but now after defining the control panel we have to register the control panel in the configuration.zcml in the generic way.

Here is the snippet of code done to register the control panel :-

<include file="permissions.zcml" />
<!-- Filter Control Panel -->
<browser:page
   name="safe_html_transform-settings"
   for="Products.CMFPlone.interfaces.IPloneSiteRoot"
   layer="..interfaces.IExperimentalSafeHtmlTransformLayer"
   class=".controlpanel.FilterControlPanel"
   permission="experimental.safe_html.controlpanel.Filtering"
/>


Here we have registered the browser page with the name safe_html_transfrom-settings, for IPloneSiteRoot of CMFPlone and using our own add-on browser layer and importing our controlpanel class.

Adding permissions for control panel

We will notice that we have added the permissions at the end of the setup and for that we will create a separate file named permissions.zcml and import that file in the configuartion.zcml.

The permission.zcml file looks like this :-
<configure
    xmlns="http://namespaces.zope.org/zope">
    <permission id="experimental.safe_html.controlpanel.Filtering"
            title="Plone Site Setup: Filtering">
        <role name="Manager"/>
        <role name="Site Administrator"/>
    </permission>
</configure>




After adding these permissions to generic setup and configuring the control panel we will be able to see the controlpanel on the plone site. Here is the snippet






Finally after that the control panel thing is working perfectly.        

What is Next ?

After that the main thing left before mid-term evaluation is to register the safe_html trasnsform in the add-on and BTW the safe_html transform is almost ready. I will explain that in next blog.

Hope you like it!!

Cheers!!
Happy Coding.                                                                                                                                                                  

                                                                                                                                                        

Comments

Popular posts from this blog

Summarizing Summer

It was a great pleasure to work with great coders/developers at Plone Foundation and learning a lot from them during the course of the program. This blog is about summarizing the whole work I have done during this summer under Google summer of code 2016 under Plone Foundation. So my project mainly focuses on improving forms in plone for dexterity. We already have forms in plone for archetype. So there is a project named collective.easyform which basically provide forms for Plone as dexterity contenttype. The main focus of the project was to improve that code base. Make this stable for plone 5.0 and above. Make all the test cases passing for the code base. Try to cover tests as much as possible code base. Also implement functionalities for fields/actions of the forms in correct place. Make the plone more user friendly. Finally for users who want to migrate their already present forms in Plone Form Gen (PFG) which is archetype to easyforms which are dexterity based forms Plone. This w...

Testing the transform

Hello everyone, now the transform for filtering html is ready and the main task is to test the transform. For that purpose I have set up the whole test environment for my add-on using testing.py for unit tests and robot tests. After setting up the environment, now its time to first write unit test for transform that we have just created to check if they are all passing and the transform is working properly or not. For creating unit test I first created test class and in that class I just call the convert function that we have created in the transform and give the input as a data stream and pass it to convert function and then get the output as required. After writing few simple test cases like 30-35 then just ran these test cases and they ran successfully. Test cases ran successfully locally :- Travis is also happy ;) Yayayay!!! Finally test cases were passing so its like a milestone for the project and its completed. The PR got merged and things working good as expect...

One Last Time

Okay. So finally the list of GSOC'16 selected students is out and I am glad that my project got selected under Plone Foundation. I am really looking forward to work on my project which is basically improving the add-on named easyforms. I have already started working on the same project and will plan with my mentor for future work. I will keep this blog updated with the work I will be doing during the project as I did last summer too. Cheers.