Django

Code

Ticket #2899 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

[patch] data and error_dict should have defaults in django.forms.FormWrapper

Reported by: john@sneeu.com Assigned to: adrian
Milestone: Component: Tools
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

In some occations it is useful for data and error_dict to have defaults in django.forms.FormWrapper.

Attachments

formwrapper_defaults.diff (0.7 kB) - added by john@sneeu.com on 10/11/06 09:29:06.
Patch for ticket #2899
formwrapper_defaults.2.diff (0.8 kB) - added by john@sneeu.com on 10/12/06 08:29:00.
New version of [patch] with changes suggested by adurdin

Change History

10/11/06 09:29:06 changed by john@sneeu.com

  • attachment formwrapper_defaults.diff added.

Patch for ticket #2899

10/11/06 12:22:22 changed by adurdin@gmail.com

There's a problem with the patch, John: in Python, default values for parameters are evaluated when the function is created, not when it is executed. Your patch will result in all FormWrappers? sharing the same default dictionaries. You should change it to something like:

def __init__(self, manipulator, data=None, error_dict=None, edit_inline=True): 
    self.manipulator, self.data = manipulator, (data or {})
    self.error_dict = error_dict or {}

10/12/06 08:29:00 changed by john@sneeu.com

  • attachment formwrapper_defaults.2.diff added.

New version of [patch] with changes suggested by adurdin

11/06/06 14:12:01 changed by Bastian Kleineidam <calvin@debian.org>

The a or b thingy in Python is not good for default arguments. If you supply an empty dictionary as argument, it will be replaced silently with another object by the arg or {} expression. The failsafe approach is to manually test for None:

def f (arg=None):
    if arg is None:
        arg = {}

11/06/06 16:56:24 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

(In [4029]) Fixed #2899: added defaults for data and error_dict params to FormWrapper?. Thanks, john@sneeu.com.


Add/Change #2899 ([patch] data and error_dict should have defaults in django.forms.FormWrapper)




Change Properties
Action