PageRenderTime 113ms CodeModel.GetById 40ms app.highlight 35ms RepoModel.GetById 36ms app.codeStats 0ms

/kai/controllers/home.py

https://bitbucket.org/bbangert/kai/
Python | 68 lines | 54 code | 12 blank | 2 comment | 7 complexity | 6c25b691faae5f7cb23f662f3e92b1e0 MD5 | raw file
 1import logging
 2
 3from pylons import request, response, session, tmpl_context as c
 4from pylons.controllers.util import abort, redirect
 5
 6from kai.lib.base import BaseController, render
 7from kai.model import Article, Comment, Snippet, Paste
 8from kai.websetup import sync_db
 9
10log = logging.getLogger(__name__)
11
12class HomeController(BaseController):
13    def sync(self):
14        if not request.environ['toppcloud.internal']:
15            abort(404)
16        sync_db(c.db)
17
18    def index(self):
19        c.articles = list(Article.by_time(c.db, descending=True, limit=5))
20        c.snippets = list(Snippet.by_date(c.db, descending=True, limit=7))
21        c.pastes = list(Paste.by_time(c.db, descending=True, limit=5))
22        return render('/home/index.mako')
23    
24    def robots(self):
25        response.content_type = 'text/plain'
26        return render('/home/robots.mako')
27        
28    def history(self):
29        c.active_sub = 'History'
30        return render('/home/history.mako')
31
32    def features(self):
33        c.active_sub = 'Features'
34        return render('/home/features.mako')
35    
36    def search(self):
37        c.active_sub = 'Search'
38        return render('/search.mako')
39    
40    def community(self):
41        c.active_tab = 'Community'
42        c.active_sub = True
43        
44        # Load various latest data
45        c.snippets = list(Snippet.by_date(c.db, descending=True, limit=5))
46        c.pastes = list(Paste.by_time(c.db, descending=True, limit=10))
47        
48        # Pull comments and grab the docs with them for their info
49        comments = list(Comment.by_anytime(c.db, descending=True, limit=10))
50        commentdata = []
51        for comment_doc in comments:
52            comment = {}
53            comment['displayname'] = comment_doc.displayname or 'Anonymous'
54            comment['created'] = comment_doc.created
55            comment['email'] = comment_doc.email or 'anonymous'
56            comment['content'] = comment_doc.content
57            comment['id'] = comment_doc.id
58            doc = c.db.get(comment_doc.doc_id)
59            if doc['type'] == 'Traceback':
60                comment['title'] = '%s: %s' % (doc['exception_type'], doc['exception_value'])
61            else:
62                comment['title'] = doc.get('title', '-- No title --')
63            comment['type'] = doc['type']
64            comment['doc'] = doc
65            comment['doc_id'] = comment_doc.doc_id
66            commentdata.append(comment)
67        c.comments = commentdata
68        return render('/home/community.mako')