Macadames' blog

Le silence est d'or, jusqu'à ce qu'il devienne plomb.

Archive for the ‘python’ Category

Je veux mon réseau social

with 2 comments

Rien de plus simple, avec  Twistranet.

Il vous faut :

Un serveur (Linux, Mac, ou Windows) avec python 2.6+ installé (ou python 2.5 accompagné de simplejson). Python 3 n’est pas supporté par contre.

Installez pip (il faut apprendre à s’en servir, ça simplifie toutes les installations/mises à jour/ désinstallations des paquets python). (*)

Installez PIL. (

En ligne de commande vous tapez :

$ pip install numericube-twistranet

Si tout s’est bien déroulé, vous êtes prêt à démarrer.

Admettons que vous voulez stocker votre projet dans le dossier « c:\mesprojets\monreseausocial » ou dans « /home/chezmoi/monreseausocial », appelons le  « path_to/monreseausocial »

Ouvrez une ligne de commande et tapez :

$ twistranet_project « path_to/monreseausocial »

Si c’est pour du test, je vous conseille plutôt de taper :

$ twistranet_project cogip « path_to/monreseausocial »

Ainsi vous verrez twistranet en action dans une société fictive appelée cogip.

Cela a pour effet de créer votre projet et de démarrer votre serveur en ligne de commande sur le port 8000. En bas du fichier de log vous trouverez le mot de passe du compte admin indispensable pour vous connecter.

Et finalement, ouvrez votre navigateur et tapez :


Vous pouvez commencer à jouer avec Twistranet, votre réseau social.

Pour couper votre serveur :

Sur la ligne de commande :


Pour changer le mot de passe du compte admin :

$ cd « path_to/monreseausocial »

$ python changepassword admin

Pour redémarrer le serveur :

$ python runserver

Pour (beaucoup) plus d’information,

Pour les développeurs, lisez aussi la doc (dossiers /docs) dans le paquet :

Si le sujet des réseaux sociaux vous intéresse je vous suggère d’aller faire un tour sur

(*) Installer pip sous Linux :

$ wget
$ tar xzf pip-0.6.3.tar.gz
$ cd pip-0.6.3
$ python install

Installer pip sous Windows :
- Téléchargez
- Ouvrir et décompresser le fichier pip-0.6.3.tar.gz
$ cd pip-0.6.3
$ python install

Written by macadames

7, mars 2011 at 1:53

Three Plone addons – part 3 : CKEditor for Plone

with one comment

Three Plone addons – part 3 : CKEditor for Plone

Why Plone4 is so cool ? because you can create easily new addons in a pure python way, look at this new addon  called « CKEditor for Plone ».

A screencast here :

More information here :

Some lines of code are used to take original ckeditor svn code and place it in a Zope browser resource (because Zope is really strict about XML/XHTML we must do this little work, i hope i could replace it by a simple svn-externals in future).

Other lines of code are here to call dependencies (collective.plonefinder to search server resources, collective.quickupload for fast upload, see previous posts).

A small javascript « select resources » code is here to communicate with Collective Plone Finder.

The most part of code is CKEditor Plone control panel because it’s important for managers to allow or disallow features, toolbars, or some plugins on their Plone site.

The last part of code is the CKEditor integration in plone wysiwyg templates.

Hmm, that’s all.

Some people ask me, why CKEditor ? Plone4 has Tiny MCE …

Because :

– CKEditor is fast (really fast)

– CKEditor is accessible (

– because i’m a FCKeditor’s friend since 10 years, Fred (Frederico Caldeira Knabben) had no chance, his initials offend some English spoken people, now than the software name is more accessible perhaps more people will be interested in its features ?

– Plone needs to be good but it also needs to have reliable addons, and CKEditor cames with a good Plone integration (relax with collective.plonefinder and collective.quickupload)

Written by macadames

24, septembre 2010 at 11:05

Three Plone addons – part 2 : Collective Plone Finder

leave a comment »

Three Plone addons – part 2 : Collective Plone Finder

Collective Plone Finder is a tool for Plone developpers that can be used to find and select elements in a Plone site. The pypi name is « collective.plonefinder » with one dependency called « collective.quickupload »

It’s a widget’s helper, and you will find in the code a simple form lib widget, it’s an example of how you can use this product. In the README.TXT, you will find a way to use the formlib widget in a Plone portlet.

In this screencast, CPF is used in a portlet named « CG30 Direct Access Portlet » (CG30 is a client) :

The goal of Collective Plone Finder is not to be used as a standalone product. But, in this second screen cast and for demonstration purpose, we use it in a full browser screen just to show you the different potential uses. Look at the address bar where you can pass some params in querystring.

More information about this package can be found here :

This product is not complete (need more documentation, unit tests, some refactorisation, and some ajax popup functions are not finished at this time, 1.0.0), but i released it because it was an important part of my third autumn Plone production « CKEditor for Plone », see the next post.

I know that many documentation is missing, free time is too short, so if you need to integrate quickly CPF features in your own widget, at this time the better way is to read the code (really easy to understand, it’s Python + Plone,  a devel dream). In future i hope  many good evolutions will came with Plone4 new energy.

Written by macadames

24, septembre 2010 at 11:05

Three Plone addons – part 1 : Plone Quick Upload

with 9 comments

Three Plone addons – part 1 : Plone Quick Upload

As good things usually happen in threes, i present you three new Plone addons i released in September 2010, i hope you will find them useful.

The first product is Plone Quick Upload (pypi package name is « collective.quickupload »), a pure javascript multiple upload tool for Plone, look at the first screencast, you could think « oh i know it’s a new Flash Upload tool » and you would be wrong, FlashUpload has no drag and drop 😉

Plone Quick Upload has a control panel with useful options (limit size, limit parallel uploads, direct upload on select, fill titles before upload, …)  :

As you can see, Plone Quick Upload manage errors and returns i18n messages when an upload raise an error (file always exist, file is too big, no permission to add content, bad content type, etc …).

For unfortunate MSIE users, the pure javascipt way cannot allow multiple selection and drag and drop, so the upload form has a graceful fallback, look at the next screencast, it’s not so bad.
And you can also choose in Plone Quick Upload control panel, to replace the pure javascript client script by a Flash Upload based script, it’s not recommended and it cannot work behind an HTTP authenticated server, but  some people want it :

More information about Plone Quick Upload (installation, use it in your own template, etc …) here  :

Written by macadames

24, septembre 2010 at 11:04

Plone and multilingual sites

with 9 comments

Usually we build multilingual Plone sites with LinguaPlone.

This solution has a big advantage, it’s generic and very easy to implement in a plone site.

But there are many inconvenients, due to the design of this product (translations are independent by design) :

  • Each translation is a new Archetype object, and it could be a big problem on sites with many contents, the portal objects number is increased by the number of available languages.
  • Translations uses plone references catalog to be linked to the original (called canonical) object, but when moving objects translations are not moved, when copying pasting objects, translations are not pasted, when deleting objects translations are not deleted, when reordering contents, translations are not reordered, when publishing objects translations are not published, … For web masters maintaining a site  with LinguaPlone inside could be a challenge.
  • When translating folders with LP, all translated contents are moved from the canonical folder to the translated folder with same language, translating low level folders on big depth tree sites could take a long long time, don’t be surprise if you get errors.
  • If a content is neutral (with no language attribute), inside a translated folder, it could not be seen when browsing a translation of the parent folder.
  • At last a lower problem :  the translation edit forms are not pretty to use, they show a table with two columns, the first column with the « canonical » content inside in « view » mode, the second column with the translation edit form, in fixed width sites the translated form width is sometimes ridiculously small.

But since many years we use LinguaPlone because it was the only easy way to make multilingual Plone sites.

By the past we were using a LP patch called LinguaFace to reduce the number of problems with LP (synchronisation on reorder, copy-paste, delete, or move – see neutral contents inside all translated folders – more usable translation edit forms …), but LF add a new layer of complexity and maintaining it with all LP versions becomes complicated. See some examples on how it works :

  • when a content is copied, all translations are copied
  • when a content is pasted or moved all translations are pasted or moved at the good place (not so easy)
  • when a content is published or retracted translations follow the same workflow transition
  • when a folder is translated, we don’t see only objects inside but also objects with same canonical Path (a new catalog index) to see also neutral contents.
  • Navtree is patched, breadcrumbs are patched, to use canonical path
  • and so on …

A big nightmare.

To day a new solution exists that store translations inside each Archetypes field, raptus.multilingualfields, and a Plone integration of raptus.multilanguagefields called raptus.multilingualplone that extends the schema of all Plone Content Types making them translatable. raptus.multilingualfields also provides multilingual catalog indexes that return the good translated data when searching for contents or displaying trees, and multilingual criterions for topics.

A LP feature not provided by raptus.multilingualfields is the internationalization of urls, if you really need this feature, i think it’s not a big challenge to add some traversal rules, for me it’s not essential.

AnotherLP  feature that can’t be provided when storing translations in fields is to get different workflows or security settings for each translation. If you need this feature use LinguaPlone, LinguaPlone is done for that, it makes all translated contents independent, but i’m curious to know the number of users who really want this feature, all clients i had never ask for that but finally, after some LP experience, always wanted the exact opposite use-case.

To make your Plone site translatable with raptus.multilanguagefields, you have two choices :

  1. Add raptus.multilanguageplone in your buildout and install it in your Plone Site using extensions products control panel, to make all your Plone content types and derived translatable (all fields for which translation make a sense are translatable).
  2. I prefer integrate by myself raptus.multilanguagefields inside a product, since we could want just some fields or content types translatable, as example i don’t need to translate the images or the files contents, just their titles and descriptions.

How to implement the second solution ?

Just take a look at raptus.multilanguageplone code, it’s easy :

  1. Make your archetype extenders to make your wanted fields translatable, example can be found here
  2. register your extenders in setuphandlers (Generic Setup import step), example here
  3. replace the standard catalog  indexes with multilingual indexes in Generic Setup profile, example here

That’s all, you will get superb edit forms with translatable fields inside, you also will get a google help to translate contents (a pleasant gadget). I say « Bravo » to raptus developpers.

Important :

  • these products are young, and there’s still many work todo to make it work without problems (tests are needed …). Last 0.6 releases have bugs under plone3.3, use the svn versions below instead.
  • raptus.multilanguageplone 0.6  has a bug in extenders with primary fields, tested in Plone 3.3  (fixed in branch aws_evols, not tested with images at this time)
  • raptus.multilanguagefields 0.6 has a bug, doctests are broken in Plone3.3 (fixed in trunk )
  • At this time these products don’t have unit tests or functional tests, it’s the only reproach i can make.  I started the work  here, and here

Written by macadames

6, février 2010 at 2:28

The power of Deliverance and PyQuery

with 8 comments

Some times ago i made a new skin for the French-speaking PYthon Association (AFPY) web site, using Deliverance and PyQuery. I made this exercice on my free time with many pleasure.

You can see the Deliverance power here :

The home page without Deliverance, the same using Deliverance proxy : all dynamic contents are taken from original Plone site, try to find it, you will notice the Deliverance + PyQuery magic in action 🙂

The association pages without Deliverance (a sphinx site), the same contents injected in the site with Deliverance

Thanks to Gaël Pasgrimaud, a friend of mine and coworker, for his big work which really help me :

Here, we use a specific Gael’s buildout and a specific package done for our Deliverance projects used at Ingeniweb, our company. With these tools (if some people are interested in, it could be released on pypi, tell us …), we get the best flexibility for Deliverance :

  • PyQuery integration
  • The good base rules for Deliverance to avoid theming bugs with Ajax and HTML editor (*)
  • Dynamic css : css are mako templates served by a skin server, colors fonts and other properties are set in a « .ini » file
  • A base mako css for Plone which permits to start the work of externalize the entire css :
    in our projects, all portal_css content links from Plone are stripped when the Plone site is called through Deliverance (just add a condition for Plone stylesheets in portal_css : python:request.HTTP_HOST in request.SERVER_URL), the final css is lighter, the Deliverance css is really clean without many ‘!important’ bad overloads)
  • Supervisor deamon to control skin servers
  • We can use eggs for our Deliverance skins.

(*) to get real wysiwyg rendering in Plone behind Deliverance ‘s  HTML editor areas, use also FCKeditor.Plone 2.6.4, in FCKeditor control panel you will find the way to inject Deliverance css in wysiwyg area, it’s an important feature for end users.

Now i can take my summer holidays in peace with myself 🙂

Written by macadames

1, août 2009 at 1:13

Some Deliverance tips

with 4 comments

I really like to use Deliverance for skinning Plone or any web application. In this post, i just want to help Deliverance beginners to configure their server, and to talk about PyQuery, which could be a good Deliverance companion.

Apache 2.2 + Deliverance : configuration

I spent some time to configure Apache in front of Deliverance, you will find here a possible configuration.

Deliverance Server configuration :

In your rules.xml, the first declaration relates to server config, use ‘’  as server address to be able to serve any ip address :

 <dev-user username="dev" password="dev" />

Always in rules.xml you need to write the proxy rule for Zope Virtual Host or another server.

If you want to serve a plone site located at http://localhost:8080/myplonesite :

<proxy path="/" rewrite-links="1">
     <dest href="http://localhost:8080/VirtualHostBase/http/{SERVER_NAME}:8000/myplonesite/VirtualHostRoot" />

If you need a more complex configuration in front of Zope, you can always use Apache + Varnish or SQUID + Pound, or IIS + EEP, and ZEO in front of Zope using another port (90 in this example) and use this Deliverance proxy rule :

<proxy path="/ rewrite-links="1">
    <dest href="http://{SERVER_NAME}:90" />

And if you want to serve anything else for another path :

<proxy path="/anotherpath" rewrite-links="1">
    <dest href="http://anythingelse" />

Apache VirtualHost configuration

You can use Deliverance on port 80 (just replace 8000 by 80 in rules.xml) to directly serve your site, but you would prefer Apache for that in many cases.

Suppose you want to rewrite all requests to « » with a Deliverance response (on, you can use the mod_rewrite like this :

<VirtualHost *:80>
    ErrorLog "logs/"
    CustomLog "logs/" combined

    # do not forget this declaration
    ProxyPreserveHost On
    RewriteEngine On
    RewriteLog "logs/"
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule ^/(.*) http://%{SERVER_NAME}:8000/$1 [P]

    # etc ...


That’s all.

If you want to serve urls starting with a particular path (/mypath),  just change your rewrite rule like this :

    RewriteRule ^/mypath(.*) http://%{SERVER_NAME}:8000/_vh_mypath$1 [P]

Just take care in this last case to put the good urls in your Deliverance static contents, if you need it .

In fact you can do anything you want with rewrite rules 🙂

Deliverance and PyQuery

PyQuery is a jQuery-like library for Python which help you to play easily with html elements. Combined with Deliverance you will be able, with a python rule, to modify content or theme on the fly, at any point of your Deliverance transformation.

To learn how to add PyQuery rules to Deliverance, read this post  (many thanks to Gaël who help me to learn Deliverance) :

Read also  :

And now just try these example :

You have a floating right toolbar with floating right tabs inside in your html template theme :

<ul id="right-bar">
    <li><a href="/abcd">ABCD</a></li>
    <li><a href="/efgh">EFGH</a></li>

You have a floating left toolbar with floating left tabs inside in your html source content :

<ul id="left-bar">
    <li><a href="/abcd">ABCD</a></li>
    <li><a href="/efgh">EFGH</a></li>

With Deliverance xml rules you want to replace right tabs by left tabs like this :

    <replace content="children:#left-bar" theme="children:#righ-bar" />

But of course you need to reverse tabs order before or after xml transformation.
To modify the theme  just add a pyquery rule after the replace declaration :

    <pyquery pyref="myskinproduct.rules:pqrules" />

In your,  create your pqrules function like this :

def pqrules(content, theme, resource_fetcher, log) :

    # if you prefer to work on content
    # before Deliverance transform
    # replace theme('#right-bar') by content('#left-bar')
    nav = theme('#right-bar')
    navitems = nav('li')
    # i'm not sure that it's needed :

Other examples :

    # replace a search button text with 'OK' in content
    content('#portal-searchbox .searchButton').val('OK')

    # remove icons from a navigation portlet
    # replace icons by "> "
    nav = content('#navigation')
    navitems = nav('li')

    # add a "last-item" class to last tab in a toolbar
    from pyquery import PyQuery as pq
    navitems = content('#navbar li')
    if navitems :

    # if you have inserted external contents in content area with Deliverance xml rules
    # you want to change a navitem class in result
    if theme("#photos') :

    #etc ...

To do this kind of template manipulations, changing content on source application could be a best practice, it depends of  your particular situation.
But i’m sure that it’s a fast way  😉

The problem is how to test the result ? twill could be a solution …

Do not transform some contents with deliverance

If you dont like bad surprises, you need to abort ajax html content transformation. And in some other cases you need also to abort Deliverance transformation (see example)

In your rules.xml, just add :

    <match pyref="myproduct.rules:match_notheme" abort="1" />

and in your

def match_notheme(req, resp, headers, *args):

    match = False
    if req.headers.get('X-Requested-With', '').startswith('XML'):
        match = True
    # the html template of FCKEditor iframe must be unchanged
    if req.path_info.startswith('/editor'):    
        match = True
    if 'notheme' in req.GET:
        match = True
    return match

Written by macadames

23, mai 2009 at 3:06