Archive for the ‘Uncategorized’ Category

Back on iw.memberreplace

March 8, 2009

I blogged some months ago about iw.memberrreplace. In some words, iw.memberreplace provides a tool that clones the security features of an unser to another one (ownership, DC creator, sharings, group membership). No more hassle digging around huge Plone site and hundreds of clicks to do this.

Last week, I read a conversation with John Stahl and Mustapha Benali about the PLIP 185, and realized that this PLIP is almost iw.memberreplace (or the opposite).

So I spend a couple of hours on that component to add the last details on that component. Et voilĂ , the last release of iw.memberreplace (1.0.0-RC1) fulfills now that PLIP: the original member can now be removed – if defined in a mutable users source.

I swear that in the future, I will read the open PLIPs before creating a new component ;o)

Enjoy…

iw.memberreplace control panel

iw.memberreplace control panel

Have your views rendered with DTML

August 16, 2008

Have your views rendered with DTML

As we’re supposed to kill the CMF skins layer in the Plone components, when tailoring the old style products to components, we put all static data (images, javascripts, stylesheets) in resources directories, python scripts to views and adpters, controller page templates to plone.app.form or plone.app.z3cform schemes, and so on…

But the new style resource directory doesn’t take care about DTML as it does for page templates. And for some kinds of stuffs like dynamic CSS/Javascript, or making a CSV file, DTML is yet the better suited than ZPT.

Yes you can publish DTML based views/pages/viewlets. This is not obvious but not that much complicated. This small example shows how to add a stylesheet using the standard Plone “base_properties” CSS data.

First the ZCML bunch at …/browser/configure.zcml:

<browser:page
  name="mystytles.css"
  for="Products.CMFPlone.interfaces.IPloneSiteRoot"
  class=".stylesheet.MyStylesheet"
  permission="zope2.Public"
/>

So we’ll have that sthylesheet published at http://<your-site>/mystyles.css.

Now the …/browser/stylesheet.py module:

...
import os
from Globals import DTMLFile
from Products.Five.browser import BrowserView
...
this_dir = os.path.dirname(os.path.abspath(__file__))
templates_dir = os.path.join(this_dir, 'templates')
# Don't add ".dtml" to the file name though the file is "mystyles.css.dtml"
mystylesheet_dtml = DTMLFile('mystyles.css', templates_dir)
...
class MyStylesheet(BrowserView):
    def __call__(self, *args, **kw):
        """This view is published"""
        # Wrap acquisition context to template
        template = mystylesheet_dtml.__of__(self.context)
        # Note that you can provide other named args below you might need in
        # your template
        return template(context=context)

And finally our DTML template at …/browser/templates/mystyles.css.dtml

/* <dtml-with "context.base_properties"> (do not remove this :)
<dtml-let portal_url="context.absolute_url()"> (do not remove this :)
*/
.silly {
  color: &dtml-discreetColor;;
}
.foo {
  background: &dtml-portal_url;/some-image.gif;
}
/* </dtml-let></dtml-with> (do not remove this :)  */

You just need to add “mystyles.css” to the Plone CSS registry but that’s another story. That’s all folks.

Note that you could prefer using z3c.zrtresource if you’re bleeding-edge oriented developer.