kai / kai / controllers /

import logging

from paste.script.util.uuid import uuid4
from pylons import request, response, session, tmpl_context as c
from pylons.controllers.util import abort, redirect_to
from pylons.decorators import jsonify

from kai.lib.base import BaseController, render
from kai.model import Human, Traceback

log = logging.getLogger(__name__)

class TracebacksController(BaseController):
    def __before__(self):
        c.active_tab = 'Tools'
        c.active_sub = 'Tracebacks'
    def create(self):
        """Create a new traceback in the system, pegged to the current
        user ID and session ID"""
        tb = Traceback.from_xml(request.body)
        tb.uuid = uuid4()
        result = {}
        uuid = tb.uuid
        result['traceback'] = dict(, uuid=uuid)
        return result
    def reown(self, id):
        if 'uuid' not in request.GET:
        tb = Traceback.load(self.db, id) or abort(404)
        tb.session_id =
        if c.user:
            tb.displayname = c.user.displayname
            tb.human_id =
        tb.uuid = None
        return 'ok'
    def show(self, id):
        c.traceback = Traceback.load(self.db, id) or abort(404)
        if c.traceback.displayname:
   = Human.load(self.db, c.traceback.human_id)
        c.is_owner = c.traceback.is_owner(c.user, check_session=True)
        return render('/tracebacks/show.mako')