~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/revision_ui.py

  • Committer: Martin Albisetti
  • Date: 2008-10-24 17:54:06 UTC
  • mfrom: (230.1.2 pep8)
  • Revision ID: martin.albisetti@canonical.com-20081024175406-73bpc73m7pshat9c
PEP8 fixes

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
 
import os
23
 
import textwrap
24
 
import time
25
 
 
26
 
import turbogears
27
 
from cherrypy import HTTPRedirect, session
 
20
from paste.httpexceptions import HTTPServerError
28
21
 
29
22
from loggerhead import util
30
 
 
31
 
 
32
 
class RevisionUI (object):
33
 
 
34
 
    def __init__(self, branch):
35
 
        # BranchView object
36
 
        self._branch = branch
37
 
        self.log = branch.log
38
 
        
39
 
    @util.strip_whitespace
40
 
    @turbogears.expose(html='loggerhead.templates.revision')
41
 
    def default(self, *args, **kw):
42
 
        z = time.time()
43
 
        h = self._branch.get_history()
44
 
        util.set_context(kw)
45
 
        
 
23
from loggerhead.controllers import TemplatedBranchView
 
24
 
 
25
 
 
26
DEFAULT_LINE_COUNT_LIMIT = 3000
 
27
 
 
28
 
 
29
class RevisionUI(TemplatedBranchView):
 
30
 
 
31
    template_path = 'loggerhead.templates.revision'
 
32
 
 
33
    def get_values(self, h, args, kw, headers):
 
34
 
46
35
        if len(args) > 0:
47
36
            revid = h.fix_revid(args[0])
48
37
        else:
49
38
            revid = None
50
 
        
51
 
        file_id = kw.get('file_id', None)
 
39
 
 
40
        filter_file_id = kw.get('filter_file_id', None)
52
41
        start_revid = h.fix_revid(kw.get('start_revid', None))
53
42
        query = kw.get('q', None)
54
 
        remember = kw.get('remember', None)
55
 
        compare_revid = kw.get('compare_revid', None)
56
 
        
 
43
        remember = h.fix_revid(kw.get('remember', None))
 
44
        compare_revid = h.fix_revid(kw.get('compare_revid', None))
 
45
 
57
46
        try:
58
 
            revid, start_revid, revid_list = h.get_view(revid, start_revid, file_id, query)
59
 
        except Exception, x:
60
 
            self.log.error('Exception fetching changes: %s' % (x,))
61
 
            util.log_exception(self.log)
62
 
            raise HTTPRedirect(self._branch.url('/changes'))
63
 
        
64
 
        navigation = util.Container(revid_list=revid_list, revid=revid, start_revid=start_revid, file_id=file_id,
65
 
                                    pagesize=1, scan_url='/revision', branch=self._branch, feed=True)
 
47
            revid, start_revid, revid_list = h.get_view(revid,
 
48
                                                        start_revid,
 
49
                                                        filter_file_id,
 
50
                                                        query)
 
51
        except:
 
52
            self.log.exception('Exception fetching changes')
 
53
            raise HTTPServerError('Could not fetch changes')
 
54
 
 
55
        navigation = util.Container(
 
56
            revid_list=revid_list, revid=revid, start_revid=start_revid,
 
57
            filter_file_id=filter_file_id, pagesize=1,
 
58
            scan_url='/revision', branch=self._branch, feed=True, history=h)
66
59
        if query is not None:
67
60
            navigation.query = query
68
 
        util.fill_in_navigation(h, navigation)
 
61
        util.fill_in_navigation(navigation)
69
62
 
70
 
        if compare_revid is not None:
71
 
            change = h.get_diff(compare_revid, revid)
72
 
        else:
73
 
            change = h.get_changes([ revid ], get_diffs=True)[0]
 
63
        change = h.get_change_with_diff(revid, compare_revid)
74
64
        # add parent & merge-point branch-nick info, in case it's useful
75
 
        h.get_branch_nicks([ change ])
 
65
        h.get_branch_nicks([change])
 
66
 
 
67
        line_count_limit = DEFAULT_LINE_COUNT_LIMIT
 
68
        line_count = 0
 
69
        for file in change.changes.modified:
 
70
            for chunk in file.chunks:
 
71
                line_count += len(chunk.diff)
76
72
 
77
73
        # let's make side-by-side diff be the default
78
74
        side_by_side = not kw.get('unified', False)
79
75
        if side_by_side:
80
 
            h.add_side_by_side([ change ])
81
 
        
82
 
        vals = {
 
76
            h.add_side_by_side([change])
 
77
 
 
78
        # Directory Breadcrumbs
 
79
        directory_breadcrumbs = (
 
80
            util.directory_breadcrumbs(
 
81
                self._branch.friendly_name,
 
82
                self._branch.is_root,
 
83
                'changes'))
 
84
 
 
85
        return {
83
86
            'branch': self._branch,
84
87
            'revid': revid,
85
88
            'change': change,
86
89
            'start_revid': start_revid,
87
 
            'file_id': file_id,
 
90
            'filter_file_id': filter_file_id,
88
91
            'util': util,
89
92
            'history': h,
90
93
            'navigation': navigation,
92
95
            'remember': remember,
93
96
            'compare_revid': compare_revid,
94
97
            'side_by_side': side_by_side,
 
98
            'url': self._branch.context_url,
 
99
            'line_count': line_count,
 
100
            'line_count_limit': line_count_limit,
 
101
            'show_plain_diffs': line_count > line_count_limit,
 
102
            'directory_breadcrumbs': directory_breadcrumbs,
95
103
        }
96
 
        h.flush_cache()
97
 
        self.log.info('/revision: %r seconds' % (time.time() - z,))
98
 
        return vals