[Zope3-Users] keeping GET data in a formlib based form
    Lorenzo Gil Sánchez 
    lgs at sicem.biz
       
    Thu Mar 15 06:41:23 EDT 2007
    
    
  
Thanks for your input, Maciej.
El mié, 14-03-2007 a las 10:39 +0100, Maciej Wisniowski escribió:
> Maybe the simplest solution is to use session for storing this data,
> eg.:
> 
> in update you check if there is 'myarg' in request, and if so then
> put this into session. If there is no 'myarg' in request
> you get this from session.
> 
I also thought about this solution but I don't like it because I will
have clean up issues like: when do I remove 'myarg' from the session?
> If you want this passed via POST/GET then you may try with
> hidden() method of widgets, or write own widget that
> renders as a hidden input, like:
> 
> class EntryWidget(SimpleInputWidget):   
>    
>     def _toFieldValue(self, input):
>         return unicode(input)       
>    
>     def __call__(self):
>         return self.hidden()
> 
> and assign this widget to field that will represent 'myarg':
> 
> self.form_fields['myarg'].custom_widget=EntryWidget
> 
I like this way better
> You will possibly have to change the line:
> data = self.request['myarg']
> 
> because your input will have form prefix.
Or change 'myarg' argument to be 'form.myarg' and use an url like this:
http://localhost:8080/myapp/mycontent/myform?form.myarg=23
In the end I wrote another interface like this:
class IDialog(Interface)
  myarg = schema.TextLine(...)
then a class like:
class Dialog(object):
  implements(IDialog, IMyContent)
  def __init__(self, context, request):
    self.myarg = request['form.myarg']
    self.context = context
  # here I implement all attributes and methods of IMyContent
  # using delegation to self.context
And finally, my form:
class MyForm(form.BaseForm):
  form_fields = form.Fields(IDialog,
                            omit_readonly=False,
                            render_context=True)
    form_fields['myarg'].custom_widget = HiddenWidget
    def __init__(self, context, request):
        context = Dialog(context, request)
        super(MyForm, self).__init__(context, request)
An this worked well. The only part I think it's not optimal is the
reimplementation (by delegation) of IMyContent in my Dialog dialog.
Any thoughts?
Lorenzo
    
    
More information about the Zope3-users
mailing list