03aee3ddf74acd5003d2d4dbdb7c3cb88d18d03a
4 from pylons
import config
, request
, response
, session
, tmpl_context
as c
5 from pylons
.controllers
.util
import abort
, redirect
, redirect_to
7 from floof
.lib
.base
import BaseController
, render
8 from floof
.model
.art
import Art
9 from floof
.model
.comments
import Comment
11 log
= logging
.getLogger(__name__
)
13 def find_owner(owner_url
):
14 """Returns whatever thing owns a group of comments."""
16 # Need to prepend a slash to make this an absolute URL
17 route
= config
['routes.map'].match('/' + owner_url
)
19 if route
['action'] not in ('show', 'view'):
22 if route
['controller'] == 'art':
27 owner
= model
.query
.get(route
['id'])
34 class CommentsController(BaseController
):
36 def thread(self
, owner_url
):
37 """View a thread of comments, either attached to an item or starting
38 from a parent comment belonging to that item.
40 owner_object
= find_owner(owner_url
)
41 c
.comments
= owner_object
.discussion
.comments
42 return render('/comments/thread.mako')
44 def reply(self
, owner_url
):
45 """Reply to a comment or discussion."""
46 return render('/comments/reply.mako')
48 def reply_done(self
, owner_url
):
49 """Finish replying to a comment or discussion."""
50 # XXX form validation woo
52 new_comment
= Comment(
53 text
=request
.params
['text'],
57 owner_object
= find_owner(owner_url
)
58 discussion
= owner_object
.discussion
59 discussion
.comments
.append(new_comment
)
60 elixir
.session
.commit()
62 return redirect('/' + owner_url
, code
=301)