Re: [Zope3-Users] keeping GET data in a formlib based form

2007-03-15 Thread Lorenzo Gil Sánchez
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

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] keeping GET data in a formlib based form

2007-03-14 Thread Maciej Wisniowski

 I need a way to keep 'myarg' information in my form for subsequent
 calls. Ideally I would like some mechanism that ends writing an input
 type=hidden id=myarg value=23/ tag in the html because that way
 my code:

 def update(self):
   [..]
   data = self.request['myarg']
   [..]

 will still work, right?

 I have thought about extending the formlib template to just do that or
 maybe adding a form.Field to my form with a special Widget associated to
 it. No idea of what's the best aproach.

 Anyone has pointer for this?
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.

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

You will possibly have to change the line:
data = self.request['myarg']

because your input will have form prefix.
I'm not sure, but you may have some issues with this solution
when doing resetForm etc.

-- 
Maciej Wisniowski

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users