Changeset 4767 for waeup


Ignore:
Timestamp:
9 Jan 2010, 18:02:36 (15 years ago)
Author:
uli
Message:

Remove FormWrapMixin?. It is not used any more.

File:
1 edited

Legend:

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

    r4765 r4767  
    273273        # We cannot simply replace local sites.
    274274        self.can_import = not ISite.providedBy(self.context)
    275 
    276 class FormWrapMixin(object):
    277     """Mixin for viewlets that renders forms.
    278 
    279     XXX: Need tests for this.
    280    
    281     This is a mixin that provides some convenience features for
    282     viewlets that want to render forms, by overriding the default
    283     `render()` and `update()` methods.
    284 
    285     To create a viewlet that renders a form, you can define one as
    286     usual but also derive from this mixin-class.
    287 
    288     Say we have a usual form view like this::
    289 
    290       >>> import grok
    291       >>> class EditForm(grok.EditForm):
    292       ...   grok.context(SomeType)
    293       ...   grok.name('addsometype')
    294       ...   form_fields = grok.AutoFields(IUniversity)
    295       ...   @grok.action('Save')
    296       ...   def save(self, **data):
    297       ...     self.applyData(self.context, **data)
    298       ...     return
    299 
    300     then we can create a viewlet that displays this view like this::
    301      
    302       >>> import grok
    303       >>> from waeup.viewlets import FormWrapMixin
    304       >>> class EditFormViewlet(FormWrapMixin, grok.Viewlet):
    305       ...     grok.viewletmanager(MainArea)
    306       ...     grok.context(ISomeType)
    307       ...     grok.view(Manage)
    308       ...     formview_name = 'addsometype'
    309 
    310     Here we define a regular viewlet with two modifications:
    311 
    312     * it is also derived from `FormWrapMixin` and
    313 
    314     * it provides an attribute ``formview_name`` which tells us, what
    315       form we want to be rendered in this viewlet. We tell the name of
    316       this form and not its class or similar.
    317 
    318     The associated view, context, viewletmanager, etc. can be set as
    319     with regular viewlets.
    320    
    321     """
    322     formview_name = None
    323    
    324     def update(self):
    325         self.form = getMultiAdapter((self.context, self.request),
    326                                     name=self.formview_name)
    327         self.form.update_form()
    328 
    329     def render(self):
    330         html_code = self.form.render()
    331         return getInnerHTMLPart(html_code)
Note: See TracChangeset for help on using the changeset viewer.