Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Re-usable form
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Diego Woitasen  
View profile  
 More options May 25 2009, 9:28 pm
From: "Diego Woitasen" <dieg...@xtech.com.ar>
Date: Mon, 25 May 2009 22:28:14 -0300 (ART)
Local: Mon, May 25 2009 9:28 pm
Subject: Re-usable form
Hi,
 I want to write a reusable form using TableForm as base class. I tried
with this:

class RuleForm(TableForm):
  def __init__(self, id=None, parent=None, children=[], host_filter=[],
**kw):
    super(RuleForm, self).__init__(id,parent,children, **kw)
    self.fields = [
        TextField(id = 'description', label = 'Description'),
    ]

and this:

class RuleForm(TableForm):
  def __init__(self, id=None, parent=None, children=[], host_filter=[],
**kw):
    children = [
        TextField(id = 'description', label = 'Description'),
    ]
    super(RuleForm, self).__init__(id,parent,children, **kw)

without sucess.

What it the recommended way to write a reusable form. The complete form
will have some select fields that changes in each use of the forms.

regards,
 Diego

--
Diego Woitasen
XTECH - Soluciones Linux para empresas
(54) 011 5219-0678


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diez B. Roggisch  
View profile  
 More options May 26 2009, 5:50 am
From: "Diez B. Roggisch" <de...@web.de>
Date: Tue, 26 May 2009 11:50:40 +0200
Local: Tues, May 26 2009 5:50 am
Subject: Re: [TurboGears] Re-usable form
On Tuesday 26 May 2009 03:28:14 Diego Woitasen wrote:

What does "without success" mean? You are aware, that in the latter example
you simply override whatever children are passed?

Besides, the simple problem of yours seems to be solvable using

common_widgets = [...] # list of widgets

some_form = Form(children = common_widgets + some_other_widgets]

Diez


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diego Woitasen  
View profile  
 More options May 26 2009, 10:04 am
From: "Diego Woitasen" <dieg...@xtech.com.ar>
Date: Tue, 26 May 2009 11:04:09 -0300 (ART)
Local: Tues, May 26 2009 10:04 am
Subject: Re: [TurboGears] Re: Re-usable form

Means, it doesn't work. If I use fields outside the constructor works, for
example:

class RuleForm(TableForm):
  fields = [
    TextField(id = 'description', label = 'Description'),
  ]

  def __init__(self, id=None, parent=None, children=[], host_filter=[],
**kw):
    super(RuleForm, self).__init__(id,parent,children, **kw)

That works, but I need fields inside the constructor because I want to use
SelectionList or CheckboxList which contents could change in each use of
RuleForm (quering data from database).

I could use a function that returns the children field list and use them
like you said but I prefer to use classes or at least understand why my
approach doesn't work.

Regards,
  Diego

--
Diego Woitasen
XTECH - Soluciones Linux para empresas
(54) 011 5219-0678


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diez B. Roggisch  
View profile  
 More options May 26 2009, 10:45 am
From: "Diez B. Roggisch" <de...@web.de>
Date: Tue, 26 May 2009 16:45:00 +0200
Subject: Re: [TurboGears] Re: Re-usable form
On Tuesday 26 May 2009 16:04:09 Diego Woitasen wrote:

"doesn't" work means nothing. If that's all you can give as an
error-description, all you can get as answer is "then do it differently".

Does it throw an exception? Don't the fields appear? If yes, none of them,
onle the super-classes one, only the subclasses one?

Diez


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diez B. Roggisch  
View profile  
 More options May 26 2009, 10:49 am
From: "Diez B. Roggisch" <de...@web.de>
Date: Tue, 26 May 2009 16:49:46 +0200
Local: Tues, May 26 2009 10:49 am
Subject: Re: [TurboGears] Re: Re-usable form
On Tuesday 26 May 2009 16:04:09 Diego Woitasen wrote:

This is not intended to work. ToscaWidgets are instantiated once, and re-used.

To make selectfields display varying values, use a callable as
options-parameter.

def get_options():
      return some_options

class MyForm(TableForm):
       class fields(WidgetList):
               select_field = SingleSelectField(options=get_options)

Diez


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diego Woitasen  
View profile  
 More options May 26 2009, 1:54 pm
From: "Diego Woitasen" <dieg...@xtech.com.ar>
Date: Tue, 26 May 2009 14:54:57 -0300 (ART)
Local: Tues, May 26 2009 1:54 pm
Subject: Re: [TurboGears] Re: Re-usable form

ok, ok... sorry...

The fields don't appear, none of them, only the submit button.

--
Diego Woitasen
XTECH - Soluciones Linux para empresas
(54) 011 5219-0678


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diego Woitasen  
View profile  
 More options May 26 2009, 2:41 pm
From: "Diego Woitasen" <dieg...@xtech.com.ar>
Date: Tue, 26 May 2009 15:41:15 -0300 (ART)
Local: Tues, May 26 2009 2:41 pm
Subject: Re: [TurboGears] Re: Re-usable form

I got "TypeError: 'function' object is not iterable".

Anyway, I don't like that approach. What if a want to pass parameters to
get_options()? I want to pass a SQLAlchemy query when the form is
instantiated to condition the data to be returned i select fields.

I think the solution at the moment is to write a function that return all
childrens to pass to my form but I don't like it.

I'm using TG2 RC1.

--
Diego Woitasen
XTECH - Soluciones Linux para empresas
(54) 011 5219-0678


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diez B. Roggisch  
View profile  
 More options May 26 2009, 4:57 pm
From: "Diez B. Roggisch" <de...@web.de>
Date: Tue, 26 May 2009 22:57:33 +0200
Local: Tues, May 26 2009 4:57 pm
Subject: Re: [TurboGears] Re: Re-usable form
Diego Woitasen schrieb:

Full stacktrace please, and code.... crystal-ball time is over for this
month.

This works in our codebase, so the problem must be on your side:

def get_users():
     """
     This function returns a list of tuples

      (User, str)

     to be used as options for a SingleSelectField.

     It is important to work with **User**-objects here,
     **not** with ids! Otherwise in case of a failed
     validation, the display of the SingleSelectField
     wouldn't show the last selected value.
     """
     return [(u, u.email) for u in User.query()[:10]]

model_select_form = ListForm("model_select_form",
                              action="model_select_field_action",
                              fields=[SingleSelectField("user",
                                                        options=get_users,

validator=ModelValidator(User)),
                                      TextField("leave_me_empty",
validator=NotEmpty()),
                                      ])

> Anyway, I don't like that approach. What if a want to pass parameters to
> get_options()? I want to pass a SQLAlchemy query when the form is
> instantiated to condition the data to be returned i select fields.

> I think the solution at the moment is to write a function that return all
> childrens to pass to my form but I don't like it.

There are various ways to overcome this. You can use the tmpl_context to
pass the query.

def get_options():
     return tmpl_context.some_options

# in the controller

@expose()
def my_action(self, ...):
     tmlp_context.some_options = my_query
     return ...

It should also be possible to do something like this (in the template):

${my_form.display(value, dict(options=dict(select_field=the_query)))}

Diez


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »