Custom postback data handler for widgets

Mikko Ohtamaa <mikko-75aZqqp77KCaMPzRcYMCawC/[email protected]>
Newsgroups gmane.comp.web.zope.plone.archetypes.devel
Organization Red Innovation
Message-ID <[email protected]>
Archetypes has hardcoded postback data saving for widgets in 
session_save_form.py. This is very no no, since custom widgets cannot 
handle their postback data themselves. KeywordWidgets is hardcoded to 
session_save_form.py.

Please, could someone check this patch and commit it to AT SVN. Unit tests 
are included (test_postback.py).

I added ticket + diff fix to AT Trac: 
http://dev.plone.org/archetypes/ticket/654

* Adds savePostbackData method to Widgets

* Modifies TypesWidget? to handle general postback

* Modifies KeyWordWidget? to handle its custom types

* Unit tests for former

---

Current implementation (Archetypes/skins/session_save_form.py:

REQUEST = context.REQUEST

# hey, don't forget to increment object number for sessions
form_data = {'HTTP_REFERER':REQUEST.get('last_referer', None)}
to_store = [f for f in context.Schema().values() if f.type != 'computed']

for field in to_store:
     fieldname = field.getName()
     if field.widget.getName() == 'KeywordWidget':
         fieldname = '%s_keywords' % field.getName()
         data = []
         if REQUEST.has_key(fieldname):
             data += REQUEST.get(fieldname)
         fieldname = '%s_existing_keywords' % field.getName()
         if REQUEST.has_key(fieldname):
             data += REQUEST.get(fieldname)
         form_data[field.getName()] = data
     else:
         if REQUEST.has_key(fieldname):
             form_data[fieldname] = REQUEST.get(fieldname)

# XXX Implicitly creating a session for user.
REQUEST.SESSION.set(context.getId(), form_data)

---

Suggested implemenation (see diff for more details):

REQUEST = context.REQUEST

# hey, don't forget to increment object number for sessions
form_data = {'HTTP_REFERER':REQUEST.get('last_referer', None)}
to_store = [f for f in context.Schema().values() if f.type != 'computed']

for field in to_store:
     # Use widget postback handler to carry data
     field.widget.savePostbackData(REQUEST, context, field, form_data)

# XXX Implicitly creating a session for user.
REQUEST.SESSION.set(context.getId(), form_data)




-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.