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
12 from floof
.model
.comments
import Discussion
14 from sqlalchemy
.exceptions
import IntegrityError
17 class ArtController(BaseController
):
18 def __before__(self
, id=None):
19 super(ArtController
, self
).__before__()
20 # Awesome refactoring!
22 c
.art
= h
.get_object_or_404(Art
, id=id)
25 # c.artwork = Art.query.order_by(Art.id.desc()).all()
30 return render("/art/new.mako")
32 # TODO: login required
34 c
.art
= Art(uploader
=c
.user
, **request
.params
)
35 c
.art
.discussion
= Discussion(count
=0)
38 elixir
.session
.commit()
39 redirect(url('show_art', id=c
.art
.id))
40 except IntegrityError
:
41 # hurr, there must be a better way to do this but I am lazy right now
43 elixir
.session
.rollback()
44 duplicate_art
= Art
.get_by(hash=hash)
45 h
.flash("We already have that one.")
46 redirect(url('show_art', id=duplicate_art
.id))
50 # c.art = h.get_object_or_404(Art, id=id)
52 c
.your_score
= c
.art
.user_score(c
.user
)
53 return render("/art/show.mako")
56 # TODO: login required
58 # c.art = h.get_object_or_404(Art, id=id)
59 score
= request
.params
.get("score")
60 if score
and score
.isnumeric():
63 score
= Rating
.reverse_options
.get(score
)
65 c
.art
.rate(score
, c
.user
)
66 elixir
.session
.commit()
68 redirect(url('show_art', id=c
.art
.id))