~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/annotate_ui.py

  • Committer: Michael Hudson
  • Date: 2008-07-28 05:26:13 UTC
  • mfrom: (128.13.91 new_theme_trunk)
  • Revision ID: michael.hudson@canonical.com-20080728052613-35uxs2xz28dsqdgz
merge the new theme created by Martin Albisetti
(this work sponsored by Canonical)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
#
19
19
 
20
 
import datetime
21
 
import logging
22
20
import os
23
21
import posixpath
24
 
import textwrap
25
 
import time
26
 
 
27
 
import turbogears
28
 
from cherrypy import HTTPRedirect, session
29
 
 
 
22
 
 
23
from paste.httpexceptions import HTTPBadRequest
 
24
 
 
25
from loggerhead.controllers import TemplatedBranchView
30
26
from loggerhead import util
31
27
 
32
28
 
33
 
log = logging.getLogger("loggerhead.controllers")
34
 
 
35
29
def dirname(path):
36
30
    while path.endswith('/'):
37
31
        path = path[:-1]
38
32
    path = posixpath.dirname(path)
39
33
    return path
40
34
 
41
 
        
42
 
class AnnotateUI (object):
43
 
 
44
 
    def __init__(self, branch):
45
 
        # BranchView object
46
 
        self._branch = branch
47
 
        self.log = branch.log
48
 
 
49
 
    @util.strip_whitespace
50
 
    @turbogears.expose(html='loggerhead.templates.annotate')
51
 
    def default(self, *args, **kw):
52
 
        z = time.time()
53
 
        h = self._branch.get_history()
54
 
        util.set_context(kw)
55
 
        
 
35
class AnnotateUI (TemplatedBranchView):
 
36
 
 
37
    template_path = 'loggerhead.templates.annotate'
 
38
 
 
39
    def get_values(self, h, args, kw, headers):
56
40
        if len(args) > 0:
57
41
            revid = h.fix_revid(args[0])
58
42
        else:
59
 
            revid = None
60
 
        
 
43
            revid = h.last_revid
 
44
 
 
45
        path = None
 
46
        if len(args) > 1:
 
47
            path = '/'.join(args[1:])
 
48
            if not path.startswith('/'):
 
49
                path = '/' + path
 
50
 
61
51
        file_id = kw.get('file_id', None)
 
52
        if (file_id is None) and (path is None):
 
53
            raise HTTPBadRequest('No file_id or filename provided to annotate')
 
54
 
62
55
        if file_id is None:
63
 
            raise HTTPRedirect(self._branch.url('/changes'))
 
56
            file_id = h.get_file_id(revid, path)
64
57
 
65
 
        try:
66
 
            revid_list, revid = h.get_file_view(revid, file_id)
67
 
        except Exception, x:
68
 
            self.log.error('Exception fetching changes: %s' % (x,))
69
 
            util.log_exception(self.log)
70
 
            raise HTTPRedirect(self._branch.url('/changes'))
71
 
            
72
58
        # no navbar for revisions
73
59
        navigation = util.Container()
74
 
        
75
 
        path = h.get_path(revid, file_id)
 
60
 
 
61
        if path is None:
 
62
            path = h.get_path(revid, file_id)
76
63
        filename = os.path.basename(path)
77
64
 
78
 
        vals = {
79
 
            'branch': self._branch,
80
 
            'util': util,
 
65
        return {
81
66
            'revid': revid,
82
67
            'file_id': file_id,
83
68
            'path': path,
84
69
            'filename': filename,
85
 
            'history': h,
86
70
            'navigation': navigation,
87
71
            'change': h.get_changes([ revid ])[0],
88
72
            'contents': list(h.annotate_file(file_id, revid)),
 
73
            'fileview_active': True,
89
74
        }
90
 
        h.flush_cache()
91
 
        self.log.info('/annotate: %r secs' % (time.time() - z,))
92
 
        return vals