Ignore:
Timestamp:
8 Jan 2010, 03:28:48 (15 years ago)
Author:
uli
Message:

Remove view component stuff. It moved to browser subpackage.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-layout/src/waeup/university/certificate.py

    r4562 r4736  
    77from zope.component.interfaces import IFactory, ComponentLookupError
    88from zope.interface import implementedBy
    9 from waeup.interfaces import (ICertificate, ICertificateContainer,
    10                               ICertificateCourse, ICourse, IDepartment)
    11 from waeup.viewlets import (FormWrapMixin, Index, Manage, MainArea,
    12                             AddCertificateCourse)
    13 from waeup.utils.helpers import getName
     9from waeup.interfaces import ICertificate, ICertificateCourse, ICourse
    1410
    1511class Certificate(grok.Container):
     
    9692
    9793    def getCourseCode(self):
     94        """Get code of a course.
     95        """
    9896        return self.course.code
    9997   
     
    112110        return implementedBy(CertificateCourse)
    113111
    114 class ContentHeader(grok.Viewlet):
    115     """A viewlet that renders the faculty, department and course title.
    116     """
    117     grok.viewletmanager(MainArea)
    118     grok.context(ICertificate)
    119     grok.view(Index)
    120     grok.order(2)
    121 
    122     def getURLAndName(self, context):
    123         url = self.view.url(context)
    124         name = getName(context)
    125         return (url, name)
    126    
    127     def render(self):
    128         url1, name1 = self.getURLAndName(
    129             self.context.__parent__.__parent__.__parent__)
    130         url2, name2 = self.getURLAndName(
    131             self.context.__parent__.__parent__)
    132         url3 = self.view.url(self.context)
    133         name3 = self.context.title
    134         return '''<h5><a href="%s">%s</a></h5>
    135                   <h4><a href="%s">%s</a></h4>
    136                   <h3><a href="%s">%s</a></h3>''' % (
    137             url1, name1, url2, name2, url3, name3)
    138 
    139 class DisplayForm(grok.DisplayForm):
    140     grok.context(ICertificate)
    141     form_fields = grok.AutoFields(ICertificate)
    142  
    143 class Content(FormWrapMixin, grok.Viewlet):
    144     """A viewlet that wraps the `DisplayForm`.
    145     """
    146     grok.viewletmanager(MainArea)
    147     grok.context(ICertificate)
    148     grok.view(Index)
    149     grok.order(2)
    150     formview_name = 'displayform' # The name of the formview we want
    151                                   # to be rendered in this viewlet.
    152 
    153 
    154 class ManageForm(grok.EditForm):
    155     """Manage the basic properties of a `Department` instance.
    156     """
    157     grok.context(ICertificate)
    158     form_fields = grok.AutoFields(ICertificate)
    159 
    160     @property
    161     def label(self):
    162         # Set certificate name as form label
    163         return self.form_fields['title'].field.get(self.context)
    164    
    165     @grok.action('Save')
    166     def save(self, **data):
    167         self.applyData(self.context, **data)
    168         return
    169    
    170     @grok.action('Save and return')
    171     def saveAndReturn(self, **data):
    172         self.applyData(self.context, **data)
    173         self.redirect(self.url(self.context))
    174         return
    175 
    176     @grok.action('Cancel')
    177     def cancel(self, **data):
    178         self.redirect(self.url(self.context))
    179         return
    180 
    181 class ManageCertificate(FormWrapMixin, grok.Viewlet):
    182     """A viewlet that renders the `ManageForm`.
    183     """
    184     grok.viewletmanager(MainArea)
    185     grok.context(ICertificate)
    186     grok.view(Manage)
    187     grok.require('waeup.manageUniversity')
    188    
    189     formview_name = 'manageform' # The name of the formview we want to
    190                                  # be rendered in this viewlet.
    191 
    192 class CourseList(grok.Viewlet):
    193     grok.viewletmanager(MainArea)
    194     grok.context(ICertificate)
    195     grok.view(Index)
    196     grok.order(2)
    197 
    198     def update(self):
    199         if 'delcourse' in self.request.form:
    200             code = self.request.form['code']
    201             level = self.request.form['level']
    202             self.context.delCourseRef(code, level=level)
    203         return
    204        
    205     def getCourseList(self):
    206         def cmpCourses(a, b):
    207             if a['level'] < b['level']:
    208                 return -1
    209             if a['level'] > b['level']:
    210                 return 1
    211             if a['mandatory'] != b['mandatory']:
    212                 if a['mandatory'] == False and b['mandatory'] == True:
    213                     return -1
    214                 return 1
    215             if a['code'] < b['code']:
    216                 return -1
    217             if a['code'] > b['code']:
    218                 return 1
    219             return 0
    220 
    221         entries = []
    222         levels = dict()
    223         for key, course in self.context.items():
    224             certcourse = self.context[key]
    225             course = certcourse.course
    226             level = certcourse.level
    227             mandatory = certcourse.core_or_elective
    228             title = course.title
    229             code = course.code
    230             course_url = self.view.url(self.context[key])
    231             semester = course.semester
    232 
    233             new_entry = dict(
    234                 level=level, mandatory=mandatory, url=course_url,
    235                 title=title, code=code, semester=semester)
    236             if str(level) not in levels.keys():
    237                 levels[str(level)] = dict()
    238             if str(semester) not in levels[str(level)].keys():
    239                 levels[str(level)][str(semester)] = []
    240             levels[str(level)][str(semester)].append(new_entry)
    241         return levels
    242 
    243 
    244 class AddCertificateCourseForm(grok.AddForm):
    245     grok.context(Certificate)
    246    
    247     form_fields = grok.AutoFields(ICertificateCourse)
    248     label = 'Add a course'
    249 
    250     @grok.action('Add course')
    251     def addCertcourse(self, **data):
    252         try:
    253             self.context.addCourseRef(**data)
    254         except DuplicationError:
    255             self.status = Invalid('The chosen course is already part of'
    256                                   'this certificate')
    257             return
    258         self.redirect(self.url(self.context))
    259 
    260     @grok.action('Cancel')
    261     def cancel(self, **data):
    262         self.redirect(self.url(self.context))
    263         return
    264 
    265 class AddCertificateCourse(FormWrapMixin, grok.Viewlet):
    266     """A viewlet that wraps the `AddCertificateCourseForm`.
    267     """
    268     grok.viewletmanager(MainArea)
    269     grok.context(ICertificate)
    270     grok.view(AddCertificateCourse)
    271     grok.require('waeup.manageUniversity')
    272 
    273     formview_name = 'addcertificatecourseform' # The name of the formview we
    274                                                # want to be rendered in this
    275                                                # viewlet.
    276 
    277 class DisplayCertCourseForm(grok.DisplayForm):
    278     grok.context(ICertificateCourse)
    279     form_fields = grok.AutoFields(ICertificateCourse)
    280 
    281 class CertCourseContent(FormWrapMixin, grok.Viewlet):
    282     """A viewlet that wraps the `DisplayForm`.
    283     """
    284     grok.viewletmanager(MainArea)
    285     grok.context(ICertificateCourse)
    286     grok.view(Index)
    287     grok.order(2)
    288     formview_name = 'displaycertcourseform' # The name of the formview we want
    289                                             # to be rendered in this viewlet.
    290 
    291 class ManageCertCourseForm(grok.EditForm):
    292     """Manage the basic properties of a `CertificateCourse` instance.
    293     """
    294     grok.context(ICertificateCourse)
    295     form_fields = grok.AutoFields(ICertificateCourse)
    296 
    297     @property
    298     def label(self):
    299         # Set certificate name as form label
    300         return 'Edit certificate course %s' % self.context.course.code
    301         return self.form_fields['title'].field.get(self.context)
    302    
    303     @grok.action('Save and return')
    304     def saveAndReturn(self, **data):
    305         parent = self.context.__parent__
    306         if self.context.level == data['level']:
    307             self.applyData(self.context, **data)
    308         else:
    309             # The level changed. We have to create a new certcourse as
    310             # the key of the entry will change as well...
    311             old_level = self.context.level
    312             parent.addCourseRef(**data)
    313             parent.delCourseRef(data['course'].code, level=old_level)
    314         self.redirect(self.url(parent))
    315         return
    316 
    317     @grok.action('Cancel')
    318     def cancel(self, **data):
    319         self.redirect(self.url(self.context))
    320         return
    321 
    322 class ManageCertificateCourse(FormWrapMixin, grok.Viewlet):
    323     """A viewlet that renders the `ManageCertCourseForm`.
    324     """
    325     grok.viewletmanager(MainArea)
    326     grok.context(ICertificateCourse)
    327     grok.view(Manage)
    328     grok.name('manage')
    329     #grok.require('waeup.manageUniversity')
    330    
    331     formview_name = 'managecertcourseform' # The name of the formview
    332                                            # we want to be rendered
    333                                            # in this viewlet.
    334 
    335    
    336112@grok.subscribe(ICourse, grok.IObjectRemovedEvent)
    337113def removedCourseHandler(course, event):
Note: See TracChangeset for help on using the changeset viewer.