Form patches
"Matt Schmidt" <[email protected]> Tue, 12 Sep 2006 14:12:27 -0400
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
Hi, I was checking in to changing the default logout render after reading the message from the 9th and I realized it was mostly pointless since handlers can only be attributed to buttons. So I decided to play with the form taglib and added some functionality to the submit tag. The basis for what I added was somewhat already there with the 'with' parameter. I changed this param to 'type', added an 'image' and 'link' type and let everything else to render the default button. I don't think changing the param name will harm anything, seeing as how it didn't really do anything before. Plus, 'with' will be a reserved keyword in python 2.6 from what I understand. The link type outputs a hidden field with the id, and some javascript to submit the form. I made a small change to the form_form tag in order to get and output the id of the form. The image type requires a patch to spyceCompile.py because of the way the html image-submit works. It's just a one liner to strip out '.x' from the handlerid. It'd probably be better to splice the string, but I didn't feel like it. That's all. I hope this is helpful for anyone. -- Matt http://sloat.liek.us/ ------------------------------------------------------------------------- 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 _______________________________________________ Spyce-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/spyce-users
spyceCompile.py.patch
(application/octet-stream, 647 B)
Index: spyceCompile.py
===================================================================
--- spyceCompile.py (revision 1177)
+++ spyceCompile.py (working copy)
@@ -428,6 +428,7 @@
self._ast.addCode("for _key in request.getpost():{")
self._ast.addCode(" if _key.startswith('_submit'):{")
self._ast.addCode(" _handlerid = _key[7:]")
+ self._ast.addCode(" _handlerid = _handlerid.replace('.x', '')")
self._ast.addCode(" if _handlerid in _handlers:{")
self._ast.addCode(" from spyceCompile import _evalWithImport")
self._ast.addCode(" for _handler in _handlers[_handlerid]:{")
form.py.patch
(application/octet-stream, 2.2 KB)
Index: form.py
===================================================================
--- form.py (revision 1177)
+++ form.py (working copy)
@@ -22,6 +22,7 @@
if self.getParent('form'):
raise 'Nested form tags are not allowed'
id = self._context['_current_form_id']
+ self.id = id
err = self._context.get('_validation_error', None)
if err and id in err:
invokeSingleton(self._api, spyceConfig.validation_render, err=err[id])
@@ -30,8 +31,8 @@
raise 'invalid method attribute value: '+method
if action is None:
action = self.getModule('request').uri_path()
- self.getOut().write('<form method="%s" action="%s"%s>' % (
- method, action, formatArgs(kwargs)) )
+ self.getOut().write('<form id="%s" method="%s" action="%s"%s>' % (
+ id, method, action, formatArgs(kwargs)) )
def end(self):
self.getOut().write('</form>')
@@ -40,22 +41,23 @@
handlers = {} # non-None so spyceCompile will handle handler attr
def syntax(self):
self.syntaxSingleOnly()
- def begin(self, with='button', **kwargs):
+ def begin(self, type='button', **kwargs):
self.parentRequired('form')
if 'name' in kwargs:
raise "invalid submit tag attribute 'name' (use handlers to set different actions for different submit buttons)"
id = '_submit' + self.getFullId()
- if with == 'button':
- html = '<input id="%s" name="%s" type="SUBMIT"%s>' % (id, id, formatArgs(kwargs),)
- else:
- # *** confirm needs work
- js = kwargs['onclick']
- js += '' # *** create hidden element w/ submit ID
+ if type == 'image':
+ html = '<input id="%s" name="%s" type="image"%s>' % (id, id, formatArgs(kwargs),)
+ elif type == 'link':
if 'value' in kwargs:
v = kwargs['value']
else:
v = 'Submit'
- html = '<a id="%s" href="" onclick="%s">%s</a>' % (id, js, v)
+ js = "document.getElementById('%s').submit()" % self.getParent('form').id
+ html = '<input type="hidden" id="%s" name="%s" value="submit"><a href="#" onclick="%s">%s</a>' % (id, id, js, v)
+ else:
+ html = '<input id="%s" name="%s" type="SUBMIT"%s>' % (id, id, formatArgs(kwargs),)
+
self.getOut().write(html)
class form_hidden(spyceTagPlus):