Thijs Triemstra avatar Thijs Triemstra committed c789741

Make the example work with pylons >= 1.0 and fix some other minor issues.

Comments (0)

Files changed (6)

pylonssecuredapp/controllers/panel.py

 import logging
 
 from pylons import request, response, session, tmpl_context as c
-from pylons.controllers.util import abort, redirect_to
+from pylons.controllers.util import abort, redirect
 
 from pylonssecuredapp.lib.base import BaseController, render
 from pylonssecuredapp.lib.auth import protect_controller
 log = logging.getLogger(__name__)
 
 
-# For Python >= 2.6 only:
-# protect_controller(in_group('admins'))
+@protect_controller(in_group('admins'))
 class PanelController(BaseController):
 
     def index(self):
         c.title = 'Page in the Control Panel'
         c.content = 'This controller is completely protected; I told you so!'
         return render('index.mako')
-
-# For Python < 2.6:
-PanelController = protect_controller(in_group('admins'))(PanelController)

pylonssecuredapp/controllers/root.py

 import logging
 
-from pylons import request, response, session, tmpl_context as c
-from pylons.controllers.util import abort, redirect_to
+from pylons import request, response, url, session, tmpl_context as c
+from pylons.controllers.util import abort, redirect
 from pylons.i18n import lazy_ugettext as l_
 from routes.util import url_for
 
         if login_counter > 0:
             flash('Wrong credentials')
         c.login_counter = unicode(login_counter)
-        c.came_from = request.params.get('came_from') or url_for('/')
+        c.came_from = request.params.get('came_from') or url('/')
         return render('login.mako')
     
     def post_login(self):
         identity = request.environ.get('repoze.who.identity')
-        came_from = str(request.params.get('came_from', '')) or url_for('/')
+        came_from = str(request.params.get('came_from', '')) or url('/')
         if not identity:
             login_counter = request.environ['repoze.who.logins'] + 1
-            redirect_to(url_for('/login', came_from=came_from,
+            redirect(url('/login', came_from=came_from,
                                 __logins=login_counter))
         userid = identity['repoze.who.userid']
         flash('Welcome back, %s!' % userid)
-        redirect_to(url_for(came_from))
+        redirect(url(came_from))
 
     def post_logout(self):
         flash('We hope to see you soon!')
-        came_from = str(request.params.get('came_from', '')) or url_for('/')
-        redirect_to(url_for(came_from))
+        came_from = str(request.params.get('came_from', '')) or url('/')
+        redirect(url(came_from))
     
     @protect_action(is_user('gustavo'))
     def only_for_gustavo(self):

pylonssecuredapp/lib/auth.py

 from logging import INFO
 
 from pylons import response
-from pylons.controllers.util import abort
+from pylons.controllers.util import abort, redirect
 
 from repoze.what.plugins.quickstart import setup_sql_auth
 from repoze.what.plugins.pylonshq import ActionProtector, \
                                 logout_handler='/logout',
                                 post_login_url='/post_login',
                                 post_logout_url='/post_logout',
-                                log_level=INFO, 
+                                log_level='info', 
                                 skip_authentication=skip_authentication)
     
     return securedapp

pylonssecuredapp/lib/helpers.py

 available to Controllers. This module is available to templates as 'h'.
 """
 
+from pylons import url
+
 from webhelpers.pylonslib import Flash as _Flash
 from webhelpers.html import literal
 from webhelpers.html.tags import *
-from webhelpers.html.secure_form import secure_form
 
-from routes.util import url_for
-
-flash = _Flash()
+flash = _Flash()

pylonssecuredapp/templates/base.mako

       % endif
       
       <p id="auth-info">
-      % if c.userid:
-          Hi, ${c.userid}! <a href="${h.url_for('/logout')}">Log out</a>
+      % if hasattr(c, 'userid'):
+          Hi, ${c.userid}! <a href="${h.url('/logout')}">Log out</a>
       % else:
-          <a href="${h.url_for('/login')}">Log in</a>
+          <a href="${h.url('/login')}">Log in</a>
       % endif
       </p>
       
       <h2>Links</h2>
     
       <ul>
-        <li><a href="${h.url_for('/')}">/</a></li>
-        <li><a href="${h.url_for('/only_for_gustavo')}">/only_for_gustavo</a></li>
-        <li><a href="${h.url_for('/only_for_foo')}">/only_for_foo</a></li>
-        <li><a href="${h.url_for('/do_something_important')}">/do_something_important</a></li>
-        <li><a href="${h.url_for('/cp/')}">/cp/</a></li>
-        <li><a href="${h.url_for('/cp/protected_too')}">/cp/protected_too</a></li>
+        <li><a href="${h.url('/')}">/</a></li>
+        <li><a href="${h.url('/only_for_gustavo')}">/only_for_gustavo</a></li>
+        <li><a href="${h.url('/only_for_foo')}">/only_for_foo</a></li>
+        <li><a href="${h.url('/do_something_important')}">/do_something_important</a></li>
+        <li><a href="${h.url('/cp/')}">/cp/</a></li>
+        <li><a href="${h.url('/cp/protected_too')}">/cp/protected_too</a></li>
       </ul>
           
       <p class="footer">

pylonssecuredapp/templates/login.mako

     <li>foo (password: whatever)</li>
 </ul>
 
-<form action="${h.url_for('/login_handler', came_from=c.came_from, __logins=c.login_counter)}"
+<form action="${h.url('/login_handler', came_from=c.came_from, __logins=c.login_counter)}"
       method="POST">
     <label for="login">
         Username: <input type="text" id="login" name="login" />
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.