Changeset 4236 for waeup/branches


Ignore:
Timestamp:
9 Jun 2009, 10:08:47 (15 years ago)
Author:
uli
Message:

Add manage view for facultycontainers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/university/facultycontainer.py

    r4233 r4236  
     1import sys
    12import grok
    23from zope.component import getUtility
     
    1011from waeup.interfaces import IFacultyContainer, IFaculty, IWAeUPCSVImporter
    1112from waeup.utils.importexport import CSVImporter
    12 from waeup.viewlets import MainArea, LeftSidebar, Index, Add, FormWrapMixin
     13from waeup.viewlets import (MainArea, LeftSidebar, Index, Add, Manage,
     14                            FormWrapMixin)
    1315
    1416
     
    102104        return result
    103105
     106class ManageFacultyContainer(grok.Viewlet):
     107    grok.viewletmanager(MainArea)
     108    grok.context(IFacultyContainer)
     109    grok.view(Manage)
     110    grok.template('manage')   
     111
     112    def update(self):
     113        form = self.request.form
     114        if 'CANCEL' in form.keys():
     115            self.view.redirect(self.view.url(self.context))
     116        if not 'DELETE' in form.keys():
     117            return
     118        fac_id = form['fac_id']
     119        if not isinstance(fac_id, list):
     120            fac_id = [fac_id]
     121        deleted = []
     122        for id in fac_id:
     123            try:
     124                del self.context[id]
     125                deleted.append(id)
     126            except:
     127                self.view.flash('Could not delete %s: %s: %s' % (
     128                        id, sys.exc_info()[0], sys.exc_info()[1]))
     129        if len(deleted):
     130            self.view.flash('Successfully deleted: %s' % ', '.join(deleted))
     131        # We have to redirect to let flash messages appear immediately...
     132        self.view.redirect(self.view.url())
     133        return
     134       
    104135class AddFacultyForm(grok.AddForm):
    105136    grok.context(IFacultyContainer)
     
    147178        return u'<div class="portlet"><a href="add">Add faculty</a></div>'
    148179
    149 
     180class ManageFacultyLink(grok.Viewlet):
     181    """A link in the left sidebar displaying 'Manage faculty'
     182    """
     183    grok.viewletmanager(LeftSidebar)
     184    grok.context(IFacultyContainer)
     185    grok.view(Index)
     186    grok.order(5)
     187    grok.require('waeup.manageUniversity')
     188   
     189    def render(self):
     190        return u'<div class="portlet"><a href="manage">Manage faculties</a></div>'
Note: See TracChangeset for help on using the changeset viewer.