Posts for the month of July 2010

An intranet portal for French Yves Rocher’s stores

Yves Rocher French cosmetics company located in over 80 countries, decides in Febuary to launch an Intranet for the 550 stores in France.

Two objectives are identified:

  1. To offer access to a set of features which simplifies the relationship between the group and its franchise network (Tool Control support, registration, reservation of resources, ...)
  2. To offer access to a set of reference content such as news, new products, quality, training, ....

In response to a constraint to put the Intranet on line for July 2010, we chose to conduct a project with agile methods based on Nagare.

The project was implemented in its entirety in six iterations of two weeks. It was an opportunity to develop new features for creating HTML content, navigation of trees and management of access rights for ease of use for end users.

Once again we used the YUI library for the development of the portal presentation layer.

Yves Rocher has also been conducting a security audit on the application implementation to control the privacy of published data and the tightness of the different profiles of users. This audit has highlighted the great qualities of Nagare in terms of securing access to an application built on this framework.

This project, initially for France is expected to manage the problems of multi-lingual, and typology for an international deployment.

Some screenshots :

How to create your own validator

With web forms you always have to validate the data sent by the users of your application. Nagare offers you two simple validators: IntegerValidator and StringValidator. You can find them in the nagare.validator module. The point of this article is to show you how to easily make your own validators.

First, you need to know what an editor property is. A property is normally used in nagare to manage value in forms. When a form is submitted, the properties receive all the values. See the documention CallbacksAndForms#the-editor-property-objects.

Those properties also the offers the validate() method to set a validation function. The nagare documentation CallbacksAndForms#the-validator-module shows you a simple usage of a IntegerValidator

Let's start with a simple example of a StringValidator:

from nagare.validator import StringValidator
from nagare import editor
my_value = editor.Property()
my_value.validate(lambda v:  StringValidator(v).shorter_than(20).not_empty())

Once the property is created, we link a validator to it. Here we want the string to be shorter than 20 characters but not empty.

We can see the validate() method of a property takes a validating function in parameter. This function is called with the value to validate, raises the exception ValueError if the value is invalid or returns the value to be set (i.e a validation function can do conversions too). Then, we can try to put a value in our property:

>>> my_value(u'nagare.org')
u'nagare.org'
>>> my_value.input
u'nagare.org'
>>> my_value.value
u'nagare.org'
>>> my_value.error
>>> my_value(u'')
u''
>>> my_value.input
u''
>>> my_value.value
u'nagare.org'
>>> my_value.error
u'Can't be empty'

Now we know how to use a simple validator, let us see how to make a custom validator. To explain this part we choose to make an EmailValidator:

class EmailValidator(StringValidator):
    def __init__(self, value, **kw):
        super(EmailValidator, self).__init__(value, **kw)
        self.match('[0-9A-Za-z_\.-]+@[0-9A-Za-z_.-]+\.[A-Za-z]{2,4}', msg=u'Invalid email')

The first thing to do is to create a class which inherits from an existing validator: here we choose to inherit from StringValidator. Then, we can add the functionnality we want to offer or overload an existing function. For our example, we overload the __init__() method and we use the match() method inherited from the StringValidator class to check the email on a regular expression. The msg parameter is the message passed if a ValueError exception is raised.

>>> my_value.validate(EmailValidator)
>>> my_value(u'contact@nagare.org')
u'contact@nagare.org'
>>> my_value.input
u'contact@nagare.org'
>>> my_value.value
u'contact@nagare.org'
>>> my_value.error
>>> my_value(u'contact@')
u'contact@'
>>> my_value.input
u'contact@'
>>> my_value.value
u'contact@nagare.org'
>>> my_value.error
u'Invalid email'

For this example we use the match() method but you can also use all the already existing methods. For that, see directly the code of IntegerValidator and Stringvalidator in the nagare.validator module core/nagare/validator.py.