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