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

Last change on this file since 5921 was 5915, checked in by Henrik Bettermann, 14 years ago

Use only getName method from helpers.py. Don't define getName for each container class.

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
8from waeup.sirp.utils.helpers import getName
9
10class CodeAndTitleTableProvider(grok.Adapter):
11    """A table provider for objects that have a code, title and prefix.
12    """
13    grok.baseclass()
14    grok.provides(ITableProvider)
15
16    title = None
17
18    def __init__(self, context):
19        self.context = context
20        self.prepare()
21
22    def prepare(self):
23        self.data_source = self.context
24
25    def getItemURL(self, view, value):
26        context_url = ''
27        if not view is None:
28            context_url = view.url(self.data_source) + '/'
29        result = '<a href="%s%s">%s</a>' % (context_url, value, value)
30        return result
31   
32    def getTables(self, view=None):
33        data = self.data_source
34        context_url = ''
35        if view:
36            context_url = view.url(self.context) + '/'
37        cols = (
38            Col(
39                header='Code', sortable=True,
40                data = tuple([self.getItemURL(view, data[x].code)
41                              for x in data])),
42            Col(
43                header='Title', sortable=True,
44                data = tuple([getName(data[x]) for x in data])),
45            )
46        self.table = Table(self.title, cols=cols)
47        return (self.table,)
48   
49class UniversityTableProvider(CodeAndTitleTableProvider):
50    grok.context(IUniversity)
51    grok.provides(ITableProvider)
52    title = 'Faculties'
53
54    def prepare(self):
55        self.data_source = self.context.faculties
56
Note: See TracBrowser for help on using the repository browser.