annotate examples/turbogears/genshitest/controllers.py @ 275:7f24dd6fb904

Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
author cmlenz
date Sun, 01 Oct 2006 22:54:57 +0000
parents 0f2bc982a2b9
children 9d3f275953b5
rev   line source
4
f8612f05af99 Added first stab of an implementation of the !TurboGears [http://www.turbogears.org/docs/plugins/template.html plugin API for template engines], and also a !TurboGears-based example using this plugin. Both written by Matt Good.
cmlenz
parents:
diff changeset
1 import logging
f8612f05af99 Added first stab of an implementation of the !TurboGears [http://www.turbogears.org/docs/plugins/template.html plugin API for template engines], and also a !TurboGears-based example using this plugin. Both written by Matt Good.
cmlenz
parents:
diff changeset
2
f8612f05af99 Added first stab of an implementation of the !TurboGears [http://www.turbogears.org/docs/plugins/template.html plugin API for template engines], and also a !TurboGears-based example using this plugin. Both written by Matt Good.
cmlenz
parents:
diff changeset
3 import cherrypy
f8612f05af99 Added first stab of an implementation of the !TurboGears [http://www.turbogears.org/docs/plugins/template.html plugin API for template engines], and also a !TurboGears-based example using this plugin. Both written by Matt Good.
cmlenz
parents:
diff changeset
4
f8612f05af99 Added first stab of an implementation of the !TurboGears [http://www.turbogears.org/docs/plugins/template.html plugin API for template engines], and also a !TurboGears-based example using this plugin. Both written by Matt Good.
cmlenz
parents:
diff changeset
5 import turbogears
110
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
6 from turbogears import controllers, expose, validate, redirect, widgets
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
7 from turbogears import identity
4
f8612f05af99 Added first stab of an implementation of the !TurboGears [http://www.turbogears.org/docs/plugins/template.html plugin API for template engines], and also a !TurboGears-based example using this plugin. Both written by Matt Good.
cmlenz
parents:
diff changeset
8
230
24757b771651 Renamed Markup to Genshi in repository.
cmlenz
parents: 110
diff changeset
9 from genshitest import json
4
f8612f05af99 Added first stab of an implementation of the !TurboGears [http://www.turbogears.org/docs/plugins/template.html plugin API for template engines], and also a !TurboGears-based example using this plugin. Both written by Matt Good.
cmlenz
parents:
diff changeset
10
230
24757b771651 Renamed Markup to Genshi in repository.
cmlenz
parents: 110
diff changeset
11 log = logging.getLogger("genshitest.controllers")
4
f8612f05af99 Added first stab of an implementation of the !TurboGears [http://www.turbogears.org/docs/plugins/template.html plugin API for template engines], and also a !TurboGears-based example using this plugin. Both written by Matt Good.
cmlenz
parents:
diff changeset
12
f8612f05af99 Added first stab of an implementation of the !TurboGears [http://www.turbogears.org/docs/plugins/template.html plugin API for template engines], and also a !TurboGears-based example using this plugin. Both written by Matt Good.
cmlenz
parents:
diff changeset
13 class Root(controllers.RootController):
262
77d92c5c23d3 Prepare [milestone:0.3.1] release.
cmlenz
parents: 230
diff changeset
14
230
24757b771651 Renamed Markup to Genshi in repository.
cmlenz
parents: 110
diff changeset
15 @expose(template="genshitest.templates.welcome")
4
f8612f05af99 Added first stab of an implementation of the !TurboGears [http://www.turbogears.org/docs/plugins/template.html plugin API for template engines], and also a !TurboGears-based example using this plugin. Both written by Matt Good.
cmlenz
parents:
diff changeset
16 def index(self):
f8612f05af99 Added first stab of an implementation of the !TurboGears [http://www.turbogears.org/docs/plugins/template.html plugin API for template engines], and also a !TurboGears-based example using this plugin. Both written by Matt Good.
cmlenz
parents:
diff changeset
17 import time
f8612f05af99 Added first stab of an implementation of the !TurboGears [http://www.turbogears.org/docs/plugins/template.html plugin API for template engines], and also a !TurboGears-based example using this plugin. Both written by Matt Good.
cmlenz
parents:
diff changeset
18 log.debug("Happy TurboGears Controller Responding For Duty")
110
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
19 return dict(now=time.ctime(),
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
20 widget=widgets.TextArea(name="widget_test",
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
21 default="This is a test of using "
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
22 "TurboGears widgets with "
230
24757b771651 Renamed Markup to Genshi in repository.
cmlenz
parents: 110
diff changeset
23 "Genshi",
110
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
24 rows=5, cols=40))
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
25
265
0f2bc982a2b9 Split up the plugin implementation into two classes: one for markup templates (?genshi-markup? or just ?genshi?) and one for text templates (?genshi-text?). Also added an example for plain-text templating to the TurboGears example app.
cmlenz
parents: 262
diff changeset
26 @expose(template="genshi-text:genshitest.templates.plain",
0f2bc982a2b9 Split up the plugin implementation into two classes: one for markup templates (?genshi-markup? or just ?genshi?) and one for text templates (?genshi-text?). Also added an example for plain-text templating to the TurboGears example app.
cmlenz
parents: 262
diff changeset
27 content_type='text/plain; charset=utf-8')
0f2bc982a2b9 Split up the plugin implementation into two classes: one for markup templates (?genshi-markup? or just ?genshi?) and one for text templates (?genshi-text?). Also added an example for plain-text templating to the TurboGears example app.
cmlenz
parents: 262
diff changeset
28 def plain(self):
0f2bc982a2b9 Split up the plugin implementation into two classes: one for markup templates (?genshi-markup? or just ?genshi?) and one for text templates (?genshi-text?). Also added an example for plain-text templating to the TurboGears example app.
cmlenz
parents: 262
diff changeset
29 return dict(name='world')
0f2bc982a2b9 Split up the plugin implementation into two classes: one for markup templates (?genshi-markup? or just ?genshi?) and one for text templates (?genshi-text?). Also added an example for plain-text templating to the TurboGears example app.
cmlenz
parents: 262
diff changeset
30
230
24757b771651 Renamed Markup to Genshi in repository.
cmlenz
parents: 110
diff changeset
31 @expose(template="genshitest.templates.login")
110
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
32 def login(self, forward_url=None, previous_url=None, *args, **kw):
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
33
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
34 if not identity.current.anonymous \
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
35 and identity.was_login_attempted() \
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
36 and not identity.get_identity_errors():
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
37 raise redirect(forward_url)
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
38
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
39 forward_url=None
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
40 previous_url= cherrypy.request.path
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
41
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
42 if identity.was_login_attempted():
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
43 msg=_("The credentials you supplied were not correct or "
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
44 "did not grant access to this resource.")
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
45 elif identity.get_identity_errors():
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
46 msg=_("You must provide your credentials before accessing "
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
47 "this resource.")
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
48 else:
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
49 msg=_("Please log in.")
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
50 forward_url= cherrypy.request.headers.get("Referer", "/")
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
51 cherrypy.response.status=403
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
52 return dict(message=msg, previous_url=previous_url, logging_in=True,
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
53 original_parameters=cherrypy.request.params,
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
54 forward_url=forward_url)
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
55
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
56 @expose()
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
57 def logout(self):
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
58 identity.current.logout()
44fbc30d78cd update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
59 raise redirect("/")
Copyright (C) 2012-2017 Edgewall Software