Changeset 78:c85ce41a75bc for wokkel/data_form.py
- Timestamp:
- Jan 5, 2010, 11:46:50 AM (13 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/data_form.py
r56 r78 1 1 # -*- test-case-name: wokkel.test.test_data_form -*- 2 2 # 3 # Copyright (c) 2003-20 09Ralph Meijer3 # Copyright (c) 2003-2010 Ralph Meijer 4 4 # See LICENSE for details. 5 5 … … 252 252 253 253 for value in self.values: 254 if self.fieldType == 'boolean':254 if isinstance(value, bool): 255 255 value = unicode(value).lower() 256 el if self.fieldType in ('jid-single', 'jid-multi'):257 value = value.full()256 else: 257 value = unicode(value) 258 258 259 259 field.addElement('value', content=value) … … 344 344 Data Form. 345 345 346 There are two similarly named properties of forms. The L{formType} is the346 There are two similarly named properties of forms. The C{formType} is the 347 347 the so-called type of the form, and is set as the C{'type'} attribute 348 348 on the form's root element. … … 352 352 special hidden field named C{'FORM_TYPE'}, to put the names of all 353 353 other fields in the namespace of the value of that field. This namespace 354 is recorded in the L{formNamespace} instance variable.354 is recorded in the C{formNamespace} instance variable. 355 355 356 356 @ivar formType: Type of form. One of C{'form'}, C{'submit'}, {'cancel'}, 357 357 or {'result'}. 358 @type formType: C{str}. 358 @type formType: C{str} 359 360 @ivar title: Natural language title of the form. 361 @type title: C{unicode} 362 363 @ivar instructions: Natural language instructions as a list of C{unicode} 364 strings without line breaks. 365 @type instructions: C{list} 366 359 367 @ivar formNamespace: The optional namespace of the field names for this 360 form. This goes in the special field named 361 C{'FORM_TYPE'}, if set. 368 form. This goes in the special field named C{'FORM_TYPE'}, if set. 362 369 @type formNamespace: C{str}. 363 @ivar fields: Dictionary of fields that have a name. Note that this is 364 meant to be used for reading, only. One should use 365 L{addField} for adding fields. 370 371 @ivar fields: Dictionary of named fields. Note that this is meant to be 372 used for reading, only. One should use L{addField} or L{makeFields} and 373 L{removeField} for adding and removing fields. 366 374 @type fields: C{dict} 375 376 @ivar fieldList: List of all fields, in the order they are added. Like 377 C{fields}, this is meant to be used for reading, only. 378 @type fieldList: C{list} 367 379 """ 368 380 … … 393 405 r.append(", formNamespace=") 394 406 r.append(repr(self.formNamespace)) 395 if self.field s:407 if self.fieldList: 396 408 r.append(", fields=") 397 409 r.append(repr(self.fieldList)) … … 425 437 426 438 for instruction in self.instructions: 427 form.addElement('instruction ', content=instruction)439 form.addElement('instructions', content=instruction) 428 440 429 441 if self.formNamespace is not None: … … 478 490 return form 479 491 492 480 493 def getValues(self): 494 """ 495 Extract values from the named form fields. 496 497 For all named fields, the corresponding value or values are 498 returned in a dictionary keyed by the field name. For multi-value 499 fields, the dictionary value is a list, otherwise a single value. 500 501 If a field has no type, and the field has multiple values, the value of 502 the dictionary entry is the list of values. Otherwise, it will be a 503 single value. 504 505 @rtype: C{dict} 506 """ 481 507 values = {} 482 508 483 509 for name, field in self.fields.iteritems(): 484 if len(field.values) > 1: 510 if (field.fieldType in ('jid-multi', 'list-multi', 'text-multi') or 511 (field.fieldType is None and len(field.values) > 1)): 485 512 value = field.values 486 513 else:
Note: See TracChangeset
for help on using the changeset viewer.