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
13 from floof
.model
.users
import User
, UserRelationship
15 from sqlalchemy
import func
16 from sqlalchemy
.exceptions
import IntegrityError
17 from sqlalchemy
.orm
.exc
import NoResultFound
20 class ArtController(BaseController
):
21 def __before__(self
, id=None):
22 super(ArtController
, self
).__before__()
23 # Awesome refactoring!
25 c
.art
= h
.get_object_or_404(Art
, id=id)
29 return render("/art/new.mako")
31 # TODO: login required
33 c
.art
= Art(uploader
=c
.user
, **request
.params
)
34 c
.art
.discussion
= Discussion(count
=0)
37 elixir
.session
.commit()
38 redirect(url('show_art', id=c
.art
.id))
39 except IntegrityError
:
40 # hurr, there must be a better way to do this but I am lazy right now
42 elixir
.session
.rollback()
43 duplicate_art
= Art
.get_by(hash=hash)
44 h
.flash("We already have that one.")
45 redirect(url('show_art', id=duplicate_art
.id))
49 # c.art = h.get_object_or_404(Art, id=id)
51 c
.your_score
= c
.art
.user_score(c
.user
)
52 return render("/art/show.mako")
55 # TODO: login required
57 # c.art = h.get_object_or_404(Art, id=id)
58 score
= request
.params
.get("score")
59 if score
and score
.isnumeric():
62 score
= Rating
.reverse_options
.get(score
)
64 c
.art
.rate(score
, c
.user
)
65 elixir
.session
.commit()
67 redirect(url('show_art', id=c
.art
.id))
70 def watchstream(self
, name
):
71 """Watchstream for a certain user."""
73 c
.watching_user
= User
.query
.filter(func
.lower(User
.name
) == name
) \
78 # This user has watches which are users which have art
79 # XXX use artist, not uploader
80 c
.artwork
= Art
.query
.join(Art
.uploader
,
81 User
.target_of_relationships
) \
82 .filter(UserRelationship
.user_id
== c
.watching_user
.id)
84 return render('/index.mako')