Changeset 5006 for main/waeup.sirp/trunk


Ignore:
Timestamp:
4 Feb 2010, 12:10:22 (15 years ago)
Author:
uli
Message:

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

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/tables.py

    r5005 r5006  
    33import grok
    44from waeup.sirp.interfaces import IUniversity
    5 from waeup.sirp.university.interfaces import (
    6     IFacultyContainer, IFaculty, IDepartment, ICourseContainer)
    75from waeup.sirp.widgets.interfaces import ITableProvider
    86from waeup.sirp.widgets.table import YUITable as Table
    97from waeup.sirp.widgets.table import Col
    10 from zope.security.management import checkPermission
    118
    129class CodeAndTitleTableProvider(grok.Adapter):
     
    4946        return (self.table,)
    5047   
    51 class DepartmentTableProvider(CodeAndTitleTableProvider):
    52     grok.context(IFaculty)
    53     grok.provides(ITableProvider)
    54     title = 'Departments'
    55 
    56 class FacultyTableProvider(CodeAndTitleTableProvider):
    57     grok.context(IFacultyContainer)
    58     grok.provides(ITableProvider)
    59     title = 'Faculties'
    60 
    6148class UniversityTableProvider(CodeAndTitleTableProvider):
    6249    grok.context(IUniversity)
     
    6754        self.data_source = self.context.faculties
    6855
    69 class CourseTableProvider(CodeAndTitleTableProvider):
    70     grok.context(IDepartment)
    71     grok.provides(ITableProvider)
    72     title = 'Courses'
    73 
    74     def prepare(self):
    75         self.data_source = self.context.courses
    76        
    77     def getTables(self, view=None):
    78         data = self.data_source
    79         context_url = ''
    80         if view:
    81             context_url = view.url(self.context) + '/'
    82 
    83         # Create a courses table...
    84         cols = (
    85             Col(
    86                 header='Code', sortable=True,
    87                 data = tuple([self.getItemURL(view, data[x].code)
    88                               for x in data])),
    89             Col(
    90                 header='Title', sortable=True,
    91                 data = tuple([data[x].title for x in data])),
    92             )
    93         delcol = Col(header='', sortable=False,
    94                      data = [
    95                 '<form method="post">'
    96                 '<input type="submit" name="delcourse" value="Delete" />'
    97                 '<input type="hidden" name="code" value="%s" />'
    98                 '</form>' % (data[x].code)
    99                 for x in data])
    100 
    101         if checkPermission('waeup.manageUniversity', self.context.courses):
    102             cols = list(cols)
    103             cols.append(delcol)
    104             cols = tuple(cols)
    105         self.coursetable = Table('Courses', cols=cols)
    106 
    107         # Create a certificates table...
    108         self.data_source = self.context.certificates
    109         data = self.data_source
    110         certcols =(
    111             Col(
    112                 header='Code', sortable=True,
    113                 data = tuple([self.getItemURL(view, data[x].code)
    114                               for x in data])),
    115             Col(
    116                 header='Title', sortable=True,
    117                 data = tuple([data[x].title for x in data])),
    118             )
    119 
    120         delcol = Col(header='', sortable=False,
    121                      data = [
    122                 '<form method="post">'
    123                 '<input type="submit" name="delcert" value="Delete" />'
    124                 '<input type="hidden" name="code" value="%s" />'
    125                 '</form>' % (data[x].code)
    126                 for x in data])
    127 
    128         if checkPermission('waeup.manageUniversity', self.context.certificates):
    129             certcols = list(certcols)
    130             certcols.append(delcol)
    131             certcols = tuple(certcols)
    132 
    133         self.certtable = Table('Certificates', cols=certcols)
    134         return (self.coursetable, self.certtable)
    135 
    136 class CourseContainerCourseTableProvider(CodeAndTitleTableProvider):
    137     grok.context(ICourseContainer)
    138     grok.provides(ITableProvider)
    139     title = 'Courses'
    140 
    141     def getTables(self, view=None):
    142         data = self.data_source
    143         context_url = ''
    144         if view:
    145             context_url = view.url(self.context) + '/'
    146         cols = (
    147             Col(
    148                 header='Code', sortable=True,
    149                 data = tuple([self.getItemURL(view, data[x].code)
    150                               for x in data])),
    151             Col(
    152                 header='Title', sortable=True,
    153                 data = tuple([data[x].title for x in data])),
    154             )
    155         self.table = Table(self.title, cols=cols)
    156         return (self.table,)
Note: See TracChangeset for help on using the changeset viewer.