Ticket #1718: template_params_1_0.patch

File template_params_1_0.patch, 2.6 kB (added by chrisz, 5 months ago)

Keep order of widget params (1.0 branch)

  • meta.py

    old new  
    55from new import instancemethod 
    66from itertools import ifilter, count 
    77from turbogears import validators 
     8from turbogears.util import setlike 
    89from formencode.schema import Schema 
    910 
    1011try: 
    1112    set 
    12 except NameError: 
     13except NameError: # Python 2.3 
    1314    from sets import Set as set 
    1415 
    1516__all__ = ["MetaWidget", "load_kid_template"] 
     
    2829                DeprecationWarning, 2) 
    2930        # Makes sure we get the union of params and member_widgets 
    3031        # from all our bases. 
    31         params_set = set(dct.get('params', [])) 
     32        params = setlike(dct.get('params', [])) 
    3233        # template_vars has been deprecated 
    3334        if 'template_vars' in dct: 
    34             params_set.update(dct['template_vars']) 
     35            params.add_all(dct['template_vars']) 
    3536            warnings.warn( 
    3637                "Use of template_vars inside a widget is deprecated, " 
    3738                "use params instead. " 
    3839                "Note: this warning will be removed once 1.0 is " 
    3940                "released and your actual code will stop working.", 
    4041                DeprecationWarning, 2) 
    41         member_widgets_set = set(dct.get('member_widgets', [])) 
     42        member_widgets = setlike(dct.get('member_widgets', [])) 
    4243        compound = False 
    4344        for base in bases: 
    44             params_set.update(getattr(base, 'params', [])) 
     45            params.add_all(getattr(base, 'params', [])) 
    4546            if getattr(base, 'compound', False): 
    46                 member_widgets_set.update(getattr(base, 'member_widgets', [])) 
     47                member_widgets.add_all(getattr(base, 'member_widgets', [])) 
    4748                compound = True 
    48         for param in params_set
     49        for param in params
    4950            # Swap all params listed at 'params' with a ParamDescriptor 
    5051            try: 
    5152                dct[param_prefix+param] = dct[param] 
     
    5354            except KeyError: 
    5455                # declared in a superclass, skip it... 
    5556                pass 
    56         dct['params'] = list(params_set) 
     57        params = list(params) 
     58        dct['params'] = params 
    5759        #XXX: Remove when deprecation is effective 
    58         dct['template_vars'] = dct['params'] 
     60        dct['template_vars'] = params 
    5961        if compound: 
    60             dct['member_widgets'] = list(member_widgets_set
     62            dct['member_widgets'] = list(member_widgets
    6163        # Pick params_doc from all bases giving priority to the widget's own 
    6264        params_doc = {} 
    6365        for base in bases: