ca1d7dc06d69635a01b23fad129895e472f2c349
3 from pylons
import request
, response
, session
, tmpl_context
as c
, h
4 from pylons
.controllers
.util
import abort
, redirect
6 from floof
.lib
.base
import BaseController
, render
8 log
= logging
.getLogger(__name__
)
11 from floof
.model
.art
import Art
, Rating
13 from sqlalchemy
.exceptions
import IntegrityError
16 class ArtController(BaseController
):
17 def __before__(self
, id=None):
18 super(ArtController
, self
).__before__()
19 # Awesome refactoring!
21 c
.art
= h
.get_object_or_404(Art
, id=id)
24 # c.artwork = Art.query.order_by(Art.id.desc()).all()
29 return render("/art/new.mako")
31 # TODO: login required
33 c
.art
= Art(uploader
=c
.user
, **request
.params
)
36 elixir
.session
.commit()
37 redirect(url('show_art', id=c
.art
.id))
38 except IntegrityError
:
39 # hurr, there must be a better way to do this but I am lazy right now
41 elixir
.session
.rollback()
42 duplicate_art
= Art
.get_by(hash=hash)
43 h
.flash("We already have that one.")
44 redirect(url('show_art', id=duplicate_art
.id))
48 # c.art = h.get_object_or_404(Art, id=id)
50 c
.your_score
= c
.art
.user_score(c
.user
)
51 return render("/art/show.mako")
54 # TODO: login required
56 # c.art = h.get_object_or_404(Art, id=id)
57 score
= request
.params
.get("score")
58 if score
and score
.isnumeric():
61 score
= Rating
.reverse_options
.get(score
)
63 c
.art
.rate(score
, c
.user
)
64 elixir
.session
.commit()
66 redirect(url('show_art', id=c
.art
.id))