Skip to main content

Plone add-on setup with registering and deregistering the add-on

For my project, I have been working on an add-on package and for this first we have to setup that add-on package to start working on it. So we created an add-on package named experimental.safe_html_transform.

We have to set the testing enviornment, Generic setup of profiles, setup for default and uninstall profiles, setting up browser layer, setting up filter control panel for the browser layer, generic setup for the filter control panel. So these are the few of the essential things that have to be configured for setting up add-on and are part of the project. We will discuss each and everything in the blog,how we setup these things and what are the things I have referred for setting up these things. So lets start...

For setting up testing environment we have to add plone.app.testing in the setting files so that we have create automated tests also robot tests for the add-on. Here is the code to be added in the setup.py

extras_require={
        'test': [
            'plone.app.testing',
            'plone.app.contenttypes',
            'plone.app.robotframework[debug]',
        ],
    },

This will help in adding all the three packages that are required for setting up testing environment.

After that we have to setup base module for unit testing, we will set up the base module in testing.py

After that we will have our test module and we will write robot test as well as unit test in that module only. Robot test will test the plone site on robot server and check if its working or not. On the other hand we can check the functionalities of our add-on using unit tests. We will also write some integration tests for the setup like test if product is installed correctly, browser layer is setup correctly etc.

After that we will be left with writing unit tests to test the transform script and checks its accuracy using as much as possible test cases. This is the basic overview of setting up the testing environment for the add-on. The documentation for the testing is too good. It really helps me a lot in understanding about the flow of setting up testing module and how it works.

For testing we just have to write "./bin/test --all" (for all tests including robot and unit tests) and "./bin/code-analysis" for checking the code using flake8 code analysis. 

After setting up testing environment we will do the generic setup of profiles for our add-on.

What is Generic Setup ?

GenericSetup is an XML-based way to import and export Plone site configurations. It is mainly used to prepare the Plone site for add-on products, by: registering CSS files, registering Javascript files, etc.

So we will also configure generic setup for the profiles of our add-on.

We will write the generic setup in configuration.zcml file (zope configuration) for "default" and "unregister" profile. Here is the snippet for the xml code for generic setup.


<genericsetup:registerProfile
        name="default"
        title="experimental.safe_html_transform"
        directory="profiles/default"
        description="Installs the experimental.safe_html_transform add-on."
        provides="Products.GenericSetup.interfaces.EXTENSION"
        />

    <genericsetup:registerProfile
      name="uninstall"
      title="experimental.safe_html_transform uninstall"
      directory="profiles/uninstall"
      description="Uninstalls the experimental.safe_html_transform package"
      provides="Products.GenericSetup.interfaces.EXTENSION"
      />


After that we have registered the profiles by the generic way, now we have to create two profiles, one is default and other is uninstall. 

Default profile contains thing that have to be done when the add-on is installed and unisntall profile contains the things that have to be done post uninstallation of our add-on.

First lets create a default profile, in that profile we will have to set up the browser layer, control panel for browser, metadata and registry and also note that all these files will be .xml, so here also we will xml to setup these things for a particular profile. You can have a look at the profile setup of my add-on

Similarly we will create an uninstall profile, for creating uninstall profiles in plone there is a great blog written by keul. That is a good way to understand how to uninstall profile and that helped me a lot. With the help of that blog I have created a unistall profile for the add-on.

After that we have created testing environment, generic setup for add-on, setting up profiles ( default and uninstall) . Still we are left with setup for browser layer and setting up filter control panel for the browser layer. So lets do it... 

After that we will setup Browser layer by generic set up for the filter control panel. We will create a browser layer interface so that our add-on can run cross browser and this can be done in the interface.py where all the interface lives. Here is the snippet for the same 

class IExperimentalSafeHtmlTransformLayer(IDefaultBrowserLayer):
    """Marker interface that defines a browser layer."""


This will create a browser layer for an add-on and we can run our add-on over the browsers. This is really a nice thing ;). 

As now browser layer is setup now we will set up the filter control panel for the add-on through generic setup in the configuration.zcml file inside the browser module. Here is the snippet of the code 

<!-- Filter Control Panel -->
    <browser:page
      name="filter-controlpanel"
      for=".controlpanel.IPloneSiteRoot"
      layer="..interfaces.IExperimentalSafeHtmlTransformLayer"
      class=".controlpanel.FilterControlPanel"
      permission="plone.app.controlpanel.Filtering"
      />


This will setup the filter control panel for the browser layer now we will configure the control panel that has been set up for the browser layer just above. This will be done in the controlpanel.py file under the browser module. You can check the code on github.The control panel will be set up through the API only and this way we have set up the control panel for the browser layer and we have also configure the control panel. This way we have set up the basic requirements of the add-on. This is just the start and we have set up the add-on. Now the main focus will be on writing the transform for filtering html using lxml. That thing will be included  in the next blog.

Hope it helps you and you enjoyed reading it. It is just a start and lot more yet to come, lot more yet to learn and lot more yet to develop.

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

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.

The Transform Finally!!

Hello everyone, today I will tell you how I implemented the safe_html transform using lxml library of python. I tried to port the safe_html form CMFDefault dependencies to lxml libraries and tried to install my new transform in place of the old safe_html transform. So when ever our add-on is installed then it will uninstall the safe_html and install our new transoform. So there are a lot of things going on in the mind about lxml, why we use that and all.. So lets explore all these things. What is lxml ? The lxml XML toolkit is a Pythonic binding for the C libraries libxml2 and libxslt. It is unique in that it combines the speed and XML feature completeness of these libraries with the simplicity of a native Python API, mostly compatible but superior to the well-known ElementTree API. Why we need to port the transform to lxml ? Earlier the safe_html transform had the dependencies of CMFDefault and we all are working to make plone free from CMFDefault dependencies as due to CMF