Changeset 3855


Ignore:
Timestamp:
16 Jan 2009, 12:28:18 (16 years ago)
Author:
uli
Message:

Make use of new viewlet concept.

File:
1 edited

Legend:

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

    r3832 r3855  
    11import grok
    2 from grok import index
    3 from zope.component import getUtility
     2import re
     3from zope.component import getUtility, getMultiAdapter
    44from zope.interface import Interface
    55
    66from waeup.interfaces import (IUniversity, IStudentContainer, IHostelContainer,
    77                              IFacultyContainer)
    8 from waeup.viewlets import MainArea
     8from waeup.viewlets import MainArea, LeftSidebar, Index, Manage
    99
    1010class University(grok.Application, grok.Container):
     
    1313    grok.implements(IUniversity)
    1414
    15     def __init__(self, name=u'Unnamed', **kw):
     15    def __init__(self, name=u'Sample University', **kw):
    1616        super(University, self).__init__(**kw)
    1717        self.name = name
     
    2222        self["hostels"] = getUtility(IHostelContainer)
    2323        self["faculties"] = getUtility(IFacultyContainer)
     24
    2425       
    25 class Manage(grok.EditForm):
     26       
     27class ManageForm(grok.EditForm):
    2628    """Manage the basic properties of a `University` instance.
    2729    """
     
    4143
    4244    @grok.action('Cancel')
    43     def cancel(self):
     45    def cancel(self, **data):
    4446        self.redirect(self.url(self.context))
    4547        return
    46        
     48
     49class ManageUniversity(grok.Viewlet):
     50    """A viewlet that renders the `ManageForm`.
     51    """
     52    grok.viewletmanager(MainArea)
     53    grok.context(IUniversity)
     54    grok.view(Manage)
     55    grok.require('waeup.manageUniversity')
     56   
     57    def update(self):
     58        self.form = getMultiAdapter((self.context, self.request),
     59                                    name='manageform')
     60        self.form.update_form()
     61        if self.request.method == 'POST':
     62            #app = get_application(self.context)
     63            #self.__parent__.redirect(self.__parent__.url(obj=app))
     64            pass
     65
     66    def render(self):
     67        result = self.form.render()
     68        try:
     69            # strip all except the form part...
     70            result = re.match('^.+\(<form[^\>]+>.*</form>).+$', result,
     71                              re.DOTALL).groups()[0]
     72        except:
     73            # except there is no such part...
     74            pass
     75        return result
     76        return self.form.render()
     77
     78   
     79   
    4780class Content(grok.Viewlet):
    4881    grok.viewletmanager(MainArea)
    4982    grok.context(IUniversity)
    50 
     83    grok.view(Index)
    5184
    5285class Edit(grok.EditForm):
    5386    grok.context(University)
    5487    grok.AutoFields(IUniversity)
     88
     89class ManageLink(grok.Viewlet):
     90    grok.viewletmanager(LeftSidebar)
     91    grok.context(IUniversity)
     92    grok.view(Index)
     93    grok.order(5)
     94    # This is so cool! This link is only displayed, when the user is
     95    # allowed to use it!
     96    grok.require('waeup.manageUniversity')
     97   
     98    def render(self):
     99        return u'<div class="portlet"><a href="manage">Settings</a></div>'
Note: See TracChangeset for help on using the changeset viewer.