annotate examples/turbogears/genshitest/controllers.py @ 793:be88c77839fc trunk

Get rid of a couple more -3 warnings.
author cmlenz
date Mon, 08 Dec 2008 21:15:19 +0000
parents 2755b06148b3
children
rev   line source
4
49364e784c47 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
49364e784c47 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
49364e784c47 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
49364e784c47 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
49364e784c47 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
64ff134868c4 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
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
7 from turbogears import identity
4
49364e784c47 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
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 110
diff changeset
9 from genshitest import json
4
49364e784c47 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
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 110
diff changeset
11 log = logging.getLogger("genshitest.controllers")
4
49364e784c47 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
49364e784c47 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
bbabcbb6378f Prepare [milestone:0.3.1] release.
cmlenz
parents: 230
diff changeset
14
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 110
diff changeset
15 @expose(template="genshitest.templates.welcome")
4
49364e784c47 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):
49364e784c47 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
49364e784c47 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
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
19 return dict(now=time.ctime(),
64ff134868c4 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",
441
2755b06148b3 Fix undefined error in TurboGears example app, and some cleanup.
cmlenz
parents: 265
diff changeset
21 default="Lorem ipsum",
110
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
22 rows=5, cols=40))
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
23
265
26bebcc26da8 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
24 @expose(template="genshi-text:genshitest.templates.plain",
26bebcc26da8 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
25 content_type='text/plain; charset=utf-8')
26bebcc26da8 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 def plain(self):
26bebcc26da8 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 return dict(name='world')
26bebcc26da8 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
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 110
diff changeset
29 @expose(template="genshitest.templates.login")
110
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
30 def login(self, forward_url=None, previous_url=None, *args, **kw):
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
31
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
32 if not identity.current.anonymous \
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
33 and identity.was_login_attempted() \
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
34 and not identity.get_identity_errors():
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
35 raise redirect(forward_url)
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
36
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
37 forward_url=None
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
38 previous_url= cherrypy.request.path
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
39
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
40 if identity.was_login_attempted():
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
41 msg=_("The credentials you supplied were not correct or "
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
42 "did not grant access to this resource.")
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
43 elif identity.get_identity_errors():
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
44 msg=_("You must provide your credentials before accessing "
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
45 "this resource.")
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
46 else:
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
47 msg=_("Please log in.")
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
48 forward_url= cherrypy.request.headers.get("Referer", "/")
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
49 cherrypy.response.status=403
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
50 return dict(message=msg, previous_url=previous_url, logging_in=True,
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
51 original_parameters=cherrypy.request.params,
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
52 forward_url=forward_url)
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
53
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
54 @expose()
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
55 def logout(self):
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
56 identity.current.logout()
64ff134868c4 update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents: 4
diff changeset
57 raise redirect("/")
Copyright (C) 2012-2017 Edgewall Software