Mercurial > genshi > genshi-test
annotate examples/turbogears/markuptest/controllers.py @ 146:db0dacc1239a
Simplifed `CoalesceFilter` (now a function)
author | cmlenz |
---|---|
date | Tue, 15 Aug 2006 10:12:03 +0000 |
parents | 44fbc30d78cd |
children |
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 |
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
|
9 from markuptest import json |
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 |
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
|
11 log = logging.getLogger("markuptest.controllers") |
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): |
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
|
14 @expose(template="markuptest.templates.welcome") |
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
|
15 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
|
16 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
|
17 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
|
18 return dict(now=time.ctime(), |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
19 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
|
20 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
|
21 "TurboGears widgets with " |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
22 "Markup", |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
23 rows=5, cols=40)) |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
24 |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
25 |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
26 @expose(template="markuptest.templates.login") |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
27 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
|
28 |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
29 if not identity.current.anonymous \ |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
30 and identity.was_login_attempted() \ |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
31 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
|
32 raise redirect(forward_url) |
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 forward_url=None |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
35 previous_url= cherrypy.request.path |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
36 |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
37 if identity.was_login_attempted(): |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
38 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
|
39 "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
|
40 elif identity.get_identity_errors(): |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
41 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
|
42 "this resource.") |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
43 else: |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
44 msg=_("Please log in.") |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
45 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
|
46 cherrypy.response.status=403 |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
47 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
|
48 original_parameters=cherrypy.request.params, |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
49 forward_url=forward_url) |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
50 |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
51 @expose() |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
52 def logout(self): |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
53 identity.current.logout() |
44fbc30d78cd
update the example TurboGears app and include an example of using TurboGears wigets
mgood
parents:
4
diff
changeset
|
54 raise redirect("/") |