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 #978 (closed defect: fixed)

Opened 11 years ago

Last modified 8 years ago

Callable not resolved at request time in Forms API

Reported by: samuraisam Owned by:
Priority: high Milestone: 1.x
Component: TG Widgets Version: 0.9a6
Severity: blocker Keywords: identity, forms, widgets tosplit
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

comment:1 Changed 11 years ago by samuraisam

  • Owner changed from anonymous to samuraisam
  • Status changed from new to assigned

comment:2 Changed 11 years ago by samuraisam

  • Status changed from assigned to new
  • Owner samuraisam deleted

comment:3 Changed 11 years ago by samuraisam

  • Component changed from Deployment to Widgets

comment:4 Changed 11 years ago 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.

comment:5 Changed 11 years ago by guest

  • Status changed from closed to reopened
  • Resolution wontfix deleted

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

comment:6 Changed 10 years ago by alberto

  • Milestone changed from 1.0 to 1.1

comment:7 Changed 10 years ago by alberto

  • Milestone changed from 1.1 to __unclassified__

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

comment:8 Changed 8 years ago by jorge.vargas

  • Keywords tosplit added

comment:9 Changed 8 years ago by jorge.vargas

  • Milestone changed from __unclassified__ to 1.x

comment:10 Changed 8 years ago by chrisz

  • Status changed from reopened to closed
  • Resolution set to fixed

Verified with the current version of TG that this only happens when no validator is explicitly specified as suggested in comment:4. Also improved the error message in this case as suggested in comment:5 (r6195). So I think we can finally close this.

Note: See TracTickets for help on using tickets.