5216da7d80365f5fdf8ed1a89510d4b28a43f652
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
.users
import User
12 from floof
.model
.art
import Art
, Rating
, UserRelation
13 from floof
.model
.comments
import Discussion
15 from sqlalchemy
.exceptions
import IntegrityError
18 class ArtController(BaseController
):
19 def __before__(self
, id=None):
20 super(ArtController
, self
).__before__()
21 # Awesome refactoring!
23 c
.art
= h
.get_object_or_404(Art
, id=id)
27 return render("/art/new.mako")
29 # TODO: login required
31 # if 'file' not in request.params or not request.params['file']:
32 # return "Validation Error: Needs a File"
35 c
.art
= Art(uploader
=c
.user
, **request
.params
)
36 c
.art
.discussion
= Discussion(count
=0)
39 artist
= User
.get_by(name
=request
.params
['artist'])
41 return "Validation Error: Artist not found"
43 relation
= UserRelation(user
=artist
, kind
="by", creator
=c
.user
, art
=c
.art
)
46 elixir
.session
.commit()
47 redirect(url('show_art', id=c
.art
.id))
48 except IntegrityError
:
49 # hurr, there must be a better way to do this but I am lazy right now
51 elixir
.session
.rollback()
52 duplicate_art
= Art
.get_by(hash=hash)
53 h
.flash("We already have that one.")
54 redirect(url('show_art', id=duplicate_art
.id))
58 # c.art = h.get_object_or_404(Art, id=id)
60 c
.your_score
= c
.art
.user_score(c
.user
)
61 return render("/art/show.mako")
64 # TODO: login required
66 # c.art = h.get_object_or_404(Art, id=id)
67 score
= request
.params
.get("score")
68 if score
and score
.isnumeric():
71 score
= Rating
.reverse_options
.get(score
)
73 c
.art
.rate(score
, c
.user
)
74 elixir
.session
.commit()
76 redirect(url('show_art', id=c
.art
.id))