source: main/waeup.sirp/trunk/src/waeup/sirp/tables.py @ 5352

Last change on this file since 5352 was 5006, checked in by uli, 15 years ago

Move academics specific UI code from tables module into separate browser.tables module.

File size: 1.7 KB
RevLine 
[4431]1"""Datatables and related components used in different contexts.
2"""
3import grok
[5005]4from waeup.sirp.interfaces import IUniversity
[4920]5from waeup.sirp.widgets.interfaces import ITableProvider
6from waeup.sirp.widgets.table import YUITable as Table
7from waeup.sirp.widgets.table import Col
[4431]8
[4432]9class CodeAndTitleTableProvider(grok.Adapter):
[4434]10    """A table provider for objects that have a code, title and prefix.
11    """
[4432]12    grok.baseclass()
[4431]13    grok.provides(ITableProvider)
14
[4432]15    title = None
[4431]16
[4434]17    def __init__(self, context):
18        self.context = context
19        self.prepare()
20
21    def prepare(self):
22        self.data_source = self.context
23
24    def getItemURL(self, view, value):
25        context_url = ''
26        if not view is None:
27            context_url = view.url(self.data_source) + '/'
28        result = '<a href="%s%s">%s</a>' % (context_url, value, value)
29        return result
30   
[4461]31    def getTables(self, view=None):
[4434]32        data = self.data_source
[4432]33        context_url = ''
34        if view:
35            context_url = view.url(self.context) + '/'
[4431]36        cols = (
37            Col(
38                header='Code', sortable=True,
[4434]39                data = tuple([self.getItemURL(view, data[x].code)
40                              for x in data])),
[4431]41            Col(
42                header='Title', sortable=True,
43                data = tuple([data.getName(x) for x in data])),
44            )
45        self.table = Table(self.title, cols=cols)
[4461]46        return (self.table,)
[4432]47   
[4434]48class UniversityTableProvider(CodeAndTitleTableProvider):
49    grok.context(IUniversity)
50    grok.provides(ITableProvider)
51    title = 'Faculties'
52
53    def prepare(self):
54        self.data_source = self.context.faculties
[4442]55
Note: See TracBrowser for help on using the repository browser.