displaying galleries on your page works
[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
5 from pylons import url
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, Rating
12
13 class ArtController(BaseController):
14 def __before__(self, id=None):
15 super(ArtController, self).__before__()
16 # Awesome refactoring!
17 if id:
18 c.art = h.get_object_or_404(Art, id=id)
19
20 # def index():
21 # c.artwork = Art.query.order_by(Art.id.desc()).all()
22 # return render
23
24 def new(self):
25 """ New Art! """
26 return render("/art/new.mako")
27
28 # TODO: login required
29 def create(self):
30 Art(uploaded_by=c.user, **request.params)
31 elixir.session.commit()
32 redirect_to(controller="main", action="index")
33
34 def show(self, id):
35 # c.art = h.get_object_or_404(Art, id=id)
36 if c.user:
37 c.your_score = c.art.user_score(c.user)
38 return render("/art/show.mako")
39
40 # # TODO: login required
41 # def tag(self, id):
42 # # c.art = h.get_object_or_404(Art, id=id)
43 # c.art.add_tags(request.params["tags"], c.user)
44 # elixir.session.commit()
45 # redirect_to('show_art', id=c.art.id)
46 #
47 # TODO: login required
48 def rate(self, id):
49 # c.art = h.get_object_or_404(Art, id=id)
50 score = request.params.get("score")
51 if score and score.isnumeric():
52 score = int(score)
53 else:
54 score = Rating.reverse_options.get(score)
55
56 c.art.rate(score, c.user)
57 elixir.session.commit()
58
59 redirect(url('art', id=c.art.id))