(Status: incomplete)
The script tg_shell_setup.py should be saved in your root directory. And from this directory run the shell command:
$ ipython shell development.ini
>>> %run tg_shell_setup
>>> whos
>>> a = DBSession.query(Page).first()
>>> a.__dict__
>>> help(a)
>>> b = Page('second pagetitle', 'SecondPage of WikiWords wiki')
>>> DBSession.add(b)
>>> pages = DBSession.query(Page).all
>>> [(page.data, page.pagename, page.id) for page in pages]
>>> ...
>>> transaction.commit()
>>> quit()
You should see the output
In [3]: a=DBSession.query(Page).first()
In [4]: a.__dict__
Out[4]:
{'_sa_instance_state': <sqlalchemy.orm.identity.IdentityManagedState object at 0x986348c>,
'data': u'initial data',
'id': 1,
'pagename': u'FrontPage'}
In [5]: help(a)
In [6]: b = Page('second pagetitle', 'SecondPage of WikiWords wiki')
In [7]: DBSession.add(b)
In [8]: pages=DBSession.query(Page).all()
In [9]: [(page.data, page.pagename, page.id) for page in pages]
Out[9]:
[(u'initial data', u'FrontPage', 1),
('SecondPage of WikiWords wiki', 'second pagetitle', 2)]
(Status: incomplete)
Download wiki20_external.py and save it in your root directory. Run as usual from the command line.
$ python wiki20_external.py
You can test your model and templates this way, and insert code from your controllers as well. The file outputs html to the screen - capture it in a file and view through your browser.
Now that you have a working Wiki, there are a number of further places to explore:
If you had any problems with this tutorial, or have ideas on how to make it better, please let us know on the mailing list! Suggestions are almost always incorporated.
paster errors:
python errors:
Genshi/XML errors: your Genshi templates (views) must be valid XML documents ,or TG2 will raise an exception. Check your templates with an XML validator:
e.g. xmllint on linux or through Cygwin on Windows for example.
$ xmllint -noout wiki20/templates/\*.html
will check all your templates at once. With the -noout option, output will be produced only if files are not valid XML.
Use your browser to detect errors.
Database errors: Turn on the sqlalchemy.echo option in your development.ini file:
[app:main]
...
sqlalchemy.echo = true
and check the SQL code emitted by SQLAlchemy in your paster serve window. Experiment with this code in an sqlite interactive session, and with SQLAlchemy in the python/ipython shell.