Changeset 4434


Ignore:
Timestamp:
25 Jul 2009, 11:31:00 (15 years ago)
Author:
uli
Message:

Move faculty table provider for universities to new module.

Location:
waeup/branches/ulif-rewrite/src/waeup
Files:
2 edited

Legend:

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

    r4409 r4434  
    1313from waeup.users import UserContainer
    1414from waeup.widgets.interfaces import ITableProvider
    15 from waeup.widgets.table import Table, Col, YUITable
    1615
    1716class University(grok.Application, grok.Container):
     
    9594                                 # be rendered in this viewlet.
    9695
    97 class FacultyTableProvider(grok.Adapter):
    98     grok.context(IUniversity)
    99     grok.provides(ITableProvider)
    100 
    101     def __init__(self, context):
    102         self.context = context
    103         data = self.context.faculties
    104         cols = (
    105             Col(
    106                 header='Code', sortable=True,
    107                 data = tuple(['<a href="faculties/%s">%s</a>' % (
    108                             data[x].code, data[x].code) for x in data])),
    109             Col(
    110                 header='Prefix', sortable=True,
    111                 data = tuple([data[x].title_prefix for x in data])),
    112             Col(
    113                 header='Title', sortable=True,
    114                 data = tuple([data[x].title for x in data])),
    115                 )
    116         self.table = YUITable('Faculties', cols=cols)
    117 
    118     def getTable(self):
    119         return self.table
    120    
    12196class Content(grok.Viewlet):
    12297    grok.viewletmanager(MainArea)
     
    125100
    126101    def update(self):
    127         self.table = ITableProvider(self.context).getTable()
     102        self.table = ITableProvider(self.context).getTable(self.view)
    128103        self.table.need()
    129104
  • waeup/branches/ulif-rewrite/src/waeup/tables.py

    r4433 r4434  
    99
    1010class CodeAndTitleTableProvider(grok.Adapter):
     11    """A table provider for objects that have a code, title and prefix.
     12    """
    1113    grok.baseclass()
    1214    grok.provides(ITableProvider)
     
    1416    title = None
    1517
     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   
    1632    def getTable(self, view=None):
    17         data = self.context
     33        data = self.data_source
    1834        context_url = ''
    1935        if view:
     
    2238            Col(
    2339                header='Code', sortable=True,
    24                 data = tuple(['<a href="%s%s">%s</a>' % (
    25                             context_url, data[x].code,
    26                             data[x].code) for x in data])),
     40                data = tuple([self.getItemURL(view, data[x].code)
     41                              for x in data])),
    2742            Col(
    2843                header='Title', sortable=True,
     
    4156    grok.provides(ITableProvider)
    4257    title = 'Faculties'
     58
     59class UniversityTableProvider(CodeAndTitleTableProvider):
     60    grok.context(IUniversity)
     61    grok.provides(ITableProvider)
     62    title = 'Faculties'
     63
     64    def prepare(self):
     65        self.data_source = self.context.faculties
Note: See TracChangeset for help on using the changeset viewer.