source: main/waeup.sirp/branches/ulif-fasttables/src/waeup/sirp/tables.py @ 5237

Last change on this file since 5237 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
Line 
1"""Datatables and related components used in different contexts.
2"""
3import grok
4from waeup.sirp.interfaces import IUniversity
5from waeup.sirp.widgets.interfaces import ITableProvider
6from waeup.sirp.widgets.table import YUITable as Table
7from waeup.sirp.widgets.table import Col
8
9class CodeAndTitleTableProvider(grok.Adapter):
10    """A table provider for objects that have a code, title and prefix.
11    """
12    grok.baseclass()
13    grok.provides(ITableProvider)
14
15    title = None
16
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   
31    def getTables(self, view=None):
32        data = self.data_source
33        context_url = ''
34        if view:
35            context_url = view.url(self.context) + '/'
36        cols = (
37            Col(
38                header='Code', sortable=True,
39                data = tuple([self.getItemURL(view, data[x].code)
40                              for x in data])),
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)
46        return (self.table,)
47   
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
55
Note: See TracBrowser for help on using the repository browser.