X-Git-Url: http://git.veekun.com/zzz-floof.git/blobdiff_plain/422dfbb85e3efd51efd676779012aeb3f9575ba4..fca6f64bc81a02c61ba45a13de25f3da2e7630b3:/floof/controllers/comments.py?ds=sidebyside diff --git a/floof/controllers/comments.py b/floof/controllers/comments.py new file mode 100644 index 0000000..03aee3d --- /dev/null +++ b/floof/controllers/comments.py @@ -0,0 +1,62 @@ +import logging + +import elixir +from pylons import config, request, response, session, tmpl_context as c +from pylons.controllers.util import abort, redirect, redirect_to + +from floof.lib.base import BaseController, render +from floof.model.art import Art +from floof.model.comments import Comment + +log = logging.getLogger(__name__) + +def find_owner(owner_url): + """Returns whatever thing owns a group of comments.""" + + # Need to prepend a slash to make this an absolute URL + route = config['routes.map'].match('/' + owner_url) + + if route['action'] not in ('show', 'view'): + abort(404) + + if route['controller'] == 'art': + model = Art + else: + abort(404) + + owner = model.query.get(route['id']) + if not owner: + abort(404) + + return owner + + +class CommentsController(BaseController): + + def thread(self, owner_url): + """View a thread of comments, either attached to an item or starting + from a parent comment belonging to that item. + """ + owner_object = find_owner(owner_url) + c.comments = owner_object.discussion.comments + return render('/comments/thread.mako') + + def reply(self, owner_url): + """Reply to a comment or discussion.""" + return render('/comments/reply.mako') + + def reply_done(self, owner_url): + """Finish replying to a comment or discussion.""" + # XXX form validation woo + + new_comment = Comment( + text=request.params['text'], + user=c.user, + ) + + owner_object = find_owner(owner_url) + discussion = owner_object.discussion + discussion.comments.append(new_comment) + elixir.session.commit() + + return redirect('/' + owner_url, code=301)