4139da8093256effc6bb2629abdf956cde405467
[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.art import Art, UserRelation
11 from floof.model.users import User
12 import elixir
13
14 class RelationController(BaseController):
15 def create(self, art_id, kind):
16 art = h.get_object_or_404(Art, id=art_id)
17 user = h.get_object_or_404(User, name=request.params['username'])
18 ## TODO: actually, this should act like a form validation.
19
20 prior_relation = UserRelation.get_by(art=art, user=user)
21 if prior_relation:
22 abort(404) ## should be a validation error
23
24 relation = UserRelation(user=user, kind=kind, art=art, creator=c.user)
25 elixir.session.commit()
26 redirect(url('show_art', id=art_id))
27
28 def index(self):
29 # Return a rendered template
30 #return render('/relation.mako')
31 # or, return a response
32 return 'Hello World'