~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/changelog_ui.py

  • Committer: Michael Hudson
  • Date: 2007-05-30 09:03:52 UTC
  • mfrom: (128.1.15 testing)
  • Revision ID: michael.hudson@canonical.com-20070530090352-2hdhyvs7jxgpoz1e
merge in the fix for #92435 too

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
 
from paste.httpexceptions import HTTPServerError
 
20
import os
 
21
import time
 
22
 
 
23
import turbogears
 
24
from cherrypy import InternalError, session
21
25
 
22
26
from loggerhead import util
23
 
from loggerhead.controllers import TemplatedBranchView
24
 
 
25
 
 
26
 
class ChangeLogUI(TemplatedBranchView):
27
 
 
28
 
    template_path = 'loggerhead.templates.changelog'
29
 
 
30
 
    def get_values(self, h, args, kw, headers):
31
 
        if args:
 
27
 
 
28
 
 
29
class ChangeLogUI (object):
 
30
    
 
31
    def __init__(self, branch):
 
32
        # BranchView object
 
33
        self._branch = branch
 
34
        self.log = branch.log
 
35
        
 
36
    @util.strip_whitespace
 
37
    @turbogears.expose(html='loggerhead.templates.changelog')
 
38
    def default(self, *args, **kw):
 
39
        z = time.time()
 
40
        h = self._branch.get_history()
 
41
        config = self._branch.config
 
42
        
 
43
        if len(args) > 0:
32
44
            revid = h.fix_revid(args[0])
33
45
        else:
34
46
            revid = None
35
47
 
36
 
        filter_file_id = kw.get('filter_file_id', None)
 
48
        file_id = kw.get('file_id', None)
37
49
        query = kw.get('q', None)
38
50
        start_revid = h.fix_revid(kw.get('start_revid', None))
39
51
        orig_start_revid = start_revid
40
 
        pagesize = 20#int(config.get('pagesize', '20'))
 
52
        pagesize = int(config.get('pagesize', '20'))
41
53
        search_failed = False
42
 
 
 
54
        
43
55
        try:
44
 
            revid, start_revid, revid_list = h.get_view(
45
 
                revid, start_revid, filter_file_id, query)
 
56
            revid, start_revid, revid_list = h.get_view(revid, start_revid, file_id, query)
 
57
            kw['start_revid'] = start_revid
46
58
            util.set_context(kw)
47
 
 
 
59
            
48
60
            if (query is not None) and (len(revid_list) == 0):
49
61
                search_failed = True
50
62
 
51
63
            if len(revid_list) == 0:
52
64
                scan_list = revid_list
53
65
            else:
54
 
                if revid in revid_list: # XXX is this always true?
55
 
                    i = revid_list.index(revid)
56
 
                else:
57
 
                    i = None
58
 
                scan_list = revid_list[i:]
59
 
            change_list = scan_list[:pagesize]
60
 
            changes = list(h.get_changes(change_list))
61
 
            h.add_changes(changes)
 
66
                scan_list = revid_list[h.get_revid_sequence(revid_list, revid):]
 
67
            entry_list = scan_list[:pagesize]
 
68
            entries = h.get_changes(entry_list)
62
69
        except:
 
70
##             import sys
 
71
##             print sys.exc_info()[2]
 
72
##             import pdb; pdb.post_mortem(sys.exc_info()[2])
63
73
            self.log.exception('Exception fetching changes')
64
 
            raise HTTPServerError('Could not fetch changes')
 
74
            raise InternalError('Could not fetch changes')
65
75
 
66
 
        navigation = util.Container(
67
 
            pagesize=pagesize, revid=revid, start_revid=start_revid,
68
 
            revid_list=revid_list, filter_file_id=filter_file_id,
69
 
            scan_url='/changes', branch=self._branch, feed=True, history=h)
 
76
        navigation = util.Container(pagesize=pagesize, revid=revid, start_revid=start_revid, revid_list=revid_list,
 
77
                                    file_id=file_id, scan_url='/changes', branch=self._branch, feed=True)
70
78
        if query is not None:
71
79
            navigation.query = query
72
 
        util.fill_in_navigation(navigation)
73
 
 
 
80
        util.fill_in_navigation(h, navigation)
 
81
        
 
82
        entries = list(entries)
74
83
        # add parent & merge-point branch-nick info, in case it's useful
75
 
        h.get_branch_nicks(changes)
76
 
 
77
 
        # does every change on this page have the same committer?  if so,
78
 
        # tell the template to show committer info in the "details block"
79
 
        # instead of on each line.
80
 
        all_same_author = True
81
 
 
82
 
        if changes:
83
 
            author = changes[0].author
84
 
            for e in changes[1:]:
85
 
                if e.author != author:
86
 
                    all_same_author = False
87
 
                    break
88
 
 
89
 
        # Directory Breadcrumbs
90
 
        directory_breadcrumbs = (
91
 
            util.directory_breadcrumbs(
92
 
                self._branch.friendly_name,
93
 
                self._branch.is_root,
94
 
                'changes'))
95
 
 
96
 
        return {
 
84
        h.get_branch_nicks(entries)
 
85
 
 
86
        vals = {
97
87
            'branch': self._branch,
98
 
            'changes': changes,
 
88
            'changes': list(entries),
99
89
            'util': util,
100
90
            'history': h,
101
91
            'revid': revid,
102
92
            'navigation': navigation,
103
 
            'filter_file_id': filter_file_id,
 
93
            'file_id': file_id,
104
94
            'start_revid': start_revid,
105
95
            'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
106
96
            'query': query,
107
97
            'search_failed': search_failed,
108
 
            'all_same_author': all_same_author,
109
 
            'url': self._branch.context_url,
110
 
            'directory_breadcrumbs': directory_breadcrumbs,
111
98
        }
 
99
        h.flush_cache()
 
100
        self.log.info('/changes %r: %r secs' % (revid, time.time() - z))
 
101
        return vals