6c5e45404df479aade922b0048670effdc363c89
[zzz-floof.git] / floof / controllers / art.py
1 import logging
2
3 from pylons import request, response, session, tmpl_context as c, h
4 from pylons.controllers.util import abort, redirect_to
5
6 from floof.lib.base import BaseController, render
7
8 log = logging.getLogger(__name__)
9
10 import elixir
11 from floof.model.art import Art
12
13 class ArtController(BaseController):
14
15 # def index():
16 # c.artwork = Art.query.order_by(Art.id.desc()).all()
17 # return render
18
19 def new(self):
20 """ New Art! """
21 return render("/art/new.mako")
22
23
24 def upload(self):
25 print "PARAMS", request.params
26 Art(uploaded_by=c.user, **request.params)
27 elixir.session.commit()
28 redirect_to(controller="main", action="index")
29
30 def show(self, id):
31 c.art = h.get_object_or_404(Art, id=id)
32 if c.user:
33 c.your_score = c.art.user_score(c.user)
34 return render("/art/show.mako")
35
36 # TODO: login required
37 def tag(self, id):
38 c.art = h.get_object_or_404(Art, id=id)
39 c.art.add_tags(request.params["tags"], c.user)
40 elixir.session.commit()
41 redirect_to(action="show", id=c.art.id)
42
43 # TODO: login required
44 def rate(self, id):
45 c.art = h.get_object_or_404(Art, id=id)
46 c.art.rate(request.params["score"], c.user)
47 elixir.session.commit()
48 redirect_to(action="show", id=c.art.id)