Transcript TurboGears

TurboGears
A python-based web Megaframework
What does it do?
 Write web applications faster.
Achieves this by allowing the user
to write applications in a highlevel interpreted programming
language while conforming to the
Model-View-Controller
architecture.
What does it use?




Kid
CherryPy
SQLObject
MochiKit
Code Examples
:Model:
# Pretend all the import statements are here.
# Next two lines are generated in every project.
hub = PackageHub("newwiki")
__connection__ = hub
# SQL equivalent to defining a table Page with the columns
# “Pagename” with a length of 30 and “data” with no max length
# set. AlternateID=True ensures uniqueness with pagename.
class Page(SQLObject):
pagename=StringCol(alternateID=True, length=30)
data=StringCol()
Code Examples, continued
:Controller:
# Pretend there are import statements here, too.
wikiwords=re.compile(r"\b([A-Z]\w+[A-Z]+\w+)")#Detects words LikeThis or TurboGears.
class Root(controllers.RootController):
@turbogears.expose(html=".templates.page") #Tells TG to use the page template
def default(self, pagename):
#for root requests along with the
return self.index(pagename)
#variable pagename
@turbogears.expose(html=".templates.edit") #The edit method uses the edit
def edit(self, pagename):
#template
page = Page.byPagename(pagename)
#Finds the pagename in the database
return dict(pagename=page.pagename, data=page.data, new=False)
Code Examples, continued
:View:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
py:extends="'master.kid'">
<head><meta content="text/html; charset=UTF-8" http-equiv="content-type"
py:replace="''"/>
<title>Welcome to TurboGears</title>
</head>
<body>
<div style="float:right; width: 10em">
Viewing <span py:replace="pagename">You will never see this.</span>
<br/>
You can return to the <a href="/">FrontPage</a>.
</div>
<form action="save" method="post">
<input type="hidden" name="new" value="${new}" />
<input type="hidden" name="pagename" py:attrs="value=pagename"/>
<textarea name="data" py:content="data" rows="10" cols="60"/>
<input type="submit" name="submit" value="Save"/>
</form> <!--Yes, this is just XHTML with embedded python variables-->
Other included components
 TurboGears toolbox
A web application that:
-Includes a frontend to the SQLobject database
-A visual model diagram generator
-An widget browser
-Shows version information to all included parts
-A python web-console