Hello again!
Finally I have time to port my project to new version of TurboGears. I was 
able to solve most of the issues but now I need your help: 
I can't load data to TW2 form. Here are some code:

widgets/news.py fragment (form):

class NewsEditForm(TableForm):
    title_label = Label(text=u'Изменить новость')
    tf_title = TextField(label=u'Заголовок', validator=NotEmpty, size=50)
    tf_url = TextField(label=u'Ссылка', validator=URL, size=50)
    tf_text = TextArea(label=u'Текст новости', validator=NotEmpty, rows=10, 
cols=50)
    news_id = HiddenField('news_id')

    submit = SubmitButton(value=u"Изменить")
    action = '/manage/saveNews'
    
manage.py Controller fragment:

class ManageController(BaseController):
...
    @expose('cafealpha.templates.manage_news')
    def news(self, news_id='', *args, **kw):
        if not request.identity:   #if not authorized then redirect to /
            redirect('/')

        news = DBSession.query(News).filter_by(id=news_id).one()
        news_form = NewsEditForm()
        news_form.tf_title.value = news.title

        return dict(pagename=u'Новости', form=news_form)

manage_news.xhtml fragment:

${form.display()}

Error I'm getting is:
  File 
"/home/uni/projects/cafealpha-tg23/venv/cafealpha/cafealpha/controllers/manage.py"
, line 46, in news
    news_form.tf_title.value = news.title
AttributeError: type object 'NewsEditForm_d' has no attribute 'tf_title'


It seems I'm misssing something obvious so pleas point me.

My Python is rusty so feel free to laugh :)

*P.S.* I was able to load data to form using this code in template:
${form.display(value=dict(tf_url=news_url))}

and passing news_url with return dict() from Controller. But I just think 
this is not the best way. Or is it?

-- 
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 https://groups.google.com/group/turbogears.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/turbogears/564ca3c2-0b22-4c30-8055-9b80ec542e41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to