Index: /waeup/branches/ulif-layout/src/waeup/university/certificate.py
===================================================================
--- /waeup/branches/ulif-layout/src/waeup/university/certificate.py	(revision 4735)
+++ /waeup/branches/ulif-layout/src/waeup/university/certificate.py	(revision 4736)
@@ -7,9 +7,5 @@
 from zope.component.interfaces import IFactory, ComponentLookupError
 from zope.interface import implementedBy
-from waeup.interfaces import (ICertificate, ICertificateContainer,
-                              ICertificateCourse, ICourse, IDepartment)
-from waeup.viewlets import (FormWrapMixin, Index, Manage, MainArea,
-                            AddCertificateCourse)
-from waeup.utils.helpers import getName
+from waeup.interfaces import ICertificate, ICertificateCourse, ICourse
 
 class Certificate(grok.Container):
@@ -96,4 +92,6 @@
 
     def getCourseCode(self):
+        """Get code of a course.
+        """
         return self.course.code
     
@@ -112,226 +110,4 @@
         return implementedBy(CertificateCourse)
 
-class ContentHeader(grok.Viewlet):
-    """A viewlet that renders the faculty, department and course title.
-    """
-    grok.viewletmanager(MainArea)
-    grok.context(ICertificate)
-    grok.view(Index)
-    grok.order(2)
-
-    def getURLAndName(self, context):
-        url = self.view.url(context)
-        name = getName(context)
-        return (url, name)
-    
-    def render(self):
-        url1, name1 = self.getURLAndName(
-            self.context.__parent__.__parent__.__parent__)
-        url2, name2 = self.getURLAndName(
-            self.context.__parent__.__parent__)
-        url3 = self.view.url(self.context)
-        name3 = self.context.title
-        return '''<h5><a href="%s">%s</a></h5>
-                  <h4><a href="%s">%s</a></h4>
-                  <h3><a href="%s">%s</a></h3>''' % (
-            url1, name1, url2, name2, url3, name3)
-
-class DisplayForm(grok.DisplayForm):
-    grok.context(ICertificate)
-    form_fields = grok.AutoFields(ICertificate)
- 
-class Content(FormWrapMixin, grok.Viewlet):
-    """A viewlet that wraps the `DisplayForm`.
-    """
-    grok.viewletmanager(MainArea)
-    grok.context(ICertificate)
-    grok.view(Index)
-    grok.order(2)
-    formview_name = 'displayform' # The name of the formview we want
-                                  # to be rendered in this viewlet.
-
-
-class ManageForm(grok.EditForm):
-    """Manage the basic properties of a `Department` instance.
-    """
-    grok.context(ICertificate)
-    form_fields = grok.AutoFields(ICertificate)
-
-    @property
-    def label(self):
-        # Set certificate name as form label
-        return self.form_fields['title'].field.get(self.context)
-    
-    @grok.action('Save')
-    def save(self, **data):
-        self.applyData(self.context, **data)
-        return
-    
-    @grok.action('Save and return')
-    def saveAndReturn(self, **data):
-        self.applyData(self.context, **data)
-        self.redirect(self.url(self.context))
-        return
-
-    @grok.action('Cancel')
-    def cancel(self, **data):
-        self.redirect(self.url(self.context))
-        return
-
-class ManageCertificate(FormWrapMixin, grok.Viewlet):
-    """A viewlet that renders the `ManageForm`.
-    """
-    grok.viewletmanager(MainArea)
-    grok.context(ICertificate)
-    grok.view(Manage)
-    grok.require('waeup.manageUniversity')
-    
-    formview_name = 'manageform' # The name of the formview we want to
-                                 # be rendered in this viewlet.
-
-class CourseList(grok.Viewlet):
-    grok.viewletmanager(MainArea)
-    grok.context(ICertificate)
-    grok.view(Index)
-    grok.order(2)
-
-    def update(self):
-        if 'delcourse' in self.request.form:
-            code = self.request.form['code']
-            level = self.request.form['level']
-            self.context.delCourseRef(code, level=level)
-        return
-        
-    def getCourseList(self):
-        def cmpCourses(a, b):
-            if a['level'] < b['level']:
-                return -1
-            if a['level'] > b['level']:
-                return 1
-            if a['mandatory'] != b['mandatory']:
-                if a['mandatory'] == False and b['mandatory'] == True:
-                    return -1
-                return 1
-            if a['code'] < b['code']:
-                return -1
-            if a['code'] > b['code']:
-                return 1
-            return 0
-
-        entries = []
-        levels = dict()
-        for key, course in self.context.items():
-            certcourse = self.context[key]
-            course = certcourse.course
-            level = certcourse.level
-            mandatory = certcourse.core_or_elective
-            title = course.title
-            code = course.code
-            course_url = self.view.url(self.context[key])
-            semester = course.semester
-
-            new_entry = dict(
-                level=level, mandatory=mandatory, url=course_url,
-                title=title, code=code, semester=semester)
-            if str(level) not in levels.keys():
-                levels[str(level)] = dict()
-            if str(semester) not in levels[str(level)].keys():
-                levels[str(level)][str(semester)] = []
-            levels[str(level)][str(semester)].append(new_entry)
-        return levels
-
-
-class AddCertificateCourseForm(grok.AddForm):
-    grok.context(Certificate)
-    
-    form_fields = grok.AutoFields(ICertificateCourse)
-    label = 'Add a course'
-
-    @grok.action('Add course')
-    def addCertcourse(self, **data):
-        try:
-            self.context.addCourseRef(**data)
-        except DuplicationError:
-            self.status = Invalid('The chosen course is already part of'
-                                  'this certificate')
-            return
-        self.redirect(self.url(self.context))
-
-    @grok.action('Cancel')
-    def cancel(self, **data):
-        self.redirect(self.url(self.context))
-        return
-
-class AddCertificateCourse(FormWrapMixin, grok.Viewlet):
-    """A viewlet that wraps the `AddCertificateCourseForm`.
-    """
-    grok.viewletmanager(MainArea)
-    grok.context(ICertificate)
-    grok.view(AddCertificateCourse)
-    grok.require('waeup.manageUniversity')
-
-    formview_name = 'addcertificatecourseform' # The name of the formview we
-                                               # want to be rendered in this
-                                               # viewlet.
-
-class DisplayCertCourseForm(grok.DisplayForm):
-    grok.context(ICertificateCourse)
-    form_fields = grok.AutoFields(ICertificateCourse)
-
-class CertCourseContent(FormWrapMixin, grok.Viewlet):
-    """A viewlet that wraps the `DisplayForm`.
-    """
-    grok.viewletmanager(MainArea)
-    grok.context(ICertificateCourse)
-    grok.view(Index)
-    grok.order(2)
-    formview_name = 'displaycertcourseform' # The name of the formview we want
-                                            # to be rendered in this viewlet.
-
-class ManageCertCourseForm(grok.EditForm):
-    """Manage the basic properties of a `CertificateCourse` instance.
-    """
-    grok.context(ICertificateCourse)
-    form_fields = grok.AutoFields(ICertificateCourse)
-
-    @property
-    def label(self):
-        # Set certificate name as form label
-        return 'Edit certificate course %s' % self.context.course.code
-        return self.form_fields['title'].field.get(self.context)
-    
-    @grok.action('Save and return')
-    def saveAndReturn(self, **data):
-        parent = self.context.__parent__
-        if self.context.level == data['level']:
-            self.applyData(self.context, **data)
-        else:
-            # The level changed. We have to create a new certcourse as
-            # the key of the entry will change as well...
-            old_level = self.context.level
-            parent.addCourseRef(**data)
-            parent.delCourseRef(data['course'].code, level=old_level)
-        self.redirect(self.url(parent))
-        return
-
-    @grok.action('Cancel')
-    def cancel(self, **data):
-        self.redirect(self.url(self.context))
-        return
-
-class ManageCertificateCourse(FormWrapMixin, grok.Viewlet):
-    """A viewlet that renders the `ManageCertCourseForm`.
-    """
-    grok.viewletmanager(MainArea)
-    grok.context(ICertificateCourse)
-    grok.view(Manage)
-    grok.name('manage')
-    #grok.require('waeup.manageUniversity')
-    
-    formview_name = 'managecertcourseform' # The name of the formview
-                                           # we want to be rendered
-                                           # in this viewlet.
-
-    
 @grok.subscribe(ICourse, grok.IObjectRemovedEvent)
 def removedCourseHandler(course, event):
