On Thu, Apr 24, 2008 at 11:46 AM, Cecil Westerhof
<[EMAIL PROTECTED]> wrote:
> To get to know TG I am trying to start writing a blog application. In my
> controller I have:
> #####
>     @expose(template='kid:tblog.BlogEntryController.templates.form')
>     def new(self, **kw):
>         return dict(modelname = self.modelname,
>                      data      = dict(authorID = identity.current.user.id),
here is your problem data is actually 2 values
data = {
authorID = 1
}

therefore when the widget looks for data it's returning 'authorId' as
that's the first entry.
you can fix this in several ways.
if you want to keep that dict (only worth it if you have more values for it.
change the template to
> ${form(value = data['authorId'], action = 'save', submit_text = "Create")}
if you don't want to keep that dict
change the controller to be
         return dict(modelname = self.modelname,
                      authorID = identity.current.user.id,
                      ....


> when the widget evaluates data it's getting

>                     form      = model_form,
>                     page      ='new')
>
>  #####
>
> and:
> #####
> class BlogEntryFields(widgets.WidgetsList):
>     author      = widgets.HiddenField()
>     date        = widgets.CalendarDateTimePicker(name      = 'date',
>                                                  label     = 'Entry Date',
>                                                   validator =
> validators.DateTimeConverter())
>     entryTitle  = widgets.TextField(name = 'entryTitle', label = 'Entry
> Title',
>                                     validator = validators.NotEmpty)
>      entryText   = widgets.TextArea(name = 'entryText', label = 'Blog
> Entry',
>                                    validator = validators.NotEmpty,
>                                    rows = 25, cols = 70)
>  #####
>
> In the kid-file I have:
> #####
> #${data}#${data['authorID']}#
> ${form(value = data, action = 'save', submit_text = "Create")}
> #####
>
> I use this, because I want that the author of an entry is the logged in
> person.
>
> When I look at the source of the generated page, I see that
>     #${data}#${data['authorID']}#
>  is expanded to
>     #authorID#1#
>
> But the hidden field becomes:
>     <input class="hiddenfield" type="hidden" id="form_author" name="author">
>
> Value is not filled.
> The code should become something like:
>     author      = widgets.HiddenField(default = <value>)
>
> but how do I retreive the needed value in BlogEntryFields?
>
> --
> Cecil Westerhof
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to