Ticket #978 (reopened defect)

Opened 2 years ago

Last modified 7 months ago

Callable not resolved at request time in Forms API

Reported by: samuraisam Assigned to:
Priority: high Milestone: __unclassified__
Component: Widgets Version: 0.9a6
Severity: blocker Keywords: identity, forms, widgets
Cc:

Description

From the mailing list:

I have a form:

class X(widgets.WidgetsList):
    blog = widgets.SingleSelectField(label="Blog", options=get_blogs)

with a function:

def get_blogs():
    return [(blog.id, blog.title)
                for blog in identity.current.identity().user.blogs]

and as seen in this (unresolved) thread:
http://groups.google.com/group/turbogears/browse_thread/thread/b1c764...
it is impossible (or at least to the best of my knowledge) to access
identity when a form is created because, again, to the best of my
knowledge and from the errors TurboGears is giving me, that happens
outside of a request. Specifically:

turbogears.identity.exceptions.RequestRequiredException: An attempt was
made to use a facility of the TurboGears Identity Management framework
that relies on an HTTP request outside of a request.

What I need is a way to make it so I can dynamically add options to
X.blog from /within/ a request. I imagine I can do this by
manipulationg the TableForm object it's placed into, but even that is
created /outside/ of a request. So, still, I need to create options my
SingleSelectField on the fly from wthin the action. How, though? I have
gotten this far:

def action(self, tg_errors=None, *args, **kw):
    my_form.fields.append(my_dymanically_generated_SingleSelectField)

But then, why even use the forms api? I have to roll my own validation
for that and other fields that are generated depending on the user
accessing the action. If someone could please look at my problem, I'd
be very greatful.

Thanks,
-Sam 

I was told to submit a ticket for this, here it is. If you need any more information catch me on #turbogears or respond to the list thread.

Thanks, -Sam

Change History

06/20/06 12:11:28 changed by samuraisam

  • owner changed from anonymous to samuraisam.
  • status changed from new to assigned.

06/20/06 12:11:44 changed by samuraisam

  • owner deleted.
  • status changed from assigned to new.

06/20/06 12:14:26 changed by samuraisam

  • component changed from Deployment to Widgets.

12/05/06 04:24:33 changed by guest

  • status changed from new to closed.
  • resolution set to wontfix.

Just add a validator to your selection widget declaration:

widgets.SingleSelectField(label="Blog", options=get_blogs, validator=validators.Int())

and you'll be fine.

12/05/06 04:35:54 changed by guest

  • status changed from closed to reopened.
  • resolution deleted.

Perhaps a better message in the exception is needed in this case.

01/12/07 06:27:54 changed by alberto

  • milestone changed from 1.0 to 1.1.

03/28/07 12:42:01 changed by alberto

  • milestone changed from 1.1 to __unclassified__.

Batch moved into unclassified from 1.1 to properly track progress on the later