Changeset 4412 for waeup


Ignore:
Timestamp:
21 Jul 2009, 14:59:33 (15 years ago)
Author:
uli
Message:

Add a YUI driven table provider for faculty containers, rendering a
sortable list of faculties.

File:
1 edited

Legend:

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

    r4390 r4412  
    1010from waeup.viewlets import (MainArea, LeftSidebar, Index, Add, Manage,
    1111                            FormWrapMixin)
    12 
     12from waeup.widgets.interfaces import ITableProvider
     13from waeup.widgets.table import Col, YUITable
    1314
    1415class FacultyContainer(grok.Container):
     
    2930            del self[key]
    3031
     32    def getName(self, key):
     33        if key in self.keys():
     34            fac = self[key]
     35            prefix = fac.title_prefix
     36            prefix = prefix[0].upper() + prefix[1:]
     37            return '%s of %s' % (prefix, fac.title)
     38           
    3139class FacultyContainerFactory(grok.GlobalUtility):
    3240    """A factory for faculty containers.
     
    5260    grok.view(Index)
    5361
     62    def update(self):
     63        self.table = ITableProvider(self.context).getTable()
     64        self.table.need()
     65   
    5466    def getFaculties(self):
    5567        """Convinience method to create a sorted list of faculties.
     
    148160    def render(self):
    149161        return u'<div class="portlet"><a href="manage">Manage faculties</a></div>'
     162
     163class FacultyTableProvider(grok.Adapter):
     164    grok.context(IFacultyContainer)
     165    grok.provides(ITableProvider)
     166
     167    def __init__(self, context):
     168        self.context = context
     169        data = self.context
     170        cols = (
     171            Col(
     172                header='Code', sortable=True,
     173                data = tuple(['<a href="%s">%s</a>' % (
     174                            data[x].code, data[x].code) for x in data])),
     175            Col(
     176                header='Title', sortable=True,
     177                data = tuple([data.getName(x) for x in data])),
     178                )
     179        self.table = YUITable('Faculties', cols=cols)
     180
     181    def getTable(self):
     182        return self.table
Note: See TracChangeset for help on using the changeset viewer.