Index: /WAeUP_SRP/trunk/WAeUPTables.py
===================================================================
--- /WAeUP_SRP/trunk/WAeUPTables.py	(revision 363)
+++ /WAeUP_SRP/trunk/WAeUPTables.py	(revision 363)
@@ -0,0 +1,77 @@
+# (C) Copyright 2005 AixtraWare <http://aixtraware.de>
+# Author: Joachim Schmitz <js@aixtraware.de>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+#
+# $Id$
+
+from zope.interface import implements
+from Globals import InitializeClass
+from Products.ZCatalog.ZCatalog import ZCatalog
+
+from interfaces import IWAeUPTable
+
+class AttributeHolder(object):
+    pass
+
+def dict2ob(dict):
+    ob = AttributeHolder()
+    for key, value in dict.items():
+        setattr(ob, key, value)
+        
+    return ob
+        
+
+class WAeUPTable(ZCatalog):
+    
+    implements(IWAeUPTable)
+        
+    def addRecord(self, **data):
+        raise NotImplementedError
+    
+    def deleteRecord(self, uid):
+        self.uncatalog_object(uid)
+    
+    def modifyRecord(self, uid, **data):
+        records = self.searchResults(uid=uid)
+        if len(records) > 1:
+            # Can not happen, but anyway...
+            raise ValueError("More than one record with uid %s" % uid)
+        if len(records) == 0:
+            raise KeyError("No record for uid %s" % uid)
+        
+        record = records[0]
+        record_data = {}
+        for field in self.schema() + self.indexes():
+            record_data[field] = getattr(record, field)
+        # Add the updated data:
+        record_data.update(data)
+        self.catalog_object(dict2ob(record_data), uid)
+
+class AccomodationTable(WAeUPTable):
+    
+    meta_type = 'WAeUP Accomodation Tool'
+    
+    def __init__(self):
+        WAeUPTable.__init__(self, 'portal_accomodation')
+
+    def addRecord(self, **data):
+        # The uid is the same as "bed".
+        uid = data['bed']
+        self.catalog_object(dict2ob(data), uid=uid)
+        return uid
+
+
+InitializeClass(AccomodationTable)
Index: /WAeUP_SRP/trunk/configure.zcml
===================================================================
--- /WAeUP_SRP/trunk/configure.zcml	(revision 363)
+++ /WAeUP_SRP/trunk/configure.zcml	(revision 363)
@@ -0,0 +1,12 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    >
+
+  <adapter
+      factory=".exportimport.WAeUPTableXMLAdapter"
+      provides="Products.GenericSetup.interfaces.IBody"
+      for=".interfaces.IWAeUPTable
+           Products.GenericSetup.interfaces.ISetupEnviron"
+      />
+
+</configure>
Index: /WAeUP_SRP/trunk/exportimport.py
===================================================================
--- /WAeUP_SRP/trunk/exportimport.py	(revision 362)
+++ /WAeUP_SRP/trunk/exportimport.py	(revision 363)
@@ -55,13 +55,27 @@
     pm = site.portal_membership
     pm.setLocalGroupRoles(site,['role:Authenticated',],'SectionReader')
+
+    importObjects(site.portal_accomodation, '', context)
+    
 ##    if hasattr(site,'campus'):
 ##        pm.setLocalGroupRoles(site.campus,['role:Authenticated',],'SectionReader')
     #setupStructure(site,context)
     #import pdb; pdb.set_trace()
-    pass
     #site = context.getSite()
     #tool = getToolByName(site, TOOL)
     #importObjects(tool, '', context)
 
+
+from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter
+
+from interfaces import IWAeUPTable
+
+class WAeUPTableXMLAdapter(ZCatalogXMLAdapter):
+    
+    __used_for__ = IWAeUPTable
+
+    _LOGGER_ID = 'waeup_table'
+
+    name = 'accomodation'
 
 # This the XMLAdapter itself. It encodes the im- / export logic that is specific
Index: /WAeUP_SRP/trunk/interfaces.py
===================================================================
--- /WAeUP_SRP/trunk/interfaces.py	(revision 362)
+++ /WAeUP_SRP/trunk/interfaces.py	(revision 363)
@@ -16,2 +16,22 @@
     """WAeUP_SRP
     """
+
+class IWAeUPTable(Interface):
+    """Tables to store object relational data
+    """
+
+    def addRecord(**data):
+        """Adds a record, with the data expressed in the data mapping.
+        
+        Raises an error if the uid exists.
+        """
+    
+    def deleteRecord(uid):
+        """Deletes the record specified by the uid"""
+    
+    def modifyRecord(uid, **data):
+        """Modifies a record, with the data expressed in the data mapping.
+        
+        Raises an error if the uid does not exist.
+        """
+        
Index: /WAeUP_SRP/trunk/profiles/default/accomodation.xml
===================================================================
--- /WAeUP_SRP/trunk/profiles/default/accomodation.xml	(revision 363)
+++ /WAeUP_SRP/trunk/profiles/default/accomodation.xml	(revision 363)
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<object name="portal_catalog" meta_type="CMF Catalog">
+ <column value="bed"/>
+ <column value="student"/>
+ <index name="bed" meta_type="FieldIndex">
+  <indexed_attr value="bed"/>
+ </index>
+ <index name="student" meta_type="FieldIndex">
+  <indexed_attr value="student"/>
+ </index>
+</object>
Index: /WAeUP_SRP/trunk/profiles/default/toolset.xml
===================================================================
--- /WAeUP_SRP/trunk/profiles/default/toolset.xml	(revision 363)
+++ /WAeUP_SRP/trunk/profiles/default/toolset.xml	(revision 363)
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<tool-setup>
+ <required tool_id="portal_accomodation"
+           class="Products.WAeUP_SRP.WAeUPTables.AccomodationTable"/>
+</tool-setup>
Index: /WAeUP_SRP/trunk/tests/test_tables.py
===================================================================
--- /WAeUP_SRP/trunk/tests/test_tables.py	(revision 363)
+++ /WAeUP_SRP/trunk/tests/test_tables.py	(revision 363)
@@ -0,0 +1,57 @@
+# (C) Copyright 2006 AixtraWare <http://aixtraware.de>
+# Author: Joachim Schmitz <js@aixtraware.de>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+#
+# $Id$
+import unittest
+
+from waeuptest import WAeUP_SRPTest
+
+class TestTables(WAeUP_SRPTest):
+    
+    # Test that data does not go away on reinstall
+    def test_install(self):
+        # Make sure the table got installed properly
+        patool = self.portal.portal_accomodation
+        self.failUnlessEqual(patool.meta_type, 'WAeUP Accomodation Tool')
+        self.failUnlessEqual(patool.schema(), ['bed', 'student'])
+        self.failUnlessEqual(patool.indexes(), ['bed', 'student'])
+        
+    def test_add_change_delete(self):
+        patool = self.portal.portal_accomodation
+        
+        # Add
+        uid = patool.addRecord(bed='bed', student='student')
+        result = patool.searchResults({'bed':'bed'})
+        self.failUnlessEqual(len(result), 1)
+        self.failUnlessEqual(result[0].student, 'student')
+        
+        # Change
+        patool.modifyRecord(uid, student='newstudent')
+        result = patool.searchResults({'bed':'bed'})
+        self.failUnlessEqual(len(result), 1)
+        self.failUnlessEqual(result[0].student, 'newstudent')
+        
+        # Delete
+        patool.deleteRecord(uid)
+        result = patool.searchResults({'bed':'bed'})
+        self.failUnlessEqual(len(result), 0)
+    
+
+def test_suite():
+    return unittest.TestSuite((
+        unittest.makeSuite(TestTables),
+        ))
