Changeset 4651


Ignore:
Timestamp:
3 Jan 2010, 21:17:12 (15 years ago)
Author:
uli
Message:

Add an AddAction? baseclass and an AddAction? to add faculties.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-layout/src/waeup/browser/viewlets.py

    r4640 r4651  
    9898    grok.view(FacultyContainerPage)
    9999    grok.template('manageaction')
     100
     101
     102#
     103# Add actions...
     104#
     105class AddAction(grok.Viewlet):
     106    """Base class for 'adding actions'.
     107
     108    AddActions are viewlets that render a button linked to an adding
     109    page. To create such a button in one of your pages, follow the
     110    following steps:
     111
     112    - Create a new class derived from AddAction. In this class:
     113   
     114    - Set a grok.context() for the context type of your page. So, if
     115      your page sets grok.context(IMyFunnyType), do the same in the
     116      viewlet class.
     117
     118    - Set the Page on which the button should appear using
     119      grok.view(). So, if your page class is MyFunnyPage, do
     120      grok.view(MyFunnyPage).
     121
     122    - Set the template to use to 'addaction'. This means to use the
     123      'addaction.pt' template in the templates/ dir. Don't fiddle
     124      around with this template file, as it is used also by other
     125      viewlets.
     126
     127    - If you want only certain authorized users to see the button, use
     128      grok.require(<Permission>). By default only people with
     129      waeup.manageUniversity permission are able to see your new
     130      button. Other users, however, will still see your page, only
     131      without the button rendered.
     132
     133    - As one can define several buttons for a certain page, you can
     134      influence the order of buttons by setting grok.order(<num>). The
     135      lower the number, the more left the button will be displayed and
     136      vice versa. Default is 4.
     137     
     138    - Set the page name as ``addview_name`` attribute. This means, if
     139      the page, the button is linked to can be reached by calling
     140      http://localhost:8080/<current_location>/@@addfoo, then you should set::
     141
     142        addview_name = 'addfoo'
     143
     144      By default the target page name 'add' is assumed. You should
     145      have good reasons not to name your AddFormPage 'add'.
     146
     147    - Set the button text by setting the ``addlink_text``
     148      attribute. If you set it to 'Add foobar', then on the page will
     149      appear a button with a small 'add stuff' icon and the text 'Add
     150      foobar'.
     151    """
     152    grok.viewletmanager(ActionBar)
     153    grok.view(FacultyContainerPage)
     154    grok.context(IFacultyContainer)
     155    grok.order(4)
     156    grok.template('addaction')
     157    grok.require('waeup.manageUniversity')
     158    grok.baseclass()
     159
     160    addview_name = 'add'
     161    addlink_text = 'Add department'
     162
     163    def getTargetURL(self):
     164        return '%s/@@%s' % (self.view.url(self.view.context), self.addview_name)
     165
     166class AddFacultiesAction(AddAction):
     167    grok.context(IFacultyContainer)
     168    grok.view(FacultyContainerPage)
     169    grok.order(4)
     170    grok.template('addaction')
     171    grok.require('waeup.manageUniversity')
     172
     173    addview_name = 'add'
     174    addlink_text = 'Add faculty'
     175
Note: See TracChangeset for help on using the changeset viewer.