Changeset 5580 for django/branches/unicode/django/newforms
- Timestamp:
- 07/01/07 00:55:01 (2 years ago)
- Files:
-
- django/branches/unicode (modified) (1 prop)
- django/branches/unicode/django/newforms/fields.py (modified) (2 diffs)
- django/branches/unicode/django/newforms/widgets.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/unicode
- Property svnmerge-integrated changed from /django/trunk:1-5530 to /django/trunk:1-5579
django/branches/unicode/django/newforms/fields.py
r5531 r5580 483 483 class MultiValueField(Field): 484 484 """ 485 A Field that is composed of multiple Fields. 486 487 Its clean() method takes a "decompressed" list of values. Each value in 485 A Field that aggregates the logic of multiple Fields. 486 487 Its clean() method takes a "decompressed" list of values, which are then 488 cleaned into a single value according to self.fields. Each value in 488 489 this list is cleaned by the corresponding field -- the first value is 489 490 cleaned by the first field, the second value is cleaned by the second … … 491 492 "compressed" into a single value. 492 493 493 Subclasses should implement compress(), which specifies how a list of494 valid values should be converted to a single value. Subclasses should not495 have to implement clean().494 Subclasses should not have to implement clean(). Instead, they must 495 implement compress(), which takes a list of valid values and returns a 496 "compressed" version of those values -- a single value. 496 497 497 498 You'll probably want to use this with MultiWidget. django/branches/unicode/django/newforms/widgets.py
r5531 r5580 305 305 A widget that is composed of multiple widgets. 306 306 307 Its render() method takes a "decompressed" list of values, not a single 308 value. Each value in this list is rendered in the corresponding widget -- 309 the first value is rendered in the first widget, the second value is 310 rendered in the second widget, etc. 311 312 Subclasses should implement decompress(), which specifies how a single 313 value should be converted to a list of values. Subclasses should not 314 have to implement clean(). 307 Its render() method is different than other widgets', because it has to 308 figure out how to split a single value for display in multiple widgets. 309 The ``value`` argument can be one of two things: 310 311 * A list. 312 * A normal value (e.g., a string) that has been "compressed" from 313 a list of values. 314 315 In the second case -- i.e., if the value is NOT a list -- render() will 316 first "decompress" the value into a list before rendering it. It does so by 317 calling the decompress() method, which MultiWidget subclasses must 318 implement. This method takes a single "compressed" value and returns a 319 list. 320 321 When render() does its HTML rendering, each value in the list is rendered 322 with the corresponding widget -- the first value is rendered in the first 323 widget, the second value is rendered in the second widget, etc. 315 324 316 325 Subclasses may implement format_output(), which takes the list of rendered 317 widgets and returns HTML that formats them any way you'd like.318 319 You'll probably want to use this with MultiValueField.326 widgets and returns a string of HTML that formats them any way you'd like. 327 328 You'll probably want to use this class with MultiValueField. 320 329 """ 321 330 def __init__(self, widgets, attrs=None): … … 352 361 353 362 def format_output(self, rendered_widgets): 363 """ 364 Given a list of rendered widgets (as strings), returns a Unicode string 365 representing the HTML for the whole lot. 366 367 This hook allows you to format the HTML design of the widgets, if 368 needed. 369 """ 354 370 return u''.join(rendered_widgets) 355 371
