Changeset 4689 for waeup/branches


Ignore:
Timestamp:
6 Jan 2010, 03:45:02 (15 years ago)
Author:
uli
Message:

Remove viewing components. They went to browser subpackage.

File:
1 edited

Legend:

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

    r4464 r4689  
    1 import sys
    21import grok
    3 from zope.component import getUtility
    4 from zope.component.factory import Factory
    5 from zope.component.interfaces import Invalid, IFactory
    6 from zope.component import createObject
    7 from zope.exceptions import DuplicationError
     2from zope.component.interfaces import IFactory
    83from zope.interface import implementedBy
    9 from waeup.interfaces import IFacultyContainer, IFaculty, IWAeUPCSVImporter
    10 from waeup.viewlets import (MainArea, LeftSidebar, Index, Add, Manage,
    11                             FormWrapMixin)
    12 from waeup.widgets.interfaces import ITableProvider
     4from waeup.interfaces import IFacultyContainer, IFaculty
    135
    146class FacultyContainer(grok.Container):
     
    4941    def getInterfaces(self):
    5042        return implementedBy(FacultyContainer)
    51 
    52 
    53 #
    54 # Viewing / Layout stuff...
    55 #
    56 class Content(grok.Viewlet):
    57     grok.viewletmanager(MainArea)
    58     grok.context(IFacultyContainer)
    59     grok.view(Index)
    60 
    61     def update(self):
    62         self.table = ITableProvider(self.context).getTables(self.view)[0]
    63         self.table.need()
    64    
    65     def getFaculties(self):
    66         """Convinience method to create a sorted list of faculties.
    67 
    68         It provides a list of dicts with entries for all data needed by
    69         usual list templates.
    70         """
    71         result = []
    72         for key, val in self.context.items():
    73             result.append(dict(id=key, name=val.title))
    74         return result
    75 
    76 class ManageFacultyContainer(grok.Viewlet):
    77     grok.viewletmanager(MainArea)
    78     grok.context(IFacultyContainer)
    79     grok.view(Manage)
    80     grok.template('manage')   
    81 
    82     def update(self):
    83         form = self.request.form
    84         if 'CANCEL' in form.keys():
    85             self.view.redirect(self.view.url(self.context))
    86         if not 'DELETE' in form.keys():
    87             return
    88         fac_id = form['fac_id']
    89         if not isinstance(fac_id, list):
    90             fac_id = [fac_id]
    91         deleted = []
    92         for id in fac_id:
    93             try:
    94                 del self.context[id]
    95                 deleted.append(id)
    96             except:
    97                 self.view.flash('Could not delete %s: %s: %s' % (
    98                         id, sys.exc_info()[0], sys.exc_info()[1]))
    99         if len(deleted):
    100             self.view.flash('Successfully deleted: %s' % ', '.join(deleted))
    101         # We have to redirect to let flash messages appear immediately...
    102         self.view.redirect(self.view.url())
    103         return
    104        
    105 class AddFacultyForm(grok.AddForm):
    106     grok.context(IFacultyContainer)
    107     form_fields = grok.AutoFields(IFaculty)
    108     label = 'Add a faculty'
    109 
    110     @grok.action('Add faculty')
    111     def addFaculty(self, **data):
    112         faculty = createObject(u'waeup.Faculty')
    113         self.applyData(faculty, **data)
    114         try:
    115             self.context.addFaculty(faculty)
    116         except DuplicationError:
    117             self.status = Invalid('The name chosen already exists '
    118                                   'in the database')
    119             return
    120         self.redirect(self.url(self.context))
    121 
    122        
    123 class AddFaculty(FormWrapMixin, grok.Viewlet):
    124     """A viewlet that wraps the `AddFacultyForm`.
    125     """
    126     grok.viewletmanager(MainArea)
    127     grok.context(IFacultyContainer)
    128     grok.view(Add)
    129     grok.require('waeup.manageUniversity')
    130 
    131     formview_name = 'addfacultyform' # The name of the formview we
    132                                      # want to be rendered in this
    133                                      # viewlet.
    134 
    135 
    136 class AddFacultyLink(grok.Viewlet):
    137     """A link in the left sidebar displaying 'Add faculty'
    138     """
    139     grok.viewletmanager(LeftSidebar)
    140     grok.context(IFacultyContainer)
    141     grok.view(Index)
    142     grok.order(5)
    143     # This is so cool! This link is only displayed, when the user is
    144     # allowed to use it!
    145     grok.require('waeup.manageUniversity')
    146    
    147     def render(self):
    148         return u'<div class="portlet"><a href="add">Add faculty</a></div>'
    149 
    150 class ManageFacultyLink(grok.Viewlet):
    151     """A link in the left sidebar displaying 'Manage faculty'
    152     """
    153     grok.viewletmanager(LeftSidebar)
    154     grok.context(IFacultyContainer)
    155     grok.view(Index)
    156     grok.order(5)
    157     grok.require('waeup.manageUniversity')
    158    
    159     def render(self):
    160         return u'<div class="portlet"><a href="manage">Manage faculties</a></div>'
Note: See TracChangeset for help on using the changeset viewer.