Mystery of the Misbehaving form

4 views
Skip to first unread message

casibbald

unread,
Dec 30, 2009, 4:56:45 PM12/30/09
to TurboGears
Hi All,

I have something strange going on with my forms, they seem to
misbehave and i don't know if its my code, or something with forms.

The strange thing is, if i get Turbogears to reload anything by adding
a comment to a file, i can visit the page and the form works again.
but the forms vanish again.

The following is a form rendered correctly:
http://prontoapps.com/images/formItemShowing.png

The following is the form if the page is refreshed, or visited from
another browser tab/machine:
http://prontoapps.com/images/formItemsVanish.png

The application does not have a DB, and is designed to manipulate
files on the filesystem.

Looking forward to someone shedding light on this.

Regards

Charles

======

The following is the root controller:
=================
# -*- coding: utf-8 -*-
"""Main Controller"""

from tg import expose, flash, require, url, request, redirect
from pylons.i18n import ugettext as _, lazy_ugettext as l_
from tg import tmpl_context, redirect, validate

from webdeploy.lib.base import BaseController
from webdeploy.model import DBSession, metadata
from webdeploy.controllers.error import ErrorController
from webdeploy.lib.mylibs import getMywebInstalledVersions as
getVersions
from webdeploy.lib.mylibs import checkIfRunning as checkIfRunning

from webdeploy.lib.applicationControlForm import
create_applicationControlForm

import os

__all__ = ['RootController']


class RootController(BaseController):
"""
The root controller for the webdeploy application.

All the other controllers and WSGI applications should be mounted
on this
controller. For example::

panel = ControlPanelController()
another_app = AnotherWSGIApplication()

Keep in mind that WSGI applications shouldn't be mounted directly:
They
must be wrapped around
with :class:`tg.controllers.WSGIAppController`.

"""

error = ErrorController()

@expose('webdeploy.templates.index')
def index(self):
"""Handle the front-page."""
myweb_home = os.getenv("MYWEB_HOME")
return dict(page='index', versions=getVersions(myweb_home),
appStatus=checkIfRunning())


@expose('webdeploy.templates.applicationControl')
def applicationControl(self, **kw):
"""Handle the 'applicationControl' page."""
tmpl_context.form = create_applicationControlForm
return dict(page='applicationControl',
control_options='controlApplicationOptions',
control_actions='controlAction')

@validate(create_applicationControlForm)
@expose()
def executeForm(self, **kw):
"""Handle the 'applicationControl' page."""
tmpl_context.form = create_applicationControlForm
redirect("index")


The following is my form code:
============
# -*- coding: utf-8 -*-

from tw.api import WidgetsList
from tw.forms import TableForm, SingleSelectField, TextField,
TextArea, Spacer, Label
from tw.forms.validators import Int, NotEmpty, DateConverter
from webdeploy.lib.mylibs import getExecutables as getExecutables


class applicationControlForm(TableForm):

class fields(WidgetsList):
installDict = getExecutables()
applicationList = []
hover_help = True
for each in installDict:
if each == "DMT" :
pass
else :
applicationList.append(each)
controlApplicationOptions = enumerate((applicationList))
controlApplication = SingleSelectField('Application',
options=controlApplicationOptions, help_text = 'Please select the
Application to control.')

controlActionOptions = enumerate(('start', 'stop'))
controlAction = SingleSelectField
(options=controlActionOptions)

create_applicationControlForm = applicationControlForm
("create_applicationControlForm", action='executeForm')

================
Environment info:
# paster --versionPasteScript 1.7.3 from /home/nowplus/apps/mywebapp/
lib/python2.6/site-packages/PasteScript-1.7.3-py2.6.egg (python 2.6.2
(r262:71600, Aug 11 2009, 07:00:48))

TurboGears2 Complete Version Information
========================================

TurboGears2 requires:

* setuptools 0.6c11
* Paste 1.7.2
* Pygments 1.0
* WebError 0.10.1
* FormEncode 1.2.1
* repoze.who 1.0.15
* PasteScript 1.7.3
* BytecodeAssembler 0.3
* TurboGears2 2.0.3
* PasteDeploy 1.3.3
* Routes 1.10.3
* nose 0.10.4
* Tempita 0.2
* AddOns 0.6
* WebFlash 0.1a9
* transaction 1.0a1
* DecoratorTools 1.7
* repoze.what 1.0.8
* prioritized-methods 0.2.1
* TurboJson 1.2.1
* SymbolType 1.0
* PEAK-Rules 0.5a1.dev-r2582
* WebOb 0.9.6.1
* repoze.who-testutil 1.0rc1
* decorator 3.0.0
* Genshi 0.5.1
* Extremes 1.1
* Beaker 1.3
* WebHelpers 0.6.4
* Pylons 0.9.7
* repoze.what-pylons 1.0rc3
* zope.interface 3.4.1
* simplejson 2.0.8
* WebTest 1.1
* Mako 0.2.4
* ToscaWidgets 0.9.8
* repoze.tm2 1.0a4

TurboGears2 Commands

* migrate (tg.devtools 2.0.2)
* quickstart (tg.devtools 2.0.2)
* shell (TurboGears2 2.0.3)
* serve (TurboGears2 2.0.3)

Widget Packages

* widgets (ToscaWidgets 0.9.8)
* resources (ToscaWidgets 0.9.8)
* widgets (tw.forms 0.9.8)
* samples (tw.forms 0.9.8)

TurboGears2 Templates

* turbogears2 (tg.devtools 2.0.2)

Toolbox2 Gadgets


Template Engines

* json (TurboJson 1.2.1)
* genshi-markup (Genshi 0.5.1)
* genshi-text (Genshi 0.5.1)
* genshi (Genshi 0.5.1)
* pylonsmyghty (Pylons 0.9.7)
* mako (Mako 0.2.4)
* toscawidgets (ToscaWidgets 0.9.8)

Available Widgets:


* ToscaWidgets 0.9.8:
- AggregatedCSSLink
- AggregatedJSLink
- CSSLink
- CSSMixin
- CSSSource
- Child
- EngineException
- EngineManager
- HostFramework
- IECSSLink
- IECSSSource
- IEJSLink
- IEJSSource
- JSFunctionCalls
- JSLink
- JSMixin
- JSSource
- LRUCache
- Link
- OrderedSet
- Renderable
- RepeatedWidget
- RepeatingWidgetBunch
- RequestLocalDescriptor
- Resource
- ServerSideCallbackMixin
- Source
- Widget
- WidgetBunch
- WidgetException
- WidgetInitialized
- WidgetLocked
- WidgetRepeater
- WidgetType
- WidgetUninitialized
- WidgetUnlocked
- WidgetsList
- adapt_value
- always_allow
- always_deny
- asbool
- base
- disable_runtime_checks
- display
- engine_plugin
- exceptions
- inject_resources
- injector_middleware
- js
- js_callback
- js_function
- js_symbol
- lazystring
- locations
- make_middleware
- merge_resources
- meta
- middleware
- registry
- render
- resource_injector
- resources
- retrieve_resources
- server
- serverside_callback
- util
- valid_id
- view

* ToscaWidgets 0.9.8:
- AggregatedCSSLink
- AggregatedJSLink
- CSSLink
- CSSMixin
- CSSSource
- Child
- EngineException
- EngineManager
- HostFramework
- IECSSLink
- IECSSSource
- IEJSLink
- IEJSSource
- JSFunctionCalls
- JSLink
- JSMixin
- JSSource
- LRUCache
- Link
- OrderedSet
- Renderable
- RepeatedWidget
- RepeatingWidgetBunch
- RequestLocalDescriptor
- Resource
- ServerSideCallbackMixin
- Source
- Widget
- WidgetBunch
- WidgetException
- WidgetInitialized
- WidgetLocked
- WidgetRepeater
- WidgetType
- WidgetUninitialized
- WidgetUnlocked
- WidgetsList
- adapt_value
- always_allow
- always_deny
- asbool
- base
- disable_runtime_checks
- display
- engine_plugin
- exceptions
- inject_resources
- injector_middleware
- js
- js_callback
- js_function
- js_symbol
- lazystring
- locations
- make_middleware
- merge_resources
- meta
- middleware
- registry
- render
- resource_injector
- resources
- retrieve_resources
- server
- serverside_callback
- util
- valid_id
- view

* tw.forms 0.9.8:
- BooleanRadioButtonList
- Button
- CalendarDatePicker
- CalendarDateTimePicker
- CheckBox
- CheckBoxList
- CheckBoxTable
- ContainerMixin
- DataGrid
- FieldSet
- FileField
- Form
- FormField
- FormFieldRepeater
- HiddenField
- ImageButton
- InputField
- InputWidget
- InputWidgetRepeater
- Label
- LabelHiddenField
- ListFieldSet
- ListForm
- ListMixin
- MultipleSelectField
- MultipleSelectionMixin
- PasswordField
- RadioButton
- RadioButtonList
- ResetButton
- SecureFormMixin
- SecureTicketField
- SelectionField
- SelectionList
- SingleSelectField
- SingleSelectionMixin
- Spacer
- SubmitButton
- TableFieldSet
- TableForm
- TableMixin
- TextArea
- TextField
- Widget
- calendar_js
- calendar_setup
- calendars
- core
- datagrid
- fields
- merge_schemas
- validators

Diez B. Roggisch

unread,
Dec 31, 2009, 1:13:18 PM12/31/09
to turbo...@googlegroups.com
casibbald schrieb:

> Hi All,
>
> I have something strange going on with my forms, they seem to
> misbehave and i don't know if its my code, or something with forms.
>
> The strange thing is, if i get Turbogears to reload anything by adding
> a comment to a file, i can visit the page and the form works again.
> but the forms vanish again.
>
> The following is a form rendered correctly:
> http://prontoapps.com/images/formItemShowing.png
>
> The following is the form if the page is refreshed, or visited from
> another browser tab/machine:
> http://prontoapps.com/images/formItemsVanish.png
>
> The application does not have a DB, and is designed to manipulate
> files on the filesystem.
>
> Looking forward to someone shedding light on this.

You want your @validate-decorator have the applicationControl-action as
error_handler.

Diez

casibbald

unread,
Jan 1, 2010, 7:26:13 AM1/1/10
to TurboGears


Hi Diez,

Thanks for your response.

I have updated as below, but still have the same problem. Could there
be another parameter missing?

@expose('webdeploy.templates.applicationControl')
def applicationControl(self, **kw):
"""Handle the 'applicationControl' page."""
tmpl_context.form = create_applicationControlForm
return dict(page='applicationControl',
control_options='controlApplicationOptions',
control_actions='controlAction')

@validate(create_applicationControlForm,
error_handler=applicationControl)


@expose()
def executeForm(self, **kw):
"""Handle the 'applicationControl' page."""
tmpl_context.form = create_applicationControlForm
redirect("index")

Regards

Charles

Diez B. Roggisch

unread,
Jan 1, 2010, 8:10:10 AM1/1/10
to turbo...@googlegroups.com
casibbald schrieb:

This looks fishy. Why do you pass strings as control_options and
control_actions? And how do you invoke the form in the template, so far
I've not seen that.

Diez

casibbald

unread,
Jan 2, 2010, 7:16:59 AM1/2/10
to TurboGears

Hi Diez,

This is the applicationControl.html template.

============
<body>

<div id="getting_started">
<h2>The following allows you to start and stop Component
Applications</h2>

<div py:replace="tmpl_context.form()">Input Form</div>

</div>

<p></p>
<p></p>
<p></p>
<p></p>
</body>

==============

control_options = is the start and stop select field.

control_applications = is the list of applications.

I am happy to share the whole lot of code with you, if you don't mind.

casibbald

unread,
Jan 2, 2010, 1:21:23 PM1/2/10
to TurboGears

Updated as follows, based on Diez's instructions.

===============

Quote: Diez

"the problem is your usage of enumerate as option-list constructor.
This is a *generator* object. Thus after the initial display of the
form, it's exhausted.

I didn't notice that before, even though your shown code-samples in
the ML had that error. I guess that's because your code is pretty
convoluted - mixing form-declaration & creation of these lists into
the class-scope is a bit on the wierd side IMHO.

All you need to do is to wrap the generator into a list:"

===============

class applicationControlForm(TableForm):

class fields(WidgetsList):
installDict = getExecutables()
applicationList = []
hover_help = True
for each in installDict:
if each == "DMT" :
pass
else :
applicationList.append(each)

controlApplicationOptions = list(enumerate((applicationList)))


controlApplication = SingleSelectField('Application',
options=controlApplicationOptions, \
help_text = 'Please
select the Application to control.')

controlActionOptions = list(enumerate(('start', 'stop')))
controlAction = SingleSelectField
(options=controlActionOptions)
submit_text = 'Save Movie'


create_applicationControlForm = applicationControlForm
("create_applicationControlForm", action='executeForm')


===========

Thank you so much, I really appreciate the help.

Reply all
Reply to author
Forward
0 new messages