d598292d063627c1f0551ef38b485fb9d751e53d
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)
26 return render("/art/new.mako")
28 # TODO: login required
30 c
.art
= Art(uploader
=c
.user
, **request
.params
)
31 c
.art
.discussion
= Discussion(count
=0)
34 elixir
.session
.commit()
35 redirect(url('show_art', id=c
.art
.id))
36 except IntegrityError
:
37 # hurr, there must be a better way to do this but I am lazy right now
39 elixir
.session
.rollback()
40 duplicate_art
= Art
.get_by(hash=hash)
41 h
.flash("We already have that one.")
42 redirect(url('show_art', id=duplicate_art
.id))
46 # c.art = h.get_object_or_404(Art, id=id)
48 c
.your_score
= c
.art
.user_score(c
.user
)
49 return render("/art/show.mako")
52 # TODO: login required
54 # c.art = h.get_object_or_404(Art, id=id)
55 score
= request
.params
.get("score")
56 if score
and score
.isnumeric():
59 score
= Rating
.reverse_options
.get(score
)
61 c
.art
.rate(score
, c
.user
)
62 elixir
.session
.commit()
64 redirect(url('show_art', id=c
.art
.id))