[Twisted-Python] InputImage, ImageHandler -- Woven [PATCH]
A widget and an InputHandler to better support <input type="image" ../> in Woven. I'm not too happy with the Widget, as it requires the src="" to be set in the template. But, FWIW, here's the patch. pax et amor, jml Index: twisted/web/woven/input.py =================================================================== RCS file: /cvs/Twisted/twisted/web/woven/input.py,v retrieving revision 1.4 diff -u -r1.4 input.py --- twisted/web/woven/input.py 28 Sep 2002 03:45:45 -0000 1.4 +++ twisted/web/woven/input.py 28 Sep 2002 06:00:05 -0000 @@ -174,6 +174,30 @@ ListHandler = List +class ImageHandler(InputHandler): + def getInput(self, request): + x, y = (request.args.get(self.submodel + '.x', None), + request.args.get(self.submodel + '.y', None)) + if(x != None and y != None): + return x[0], y[0] + else: + return None + + def check(self, request, data): + if data is None: return None + if len(data) != 2: return () + try: + int(data[0]) + int(data[1]) + return 1 + except (TypeError, ValueError): + return 0 + + def handleInvalid(self, request, data): + if data is not None: + self.view.setError(request, "%s is not a valid coordinate." % str(data)) + + class NewObject(SingleValue): """ Check to see if the name the user entered is valid. Index: twisted/web/woven/widgets.py =================================================================== RCS file: /cvs/Twisted/twisted/web/woven/widgets.py,v retrieving revision 1.15 diff -u -r1.15 widgets.py --- twisted/web/woven/widgets.py 28 Sep 2002 03:45:45 -0000 1.15 +++ twisted/web/woven/widgets.py 28 Sep 2002 06:00:07 -0000 @@ -369,6 +369,12 @@ self.add(Text(self.getData())) return Input.generateDOM(self, request, node) +class InputImage(Input): + def initialize(self): + self['type'] = 'image' + def generateDOM(self, request, node): + return Widget.generateDOM(self, request, node) + class Anchor(Widget): tagName = 'a' def initialize(self):
participants (1)
-
Jonathan Lange