PageRenderTime 233ms CodeModel.GetById 71ms app.highlight 8ms RepoModel.GetById 93ms app.codeStats 0ms

/kai/controllers/tracebacks.py

https://bitbucket.org/bbangert/kai/
Python | 67 lines | 56 code | 9 blank | 2 comment | 8 complexity | 4fff63e5a958a5bef16b66a01175a732 MD5 | raw file
 1import logging
 2
 3from paste.script.util.uuid import uuid4
 4from pylons import request, response, session, tmpl_context as c
 5from pylons.controllers.util import abort, redirect
 6from pylons.decorators import jsonify
 7
 8from kai.lib.base import BaseController, CMSObject, render
 9from kai.lib.helpers import success_flash
10from kai.model import Comment, Human, Traceback
11
12log = logging.getLogger(__name__)
13
14class TracebacksController(BaseController, CMSObject):
15    _cms_object = Traceback
16    
17    def __before__(self):
18        c.active_tab = 'Tools'
19        c.active_sub = 'Tracebacks'
20    
21    def index(self):
22        start = request.GET.get('start', '1')
23        startkey = request.GET.get('startkey')
24        prevkey = request.GET.get('prevkey')
25        if startkey:
26            c.tracebacks = Traceback.by_time(self.db, descending=True, startkey=startkey, limit=11)
27        elif prevkey:
28            c.tracebacks = Traceback.by_time(self.db, startkey=prevkey, limit=11)
29            c.reverse = True
30        else:
31            c.tracebacks = Traceback.by_time(self.db, descending=True, limit=11)
32        c.start = start
33        return render('/tracebacks/index.mako')
34    
35    @jsonify
36    def create(self):
37        """Create a new traceback in the system, pegged to the current
38        user ID and session ID"""
39        tb = Traceback.from_xml(request.body)
40        tb.uuid = uuid4()
41        tb.store(self.db)
42        result = {}
43        uuid = tb.uuid
44        result['traceback'] = dict(link=tb.id, uuid=uuid)
45        return result
46    
47    def reown(self, id):
48        if 'uuid' not in request.GET:
49            abort(500)
50        tb = Traceback.load(self.db, id) or abort(404)
51        session.save()
52        if c.user:
53            tb.displayname = c.user.displayname
54            tb.human_id = c.user.id
55            tb.email = c.user.email
56        else:
57            tb.session_id = session.id
58        tb.uuid = None
59        tb.store(self.db)
60        return 'ok'
61    
62    def show(self, id):
63        c.traceback = Traceback.load(self.db, id) or abort(404)
64        if c.traceback.displayname:
65            c.author = Human.load(self.db, c.traceback.human_id)
66        c.is_owner = self._check_owner(c.traceback, c.user, check_session=True)
67        return render('/tracebacks/show.mako')