Merge branch 'master' of git@veekun.com:floof
[zzz-floof.git] / floof / controllers / users.py
1 import logging
2
3 from pylons import request, response, session, tmpl_context as c
4 from pylons.controllers.util import abort, redirect_to
5 from sqlalchemy import func
6 from sqlalchemy.orm.exc import NoResultFound
7
8 from floof.lib.base import BaseController, render
9 from floof.model.users import User, UserRelationship
10
11 log = logging.getLogger(__name__)
12
13 class UsersController(BaseController):
14
15 def list(self):
16 """List of all users."""
17
18 # TODO paging!
19 c.users = User.query.all()
20
21 return render('/users/index.mako')
22
23 def view(self, name):
24 """Userpage."""
25
26 try:
27 c.this_user = User.query.filter(func.lower(User.name) == name) \
28 .one()
29 except NoResultFound:
30 abort(404)
31
32 rels = UserRelationship.query.filter_by(
33 user_id=c.user.id,
34 target_user_id=c.this_user.id,
35 ).all()
36
37 c.relationships = [_.type for _ in rels]
38
39 return render('/users/view.mako')