From 3036be98ef57c54a3c06ac55d9b96432cfeaad90 Mon Sep 17 00:00:00 2001 From: Eevee Date: Thu, 22 Apr 2010 22:21:10 -0700 Subject: [PATCH] Stubby user page. #70 --- spline/plugins/users/__init__.py | 5 ++++ spline/plugins/users/controllers/users.py | 34 ++++++++++++++++++++++++++ spline/plugins/users/templates/users/view.mako | 7 ++++++ 3 files changed, 46 insertions(+) create mode 100644 spline/plugins/users/controllers/users.py create mode 100644 spline/plugins/users/templates/users/view.mako diff --git a/spline/plugins/users/__init__.py b/spline/plugins/users/__init__.py index 5173931..5e006cf 100644 --- a/spline/plugins/users/__init__.py +++ b/spline/plugins/users/__init__.py @@ -8,6 +8,7 @@ import spline.model as model import spline.model.meta as meta import spline.plugins.users.controllers.accounts +import spline.plugins.users.controllers.users import spline.plugins.users.model def add_routes_hook(map, *args, **kwargs): @@ -16,6 +17,9 @@ def add_routes_hook(map, *args, **kwargs): map.connect('/accounts/login_finish', controller='accounts', action='login_finish') map.connect('/accounts/logout', controller='accounts', action='logout') + map.connect('/users/{id};{name}', controller='users', action='view') + map.connect('/users/{id}', controller='users', action='view') + def check_userid_hook(action, **params): """Hook to see if a user is logged in and, if so, stick a user object in c. @@ -40,6 +44,7 @@ class UsersPlugin(PluginBase): def controllers(self): return dict( accounts = spline.plugins.users.controllers.accounts.AccountsController, + users = spline.plugins.users.controllers.users.UsersController, ) def model(self): diff --git a/spline/plugins/users/controllers/users.py b/spline/plugins/users/controllers/users.py new file mode 100644 index 0000000..d64d39f --- /dev/null +++ b/spline/plugins/users/controllers/users.py @@ -0,0 +1,34 @@ +import logging + +from pylons import config, request, response, session, tmpl_context as c, url +from pylons.controllers.util import abort, redirect_to +from routes import request_config +from sqlalchemy.orm.exc import NoResultFound + +from spline import model +from spline.model import meta +from spline.lib import helpers as h +from spline.lib.base import BaseController, render + +log = logging.getLogger(__name__) + +class UsersController(BaseController): + + def index(self): + # Return a rendered template + # return render('/template.mako') + # or, Return a response + return 'stub' + + def view(self, id, name=None): + """User page. + + URL is /users/id:name, where 'name' only exists for readability and is + entirely optional and ignored. + """ + + c.page_user = meta.Session.query(model.User).get(id) + if not c.page_user: + abort(404) + + return render('/users/view.mako') diff --git a/spline/plugins/users/templates/users/view.mako b/spline/plugins/users/templates/users/view.mako new file mode 100644 index 0000000..6462646 --- /dev/null +++ b/spline/plugins/users/templates/users/view.mako @@ -0,0 +1,7 @@ +<%inherit file="/base.mako" /> +<%def name="title()">${c.page_user.name} - Users +<%def name="title_in_page()">User: ${c.page_user.name} + +

${c.page_user.name}

+ +A user! -- 2.7.4