Changeset 277
- Timestamp:
- 01/19/07 12:27:07 (2 years ago)
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/examples.tac (modified) (1 diff)
- trunk/formal/__init__.py (modified) (1 diff)
- trunk/formal/examples/main.py (modified) (3 diffs)
- trunk/formal/examples/stanstyle.py (copied) (copied from branches/convenient-adding/formal/examples/stanstyle.py)
- trunk/formal/form.py (modified) (5 diffs)
- trunk/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r266 r277 1 2007-01-19 Matt Goodall <matt@pollenation.net> 2 3 Made construction of the form more convenient by adding addField and 4 addGroup methods to Form and Group as well as returning the added item. 5 6 I also added the ability to construct a Form in a stan-like way. See the 7 stanstyle example for details. 8 1 9 2006-11-30 Tim Parkin <tim@pollenation.net> 2 10 trunk/examples.tac
r196 r277 4 4 5 5 application = service.Application('examples') 6 service = internet.TCPServer(8000, main.makeSite( application))6 service = internet.TCPServer(8000, main.makeSite()) 7 7 service.setServiceParent(application) 8 8 trunk/formal/__init__.py
r266 r277 4 4 5 5 6 version_info = (0, 1 0, 0)6 version_info = (0, 11, 0) 7 7 version = '.'.join([str(i) for i in version_info]) 8 8 trunk/formal/examples/main.py
r256 r277 15 15 'formal.examples.prepopulate.PrepopulateFormPage', 16 16 'formal.examples.group.GroupFormPage', 17 'formal.examples.stanstyle.StanStyleFormPage', 17 18 'formal.examples.fileupload.FileUploadFormPage', 18 19 'formal.examples.smartupload.SmartUploadFormPage', … … 27 28 ] 28 29 29 def makeSite( application):30 def makeSite(): 30 31 root = RootPage() 31 site = appserver.NevowSite(root, logPath= 'web.log')32 site = appserver.NevowSite(root, logPath="web.log") 32 33 return site 33 34 … … 110 111 setattr(RootPage, 'child_formal.css', formal.defaultCSS) 111 112 setattr(RootPage, 'child_js', formal.formsJS) 113 114 if __name__ == '__main__': 115 116 import sys 117 from twisted.internet import reactor 118 from twisted.python import log 119 120 if len(sys.argv) > 1: 121 port = int(sys.argv[1]) 122 else: 123 port = 8000 124 125 log.startLogging(sys.stdout) 126 site = makeSite() 127 reactor.listenTCP(port, site) 128 reactor.run() 129 trunk/formal/form.py
r271 r277 237 237 238 238 239 class Group(object): 239 class AddHelperMixin(object): 240 """ 241 A mixin that provides methods for common uses of add(...). 242 """ 243 244 245 def addGroup(self, *a, **k): 246 return self.add(Group(*a, **k)) 247 248 249 def addField(self, *a, **k): 250 return self.add(Field(*a, **k)) 251 252 253 def __getitem__(self, items): 254 """ 255 Overridden to allow stan-style construction of forms. 256 """ 257 # Items may be a list or a scalar so stick a scalar into a list 258 # immediately to simplify the code. 259 try: 260 items = iter(items) 261 except TypeError: 262 items = [items] 263 # Add each item 264 for item in items: 265 self.add(item) 266 # Return myself 267 return self 268 269 270 class Group(AddHelperMixin, object): 240 271 241 272 … … 257 288 258 289 key = property(lambda self: itemKey(self)) 259 260 290 291 261 292 def setItemParent(self, itemParent): 262 293 self.itemParent = itemParent … … 314 345 315 346 316 class Form( object):347 class Form(AddHelperMixin, object): 317 348 318 349 implements( iformal.IForm ) … … 332 363 self.getItemByName = self.items.getItemByName 333 364 334 def addField(self, name, type, widgetFactory=None, label=None,335 description=None, cssClass=None):336 self.add(Field(name, type, widgetFactory, label, description, cssClass))337 365 338 366 def addAction(self, callback, name="submit", validate=True, label=None): … … 429 457 self.items.append(item) 430 458 item.setItemParent(self.itemParent) 459 return item 431 460 432 461 trunk/setup.py
r266 r277 3 3 setup( 4 4 name='formal', 5 version='0.1 0.0',5 version='0.11.0', 6 6 description='HTML forms framework for Nevow', 7 7 author='Matt Goodall',
