I tried submitting this through trac, but, no matter what text I put
in, trac believed that my description was spam.
From:
http://www.turbogears.org/2.0/docs/main/ToscaWidgets/forms.html
when using the quickstart setup, a number of changes to the examples
and code need to be made in order to get the example code to work.
I've included a diff of the documentation changes:
tsavo:tw mcd$ diff -Naur forms.txt.orig forms.txt
--- forms.txt.orig 2008-07-28 20:16:34.000000000 -0400
+++ forms.txt 2008-07-28 20:45:51.000000000 -0400
@@ -22,6 +22,19 @@
Let's start with a simple SQLAlchemy model that has a Movie object
like this ``model/__init__.py``
+If you have used the default quickstart installation, you'll need to
make the following two changes at the top of model/__init__.py
+
+Remove or comment:
+
+#from sqlalchemy.orm import scoped_session, sessionmaker
+#from sqlalchemy import MetaData
+
+Add the following:
+
+from sqlalchemy.orm import scoped_session, sessionmaker, mapper
+from sqlalchemy import *
+import sqlalchemy.types as types
+
::
# model/__init__.py
@@ -45,12 +58,12 @@
Basic Form
----------
-To create a form for the model add the following code in your root.py
(this does not handle validation):
+To create a form for the model add the following code in your root.py
above class RootController (this does not handle validation):
::
from tw.forms import TableForm, TextField, CalendarDatePicker,
SingleSelectField, TextArea
- from toscawidgets.api import WidgetsList
+ from tw.api import WidgetsList
class MovieForm(TableForm):
# This WidgetsList is just a container
@@ -85,7 +98,9 @@
xmlns:xi="
http://www.w3.org/2001/XInclude">
<!-- This line is important, since it will automatically handle
including any required resources in the head -->
- <xi:include href="../master.html" />
+ <xi:include href="master.html" />
+ <xi:include href="footer.html" />
+ <xi:include href="header.html" />
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"
py:replace="''"/>
@@ -114,10 +129,16 @@
# Passing the form in the return dict is no longer kosher,
you can
# set pylons.c.form instead and use c.form in your template
# (remember to 'import pylons' too)
- pylons.c.form = model_form
+ pylons.c.form = create_movie_form
return dict(modelname='Movie')
-Run the application, surf to `
http://localhost:8080/new_form/ <http://
localhost:8080/new_form/>`_ You will see a form that looks like this:
+You will also need to add:
+
+import pylons
+
+in the top section of root.py and if you did not name your project
toscasample, replace toscasample in the @expose line with your project
name.
+
+Run the application, surf to `
http://localhost:8080/new <http://
localhost:8080/new>`_ You will see a form that looks like this:
.. image::
http://docs.turbogears.org/2.0/RoughDocs/ToscaWidgets/Forms?action=AttachFile&do=get&target=movie_form.png
@@ -267,7 +288,7 @@
movie.title = kw['title']
movie.year = kw['year']
movie.release_date = kw['release_date']
- movie.descrpition = kw['description']
+ movie.description = kw['description']
movie.genre = kw['genre']
DBSession.save(movie)
DBSession.commit()