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

Last change on this file since 5936 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
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
[5915]8from waeup.sirp.utils.helpers import getName
[4431]9
[4432]10class CodeAndTitleTableProvider(grok.Adapter):
[4434]11    """A table provider for objects that have a code, title and prefix.
12    """
[4432]13    grok.baseclass()
[4431]14    grok.provides(ITableProvider)
15
[4432]16    title = None
[4431]17
[4434]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   
[4461]32    def getTables(self, view=None):
[4434]33        data = self.data_source
[4432]34        context_url = ''
35        if view:
36            context_url = view.url(self.context) + '/'
[4431]37        cols = (
38            Col(
39                header='Code', sortable=True,
[4434]40                data = tuple([self.getItemURL(view, data[x].code)
41                              for x in data])),
[4431]42            Col(
43                header='Title', sortable=True,
[5915]44                data = tuple([getName(data[x]) for x in data])),
[4431]45            )
46        self.table = Table(self.title, cols=cols)
[4461]47        return (self.table,)
[4432]48   
[4434]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
[4442]56
Note: See TracBrowser for help on using the repository browser.