Changeset 5380 for main


Ignore:
Timestamp:
7 Aug 2010, 14:03:41 (14 years ago)
Author:
uli
Message:

Change viewlets for links in upper-left box:

  • All respective viewlets defined in here now are displayed on every page, not only the homepage. To do this we changed the context and view each of the viewlets is bound to to IWAeUPObject and WAeUPPage. That means, that these links are displayed on all views that derive from WAeUPPage and whose context is of type IWAeUPObject or derived.
  • Turned ManageLink into a reusable base class for other viewlets of that kind. This made the other changed viewlets much shorter and now we only have to change one line of HTML code (the ManageLink.render() method) when we wish to change the HTML displayed by all these links.
  • In order to make the ManageLink base class reusable, there are now two attributes, deriving classes should set: text and link which tell how the link to create in the upper left box should look like.
  • Documented the viewlets with docstrings.
File:
1 edited

Legend:

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

    r5152 r5380  
    1515from waeup.sirp.interfaces import (IWAeUPObject, IWAeUPXMLExporter,
    1616                                   IWAeUPXMLImporter, IDataCenter)
     17from waeup.sirp.browser.layout import WAeUPPage
    1718
    1819grok.templatedir('templates')
     
    226227
    227228class ManageLink(grok.Viewlet):
     229    """A link displayed in the upper left box.
     230
     231    This viewlet renders a link to the application object's settings
     232    form (the 'manage' view).
     233
     234    In derived classes you can create different links by setting a
     235    different link and text attribute. The `link` parameter is
     236    understood relative to the respective application object, so that
     237    ``@@manage`` will create a link to
     238    ``localhost:8080/app/@@manage``.
     239
     240    Links defined by descendants from this viewlet are displayed on
     241    every page the user is allowed to go to, if the user has also the
     242    permissions set by `grok.require()`. By default only users with
     243    ``waeup.manageUniversity`` permission will see links defined by
     244    this or derivated classes.
     245    """
    228246    grok.viewletmanager(LeftSidebar)
    229     grok.context(IUniversity)
    230     grok.view(UniversityPage)
     247    grok.context(IWAeUPObject)
     248    grok.view(WAeUPPage)
    231249    grok.order(5)
    232250    # This link is only displayed, if the user is
    233251    # allowed to use it!
    234252    grok.require('waeup.manageUniversity')
     253
     254    link = '@@manage'
     255    text = u'Portal Settings'
    235256   
    236257    def render(self):
    237         return u'<div class="portlet"><a href="manage">Settings</a></div>'
     258        url = self.view.url(grok.getSite(), self.link)
     259        return u'<div class="portlet"><a href="%s">%s</a></div>' % (
     260                url, self.text)
     261
    238262
    239263class ManageFacultiesLink(grok.Viewlet):
     
    245269    # allowed to use it!
    246270    grok.require('waeup.manageUniversity')
    247    
     271
    248272    def render(self):
    249273        return u'<div class="portlet"><a href="faculties">Manage faculties</a></div>'
    250274
    251 class ManageUsersLink(grok.Viewlet):
    252     grok.viewletmanager(LeftSidebar)
    253     grok.context(IUniversity)
    254     grok.view(UniversityPage)
     275class ManageUsersLink(ManageLink):
     276    """A link to users management, placed in upper left box.
     277    """
    255278    grok.order(6)
    256279    grok.require('waeup.manageUsers')
    257280
    258     def render(self):
    259         return u'<div class="portlet"><a href="users">Manage users</a></div>'
    260 
    261 class ManageDataCenter(grok.Viewlet):
    262     grok.viewletmanager(LeftSidebar)
    263     grok.context(IUniversity)
    264     grok.view(UniversityPage)
     281    link = u'users'
     282    text = u'Portal Users'
     283
     284class ManageDataCenter(ManageLink):
     285    """A link to datacenter, placed in upper left box.
     286    """
    265287    grok.order(6)
    266288    grok.require('waeup.manageUniversity')
    267289
    268     def render(self):
    269         return u'<div class="portlet"><a href="datacenter">Data Center</a></div>'
     290    link = u'datacenter'
     291    text = u'Data Center'
    270292
    271293#
Note: See TracChangeset for help on using the changeset viewer.