Ticket #1718: template_params_1_1.patch

File template_params_1_1.patch, 4.0 kB (added by chrisz, 8 months ago)

Keep order of widget params and remove deprecated params (1.1 branch)

  • base.py

    old new  
    1010from cherrypy.config import configs 
    1111import tgmochikit 
    1212 
    13 try: 
    14     set 
    15 except NameError: 
    16     from sets import Set as set 
    17  
    1813__all__ = ["load_widgets", "all_widgets", "Widget", "CompoundWidget", 
    1914           "WidgetsList", "register_static_directory", 
    2015           "static", "Resource", "Link", "CSSLink", "JSLink", 
     
    224219    # there is rarely the need to override or extend them if inheritting 
    225220    # directly or indirectly from Widget. 
    226221 
    227     # update_data has been deprecated 
    228     update_data = update_params 
    229  
    230222    def __call__(self, *args, **params): 
    231223        """ 
    232224        Delegate to display. Used as an alias to avoid tiresome typing 
     
    269261        params["name"] = self.name 
    270262        params["value"] = to_unicode(self.adjust_value(value, **params)) 
    271263        self.update_params(params) 
    272         # update_data has been deprecated 
    273         self.update_data(params) 
    274264        try: 
    275265            transform = view.engines['kid'].transform 
    276266        except (KeyError, AttributeError): 
  • 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 
    10 try: 
    11     set 
    12 except NameError: 
    13     from sets import Set as set 
    14  
    1511__all__ = ["MetaWidget", "load_kid_template"] 
    1612 
    1713param_prefix = '_param_' 
    1814 
    1915class MetaWidget(type): 
    2016    def __new__(cls, name, bases, dct): 
    21         # update_data has been deprecated 
    22         if 'update_data' in dct and name != "Widget": 
    23             warnings.warn( 
    24                 "update_data has been renamed update_params, please " 
    25                 "rename your method. " 
    26                 "Note: this warning will be removed once 1.0 is " 
    27                 "released and your actual code will stop working.", 
    28                 DeprecationWarning, 2) 
    2917        # Makes sure we get the union of params and member_widgets 
    3018        # from all our bases. 
    31         params_set = set(dct.get('params', [])) 
    32         # template_vars has been deprecated 
    33         if 'template_vars' in dct: 
    34             params_set.update(dct['template_vars']) 
    35             warnings.warn( 
    36                 "Use of template_vars inside a widget is deprecated, " 
    37                 "use params instead. " 
    38                 "Note: this warning will be removed once 1.0 is " 
    39                 "released and your actual code will stop working.", 
    40                 DeprecationWarning, 2) 
    41         member_widgets_set = set(dct.get('member_widgets', [])) 
     19        params = setlike(dct.get('params', [])) 
     20        member_widgets = setlike(dct.get('member_widgets', [])) 
    4221        compound = False 
    4322        for base in bases: 
    44             params_set.update(getattr(base, 'params', [])) 
     23            params.add_all(getattr(base, 'params', [])) 
    4524            if getattr(base, 'compound', False): 
    46                 member_widgets_set.update(getattr(base, 'member_widgets', [])) 
     25                member_widgets.add_all(getattr(base, 'member_widgets', [])) 
    4726                compound = True 
    48         for param in params_set
     27        for param in params
    4928            # Swap all params listed at 'params' with a ParamDescriptor 
    5029            try: 
    5130                dct[param_prefix+param] = dct[param] 
     
    5332            except KeyError: 
    5433                # declared in a superclass, skip it... 
    5534                pass 
    56         dct['params'] = list(params_set) 
    57         #XXX: Remove when deprecation is effective 
    58         dct['template_vars'] = dct['params'] 
     35        params = list(params) 
     36        dct['params'] = params 
    5937        if compound: 
    60             dct['member_widgets'] = list(member_widgets_set
     38            dct['member_widgets'] = list(member_widgets
    6139        # Pick params_doc from all bases giving priority to the widget's own 
    6240        params_doc = {} 
    6341        for base in bases: