Hello,
I've made my first application with TG (the URL is not public yet) and
I want to share my first application to help the newcomers.
I've chosen to use SQLAlchemy and Kid (the choice is difficult with
TG 1.0).
SA rocks! I described my data model with plain SA (table, class
and mapper) but today I would have chosen to use the declarative
plugin of SA (like I did for the Transifex Project).
Other notes:
1 - choose a coding convention for SA, eg. Table.query.all()
and not session.query(Table).all()
2 - Table.query.get(id) doesn't raise an exception like a
filter_by().one() so be careful!
I tried to use the TG Crud extension but I didn't like the generated
code and in fact, I didn't find the generated skeleton useful.
I lost too much time with the TG registration extension, I
already talked about that with Patrick and he has released a new
version since my comments but in the end, I used my own version.
I experimented with many things with Kid to have a nice layout
template, I identified two approaches:
1 - the default one, where each action can override master.kid (py:extends)
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#
"
py:extends="'master.kid'">
2 - the other one is to use the py:layout method
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#
"
py:layout="'layout.kid'">
I defined different anchors (tags) in the master.kid such as the
'content' one so the layout is preserved across the different
action templates.
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#
"
py:layout="'layout.kid'">
<head>
<title py:match="item.tag == '{http://www.w3.org/1999/xhtml}title'">Your
site - ${record.title}</title>
</head>
<body>
<div py:match="item.tag == '{http://www.w3.org/1999/xhtml}content'">
<div py:replace="XML(record.data)">Content</div>
</div>
</body>
</html>
If you make a change in master.kid (or layout.kid as in this
example), don't forget to manually restart your app because the
change won't be detected.
Genshi is really more powerful than Kid.
1 - Don't use default arg to function used for error_handling, eg.
def edit(self, id, tg_errors=None):
...
@error_handler(edit)
You can see that 'id' has no default value, it's required to provide
error handling.
2 - Don't use .all() in queries used by a paginator
3 - Use only named argument in the source code,
eg. http://localhost:8080/page/show?id=13 and NOT
http://localhost:8080/page/show/13 because the last '/' can break
a relative URL (eg. ../static)
4 - MochiKit initialization is slow. Avoid activating MochiKit on each
page (in app.cfg) and add it explicitly when required (in the template)
5 - All the widgets are built at initialization time so you can use
the update_params method to use dynamic values (eg. page_widget.py)
6 - The 'options' field used in widgets is important for the internal
validator of the widget so don't use a 'dummy' string if you
intend to insert integers with update_params, the selected option
won't work.
The wiki of TurboGears needs some love (content and artwork) but my
english sucks :(
Stéphane
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---