Changeset 5914
- Timestamp:
- 5 Apr 2011, 19:57:39 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/browser/viewlets.py
r5472 r5914 332 332 # Add actions... 333 333 # 334 class AddAction(grok.Viewlet):335 """Base class for 'adding actions'.336 337 AddActions are viewlets that render a button linked to an adding338 page. To create such a button in one of your pages, follow the339 following steps:340 341 - Create a new class derived from AddAction. In this class:342 343 - Set a grok.context() for the context type of your page. So, if344 your page sets grok.context(IMyFunnyType), do the same in the345 viewlet class.346 347 - Set the Page on which the button should appear using348 grok.view(). So, if your page class is MyFunnyPage, do349 grok.view(MyFunnyPage).350 351 - Set the template to use to 'addaction'. This means to use the352 'addaction.pt' template in the templates/ dir. Don't fiddle353 around with this template file, as it is used also by other354 viewlets.355 356 - If you want only certain authorized users to see the button, use357 grok.require(<Permission>). By default only people with358 waeup.manageUniversity permission are able to see your new359 button. Other users, however, will still see your page, only360 without the button rendered.361 362 - As one can define several buttons for a certain page, you can363 influence the order of buttons by setting grok.order(<num>). The364 lower the number, the more left the button will be displayed and365 vice versa. Default is 4.366 367 - Set the page name as ``addview_name`` attribute. This means, if368 the page, the button is linked to can be reached by calling369 http://localhost:8080/<current_location>/@@addfoo, then you should set::370 371 addview_name = 'addfoo'372 373 By default the target page name 'add' is assumed. You should374 have good reasons not to name your AddFormPage 'add'.375 376 - Set the button text by setting the ``addlink_text``377 attribute. If you set it to 'Add foobar', then on the page will378 appear a button with a small 'add stuff' icon and the text 'Add379 foobar'.380 """381 grok.viewletmanager(ActionBar)382 grok.view(FacultyContainerPage)383 grok.context(IFacultyContainer)384 grok.order(4)385 grok.template('addaction')386 grok.require('waeup.manageUniversity')387 grok.baseclass()388 389 addview_name = 'add'390 addlink_text = 'Add department'391 392 def getTargetURL(self):393 return '%s/@@%s' % (self.view.url(self.view.context), self.addview_name)394 334 395 335 class AddFacultyActionButton(AddActionButton): … … 550 490 551 491 @property 492 def active(self): 493 view_pnav = getattr(self.view, 'pnav', 0) 494 userid = self.request.principal.id 495 if view_pnav == self.pnav and userid == 'zope.anybody': 496 return 'active' 497 return '' 498 499 @property 552 500 def link_target(self): 553 501 return self.view.application_url('contactadmin')
Note: See TracChangeset for help on using the changeset viewer.