.. $ more README *.py ui/portal/*.xml > all.txt; a2ps all.txt -o all.ps
.. $ rest2html --stylesheet-path=../main.css README a.html 
.. $ rest2latex README a.latex; pdflatex a.latex; acroread a.pdf

============================================
Creating our Own Namespace for the metadata
============================================

By default iKaaro give us a default metadata who use DublinCore. Here we add a
new namespace, **port:** so we can define our own metadata, here is an example
of what will look like a persistant xml file with the metadata:: 

  <?xml version="1.0" encoding="UTF-8"?>
  <metadata xmlns:port="http://xml.itools.org/namespaces/port"
            xmlns:dc="http://purl.org/dc/elements/1.1">
    <port:title>A Title </port:title>
    <port:expiration_date>2003-12-08 10:30</port:expiration_date>
    <version>20041204</version>
    <format>Portal</format>
    <dc:title>The title in the standard DublinCore namespace</dc:title>
    <port:rank>3</port:rank>
    <port:description>A description in our portal namespace</port:description>
  </metadata>

To do this we have a very few code to add: 

- A Namespace class who inherit from the **itools.itoolsAbstractNamespace**
- import the ``Namespace`` module in the ``__init__.py`` 
- make an ``edit_metadata_form`` and an ``edit_metadata`` method to controle
  the ``ui/portal/Metadata_edit.xml`` template.


Tree
=====
::

  .
  |-- README
  |-- Namespace.py
  |-- Root.py
  |-- Skins.py
  |-- __init__.py
  `-- ui
      `-- portal
          |-- Base_view.xml
          |-- Document_view.xml
          |-- FrontOffice1_template.xhtml
          |-- Metadata_edit.xml
          |-- PortalFolder_list_view.xml
          |-- images
          |   |-- Document16.png
          |   |-- Document48.png
          |   |-- Folder16.png
          |   |-- Folder48.png
          |   `-- px.gif
          `-- main.css


Namespace.py
=============
::

  # Import from Python
  from datetime import datetime

  # Import from itools
  from itools.xml import XML, namespaces
  from itools.xml.namespaces import AbstractNamespace as itoolsAbstractNamespace
  from itools.handlers import IO

  schema = {
      'expiration_date': {'type': IO.DateTime, 'default': datetime.now()},
      'description': {'type': IO.Unicode, 'default': u''},
      'rank': {'type': IO.Integer, 'default': 99},
      'title': {'type': IO.Unicode, 'default': u''},
      }


  class Namespace(itoolsAbstractNamespace):

      class_uri = 'http://xml.itools.org/namespaces/port'
      class_prefix = 'port'

      def get_attribute_schema(name):
          try:
              return schema[name]
          except KeyError:
              raise XML.XMLError, 'unknown property "%s"' % name
      get_attribute_schema = staticmethod(get_attribute_schema)

  print 'register portal namespaces'
  namespaces.set_namespace(Namespace)

edit_metadata_form and edit_metadata method
===========================================
::

  edit_metadata__access__ = True
  def edit_metadata(self, **kw):
      context = get_context()
      root = context.root

      self.set_property('dc:title', kw.get('dc:title'))
      self.set_property('port:title', kw.get('port:title'))
      self.set_property('port:description', kw.get('port:description'))
      self.set_property('port:rank', kw.get('port:rank'))

      expiration_date = kw.get('port:expiration_date')
      self.set_property('port:expiration_date', expiration_date) 

      # Reindex
      root.reindex_handler(self)
      message = 'Metadata changed.'
      comeback('edit_metadata_form', message)


  edit_metadata_form__access__ = True 
  edit_metadata_form__label__ = 'port Metadata'
  def edit_metadata_form(self):
      namespace = {}

      # Title
      namespace['title'] = self.get_property('dc:title')

      # expiration_date 
      exp_date = self.get_property('port:expiration_date')
      namespace['expiration_date'] = exp_date.strftime('%Y-%m-%d %H:%M')

      # Title port
      namespace['port_title'] = self.get_property('port:title')

      # Rank port
      namespace['port_rank'] = self.get_property('port:rank')

      # Description
      namespace['description'] = self.get_property('port:description')

      handler = ui.get_handler('frontoffice1/Metadata_edit.xml')
      return stl(handler, namespace)


Root.py
=========

We have the classe Base to factoring the ``views`` and the ``switch_skin``
methods who are common to the **Root**, **Document** and the **PortalFolder**.

.. figure:: ../images/class_diagram_5.png
   :align: center 
   :scale: 90 
 

__init__.py
============

We need to import the Namespace in the __init__ to register our namespace::

  ...
  import Namespace
  ...


iKaaro and itools API used in portals
======================================

class variables
-----------------
::

    class_id = 'PortalFolder'
    class_title = u'Our Portal Folder'
    class_description = u'Here the description of our Portal Folder'
    class_version = '20041106'
    class_icon48 = 'portal/images/Folder48.png'
    class_icon16 = 'portal/images/Folder16.png'

class method
-------------


