Index: /waeup/branches/ulif-rewrite/src/waeup/hostel/hostelcontainer.py
===================================================================
--- /waeup/branches/ulif-rewrite/src/waeup/hostel/hostelcontainer.py	(revision 3939)
+++ /waeup/branches/ulif-rewrite/src/waeup/hostel/hostelcontainer.py	(revision 3940)
@@ -1,6 +1,6 @@
 import grok
 
-from waeup.interfaces import IHostelContainer
-from waeup.viewlets import MainArea, Index
+from waeup.interfaces import IHostelContainer, IHostel
+from waeup.viewlets import MainArea, Index, Add, FormWrapMixin
 from hostel import Hostel
 
@@ -13,4 +13,15 @@
     next_id = 0L
 
+    def addHostel(self, hostel):
+        if not IHostel.providedBy(hostel):
+            raise TypeError('HostelContainers contain only IHostel instances')
+        id = str(self.next_id)
+        self[id] = hostel
+        while self.next_id in self.keys():
+            # Look for next unused int...
+            self.next_id += 1
+        return id
+
+
 # We register HostelContainer as a utility. This way we can
 # call getUtility(IHostelContainer) from anywhere in the code and
@@ -18,2 +29,30 @@
 grok.global_utility(HostelContainer, provides=IHostelContainer)
 
+class AddHostelForm(grok.AddForm):
+    grok.context(IHostelContainer)
+    form_fields = grok.AutoFields(IHostel)
+    label = 'Add a hostel'
+
+    @grok.action('Add hostel')
+    def addHostel(self, **data):
+        hostel = getUtility(IHostel)
+        self.applyData(hostel, **data)
+        try:
+            self.context.addHostel(hostel)
+        except DuplicationError:
+            self.status = Invalid('The name chosen already exists '
+                                  'in the database')
+            return
+        self.redirect(self.url(self.context))
+
+class AddHostel(FormWrapMixin, grok.Viewlet):
+    """A viewlet that wraps the `AddHostelForm`.
+    """
+    grok.viewletmanager(MainArea)
+    grok.context(IHostelContainer)
+    grok.view(Add)
+    grok.require('waeup.manageUniversity')
+
+    formview_name = 'addhostelform' # The name of the formview we want
+                                    # to be rendered in this viewlet.
+
