430 |
430 |
431 class CtxComponentsRegistry(CWRegistry): |
431 class CtxComponentsRegistry(CWRegistry): |
432 def poss_visible_objects(self, *args, **kwargs): |
432 def poss_visible_objects(self, *args, **kwargs): |
433 """return an ordered list of possible components""" |
433 """return an ordered list of possible components""" |
434 context = kwargs.pop('context') |
434 context = kwargs.pop('context') |
435 if kwargs.get('rset') is None: |
435 if '__cache' in kwargs: |
|
436 cache = kwargs.pop('__cache') |
|
437 elif kwargs.get('rset') is None: |
436 cache = args[0] |
438 cache = args[0] |
437 else: |
439 else: |
438 cache = kwargs['rset'] |
440 cache = kwargs['rset'] |
439 try: |
441 try: |
440 cached = cache.__components_cache |
442 cached = cache.__components_cache |
441 except AttributeError: |
443 except AttributeError: |
442 ctxcomps = super(CtxComponentsRegistry, self).poss_visible_objects( |
444 ctxcomps = super(CtxComponentsRegistry, self).poss_visible_objects( |
443 *args, **kwargs) |
445 *args, **kwargs) |
|
446 if cache is None: |
|
447 components = [] |
|
448 for component in ctxcomps: |
|
449 cctx = component.cw_propval('context') |
|
450 if cctx == context: |
|
451 component.cw_extra_kwargs['context'] = cctx |
|
452 components.append(component) |
|
453 return components |
444 cached = cache.__components_cache = {} |
454 cached = cache.__components_cache = {} |
445 for component in ctxcomps: |
455 for component in ctxcomps: |
446 cached.setdefault(component.cw_propval('context'), []).append(component) |
456 cctx = component.cw_propval('context') |
|
457 component.cw_extra_kwargs['context'] = cctx |
|
458 cached.setdefault(cctx, []).append(component) |
447 thisctxcomps = cached.get(context, ()) |
459 thisctxcomps = cached.get(context, ()) |
448 # XXX set context for bw compat (should now be taken by comp.render()) |
460 # XXX set context for bw compat (should now be taken by comp.render()) |
449 for component in thisctxcomps: |
461 for component in thisctxcomps: |
450 component.cw_extra_kwargs['context'] = context |
462 component.cw_extra_kwargs['context'] = context |
451 return thisctxcomps |
463 return thisctxcomps |