Em Sexta 28 Abril 2006 16:53, Jorge Godoy escreveu:
>
> With the subclassing solution pointed out I'm happy.  It works for me. ;-)

I should really do more tests befores saying that things work.

(...)

> class Fields(TextField):
>     """
>     <basic doc>
>
>     Note that this requires that this class be wrapped inside a list to be
>     used with a form: [Fields()].
>     """
>     name = 'name'
>     option1 = ...
>
> So, I'm subclassing *and* documenting the use for this widget. :-)

The, I get this error while using it like this:

class WidgetsToSomething(widgets.WidgetsList)
    widget1 = ...
    widget2 = Fields()
    widget3 = ...


Traceback (most recent call last):
  File 
"/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py",
 
line 105, in _run
    self.main()
  File 
"/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py",
 
line 254, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in default
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py",
 
line 200, in expose
    output = database.run_with_transaction(func._expose,func, accept, 
allow_json, allow_json_from_config,*args, **kw)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/database.py", 
line 216, in run_with_transaction
    retval = func(*args, **kw)
  File "<string>", line 5, in _expose
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py",
 
line 219, in <lambda>
    func._expose.when(rule)(lambda _func, accept, allow_json, 
allow_json_from_config,*args,**kw: _execute_func(
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py",
 
line 240, in _execute_func
    output = errorhandling.try_call(func, *args, **kw)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/errorhandling.py",
 
line 68, in try_call
    return func(self, *args, **kw)
  File 
"/home/godoy/empresa/clientes/latam/Site-Amostras/siteamostras/controllers/equipamentos.py",
 
line 29, in default
    return self.equipamentos(args[0])
  File "<string>", line 3, in equipamentos
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py",
 
line 197, in expose
    output = func._expose(func, accept, allow_json, allow_json_from_config, 
*args, **kw)
  File "<string>", line 5, in _expose
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py",
 
line 219, in <lambda>
    func._expose.when(rule)(lambda _func, accept, allow_json, 
allow_json_from_config,*args,**kw: _execute_func(
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py",
 
line 250, in _execute_func
    return _process_output(output, template, format, content_type, mapping, 
fragment)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py",
 
line 56, in _process_output
    mapping=mapping, content_type=content_type,fragment=fragment)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/view/base.py", 
line 129, in render
    return turbogears.util.adapt_call(engine.render, **dict(info=info, 
format=format, fragment=fragment, template=template, mapping=mapping))
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/util.py", 
line 131, in adapt_call
    return func(*args, **kw)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/plugins/kid/turbokid/kidsupport.py",
 
line 156, in render
    return t.serialize(encoding=self.defaultencoding, output=format, 
fragment=fragment)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/__init__.py",
 
line 236, in serialize
    return serializer.serialize(self, encoding, fragment)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/serialization.py",
 
line 51, in serialize
    text = list(self.generate(stream, encoding, fragment))
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/serialization.py",
 
line 327, in generate
    for ev, item in self.apply_filters(stream):
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/serialization.py",
 
line 84, in balancing_filter
    for ev, item in stream:
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py",
 
line 206, in _coalesce
    for ev, item in stream:
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/filter.py",
 
line 21, in transform_filter
    for ev, item in apply_matches(stream, template, templates, apply_func):
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/filter.py",
 
line 31, in apply_matches
    item = stream.expand()
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py",
 
line 95, in expand
    for ev, item in self._iter:
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py",
 
line 164, in _track
    for p in stream:
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py",
 
line 206, in _coalesce
    for ev, item in stream:
  File 
"/home/godoy/empresa/clientes/latam/Site-Amostras/siteamostras/templates/form_generico.py",
 
line 150, in _pull
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/meta.py",
 
line 101, in lockwidget
    output = self.__class__.display(self, *args, **kw)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/base.py",
 
line 310, in display
    return super(CompoundWidget, self).display(value, **params)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/forms.py",
 
line 51, in _update_path
    returnval = func(self, *args, **kw)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/forms.py",
 
line 228, in display
    return super(InputWidget, self).display(value, **params)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/base.py",
 
line 239, in display
    return view.transform(params, template=self.template_c)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/view/base.py", 
line 134, in transform
    return engine.transform(info, template)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/plugins/kid/turbokid/kidsupport.py",
 
line 173, in transform
    return ElementStream(t.transform()).expand()
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py",
 
line 95, in expand
    for ev, item in self._iter:
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py",
 
line 164, in _track
    for p in stream:
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/filter.py",
 
line 21, in transform_filter
    for ev, item in apply_matches(stream, template, templates, apply_func):
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/filter.py",
 
line 25, in apply_matches
    for ev, item in stream:
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py",
 
line 164, in _track
    for p in stream:
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py",
 
line 206, in _coalesce
    for ev, item in stream:
  File "<string>", line 67, in _pull
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/meta.py",
 
line 101, in lockwidget
    output = self.__class__.display(self, *args, **kw)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/forms.py",
 
line 51, in _update_path
    returnval = func(self, *args, **kw)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/forms.py",
 
line 228, in display
    return super(InputWidget, self).display(value, **params)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/base.py",
 
line 236, in display
    self.update_params(params)
  File 
"/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/forms.py",
 
line 684, in update_params
    for i, option in enumerate(d["options"]):
TypeError: iteration over non-sequence



Putting Fields inside a list -- [Fields()] -- makes the widget disappear as 
well as the error, so it doesn't work either.  The same happens if I don't 
instantiate the class...

So I believe that what I want is not possible, unfortunately...  I'll put the 
code back and live with it :-(


My real "class" is:

class WidgetsSelecaoFornecedores(widgets.SingleSelectField):
    """
    Widget para a seleção de um fornecedor dentre os fornecedores
    cadastrados e ativos.

    Reparar que esta invocação deve ser colocada dentro de uma lista --
    [WidgetsSelecaoFornecedores()] -- pois estou fazendo uma subclasse do
    widget para permitir seu reuso em outros contextos.
    """
    name = 'fornecedor'
    label = _('Fornecedor')
    css_classes = ['required']
    options = fornecedores
    validator = validators.Int(not_empty = True)


Thanks and don't worry with this...  It is bringing more troubles than it 
should.  But we at least know that none of the approaches worked.



-- 
Jorge Godoy      <[EMAIL PROTECTED]>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk
-~----------~----~----~----~------~----~------~--~---

Reply via email to