custom
Here is my controller for the form:
class User5amController(AdminBaseController):
@expose('alims.templates.widget')
def index(self, *args, **kw):
log.debug('***%s***' %kw)
return self.widget(UserForm,kw)
The debug log is in there to confirm that the attributes I send via the URL
appears in kw (it does)
The form is here:
class UserForm(AdminPage):
entity = model.User
title = 'User'
class child(FloatForm):
cid=1
css_class = 'floatform'
buttons = [SaveButton(),CancelButton()]
help_msg = 'Enter the information for the new user'
id = HiddenField(validator=twc.IntValidator)
customer_id = TextField(
label="Customer ID",
attrs=dict(disabled=True),
value=cid
)
user_name = TextField(
label="User ID",
validator = twc.Required
)
password = PasswordField(
label="Password",
validator = twc.Required
)
Now, basically what I need is to set 'cid' in the form to the value of
'customer_id' in 'kw' - instead of its current placeholder 'cid=1'.
The template is here:
<form xmlns:py="http://genshi.edgewall.org/" class="floatform"
py:attrs="w.attrs">
<div py:if="w.error_msg" class="formerror" py:content="w.error_msg"/>
<div py:if="w.help_msg" class="formhelp"><p
py:content="w.help_msg"/></div>
<div py:replace="w.child.display()"/>
<div py:for="button in w.buttons" class="field"
py:content="button.display()"/>
</form>
I am assuming here is where I have to do something... I just do not know
what.
On Wednesday, July 24, 2013 1:52:03 PM UTC-4, Alessandro Molina wrote:
>
> Hi,
> is your form automatically generated by the admin or are you talking about
> a custom made controller and template?
>
>
> On Wed, Jul 24, 2013 at 4:49 PM, Dennis Backhaus <
> [email protected] <javascript:>> wrote:
>
>> Sounds like a simple task, *but for some reason this only works for the
>> primary key of the model in my form*.
>>
>> Example:
>>
>> /customer - opens an empty form to add a new customer
>>
>> /customer?customer_id=X - opens a form with the customer information of
>> customer with customer_id = X for edit
>>
>> /customer?customer_name=Tech - opens an empty form to add a new customer
>> (instead of opening the customer object where customer_name=Tech
>>
>> Why is this happening? I spent the last two hours on google trying to
>> find answers, but I did not find anything yet. Most answers seem to suggest
>> that it should just simply work. Since it does not, I wonder if this is a
>> TG (TW) issue?
>>
>>
>> In the end I want to get to the point that customers can only be created
>> when customer_name is defined in the URL and the customer_name field is
>> read_only in the form.
>>
>>
>>
>> If this is not a TG problem, please direct me to the right answer. Thanks
>> a lot,
>>
>> Dennis
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "TurboGears" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/turbogears.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/groups/opt_out.