Warning:
Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.
Ticket #1718: template_params_1_1.patch
| File template_params_1_1.patch,
4.0 KB
(added by chrisz, 4 years ago) |
|
Keep order of widget params and remove deprecated params (1.1 branch)
|
-
|
|
|
|
| 10 | 10 | from cherrypy.config import configs |
| 11 | 11 | import tgmochikit |
| 12 | 12 | |
| 13 | | try: |
| 14 | | set |
| 15 | | except NameError: |
| 16 | | from sets import Set as set |
| 17 | | |
| 18 | 13 | __all__ = ["load_widgets", "all_widgets", "Widget", "CompoundWidget", |
| 19 | 14 | "WidgetsList", "register_static_directory", |
| 20 | 15 | "static", "Resource", "Link", "CSSLink", "JSLink", |
| … |
… |
|
| 224 | 219 | # there is rarely the need to override or extend them if inheritting |
| 225 | 220 | # directly or indirectly from Widget. |
| 226 | 221 | |
| 227 | | # update_data has been deprecated |
| 228 | | update_data = update_params |
| 229 | | |
| 230 | 222 | def __call__(self, *args, **params): |
| 231 | 223 | """ |
| 232 | 224 | Delegate to display. Used as an alias to avoid tiresome typing |
| … |
… |
|
| 269 | 261 | params["name"] = self.name |
| 270 | 262 | params["value"] = to_unicode(self.adjust_value(value, **params)) |
| 271 | 263 | self.update_params(params) |
| 272 | | # update_data has been deprecated |
| 273 | | self.update_data(params) |
| 274 | 264 | try: |
| 275 | 265 | transform = view.engines['kid'].transform |
| 276 | 266 | except (KeyError, AttributeError): |
-
|
|
|
|
| 5 | 5 | from new import instancemethod |
| 6 | 6 | from itertools import ifilter, count |
| 7 | 7 | from turbogears import validators |
| | 8 | from turbogears.util import setlike |
| 8 | 9 | from formencode.schema import Schema |
| 9 | 10 | |
| 10 | | try: |
| 11 | | set |
| 12 | | except NameError: |
| 13 | | from sets import Set as set |
| 14 | | |
| 15 | 11 | __all__ = ["MetaWidget", "load_kid_template"] |
| 16 | 12 | |
| 17 | 13 | param_prefix = '_param_' |
| 18 | 14 | |
| 19 | 15 | class MetaWidget(type): |
| 20 | 16 | 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) |
| 29 | 17 | # Makes sure we get the union of params and member_widgets |
| 30 | 18 | # 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', [])) |
| 42 | 21 | compound = False |
| 43 | 22 | for base in bases: |
| 44 | | params_set.update(getattr(base, 'params', [])) |
| | 23 | params.add_all(getattr(base, 'params', [])) |
| 45 | 24 | if getattr(base, 'compound', False): |
| 46 | | member_widgets_set.update(getattr(base, 'member_widgets', [])) |
| | 25 | member_widgets.add_all(getattr(base, 'member_widgets', [])) |
| 47 | 26 | compound = True |
| 48 | | for param in params_set: |
| | 27 | for param in params: |
| 49 | 28 | # Swap all params listed at 'params' with a ParamDescriptor |
| 50 | 29 | try: |
| 51 | 30 | dct[param_prefix+param] = dct[param] |
| … |
… |
|
| 53 | 32 | except KeyError: |
| 54 | 33 | # declared in a superclass, skip it... |
| 55 | 34 | 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 |
| 59 | 37 | if compound: |
| 60 | | dct['member_widgets'] = list(member_widgets_set) |
| | 38 | dct['member_widgets'] = list(member_widgets) |
| 61 | 39 | # Pick params_doc from all bases giving priority to the widget's own |
| 62 | 40 | params_doc = {} |
| 63 | 41 | for base in bases: |
Download in other formats: