Depend on wtforms.
[zzz-floof.git] / floof / controllers / relation.py
1 import logging
2
3 from pylons import request, response, session, tmpl_context as c, h, url
4 from pylons.controllers.util import abort, redirect
5
6 from floof.lib.base import BaseController, render
7
8 log = logging.getLogger(__name__)
9
10 from floof.model import Art, UserRelation
11 from floof.model.users import User
12 import elixir
13
14 # TODO!!! Implement adding a related user the same way that it works
15 # on the "add new art" page
16
17 class RelationController(BaseController):
18 def create(self, art_id, kind):
19 art = h.get_object_or_404(Art, id=art_id)
20 user = h.get_object_or_404(User, name=request.params['username'])
21 ## TODO: actually, this should act like a form validation.
22
23 prior_relation = UserRelation.get_by(art=art, user=user)
24 if prior_relation:
25 abort(404) ## should be a validation error
26
27 relation = UserRelation(user=user, kind=kind, art=art, creator=c.user)
28 elixir.session.commit()
29 redirect(url('show_art', id=art_id))
30
31 def index(self):
32 # Return a rendered template
33 #return render('/relation.mako')
34 # or, return a response
35 return 'Hello World'