~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/changelog_ui.py

 * Make navigation links use revnos instead of revids
 * Don't always pass on start_revid. Why would we do that?

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 time
 
21
 
 
22
import turbogears
 
23
from cherrypy import InternalError
21
24
 
22
25
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, path, kwargs, headers):
31
 
        history = self._history
32
 
        revid = self.get_revid()
33
 
        filter_file_id = kwargs.get('filter_file_id', None)
34
 
        query = kwargs.get('q', None)
35
 
        start_revid = history.fix_revid(kwargs.get('start_revid', None))
36
 
        orig_start_revid = start_revid
37
 
        pagesize = 20#int(config.get('pagesize', '20'))
38
 
        search_failed = False
39
 
 
40
 
        if filter_file_id is None and path is not None:
41
 
            filter_file_id = history.get_file_id(revid, path)
42
 
 
 
26
from loggerhead.templatefunctions import templatefunctions
 
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='zpt: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
        h._branch.lock_read()
43
44
        try:
44
 
            revid, start_revid, revid_list = history.get_view(
45
 
                revid, start_revid, filter_file_id, query)
46
 
            util.set_context(kwargs)
47
 
 
48
 
            if (query is not None) and (len(revid_list) == 0):
49
 
                search_failed = True
50
 
 
51
 
            if len(revid_list) == 0:
52
 
                scan_list = revid_list
 
45
            if len(args) > 0:
 
46
                revid = h.fix_revid(args[0])
53
47
            else:
54
 
                if revid in revid_list: # XXX is this always true?
55
 
                    i = revid_list.index(revid)
 
48
                revid = None
 
49
 
 
50
            filter_file_id = kw.get('filter_file_id', None)
 
51
            query = kw.get('q', None)
 
52
            start_revid = h.fix_revid(kw.get('start_revid', None))
 
53
            orig_start_revid = start_revid
 
54
            pagesize = int(config.get('pagesize', '20'))
 
55
            search_failed = False
 
56
 
 
57
            try:
 
58
                revid, start_revid, revid_list = h.get_view(
 
59
                    revid, start_revid, filter_file_id, query)
 
60
                util.set_context(kw)
 
61
 
 
62
                if (query is not None) and (len(revid_list) == 0):
 
63
                    search_failed = True
 
64
 
 
65
                if len(revid_list) == 0:
 
66
                    scan_list = revid_list
56
67
                else:
57
 
                    i = None
58
 
                scan_list = revid_list[i:]
59
 
            change_list = scan_list[:pagesize]
60
 
            changes = list(history.get_changes(change_list))
61
 
            history.add_changes(changes)
62
 
        except:
63
 
            self.log.exception('Exception fetching changes')
64
 
            raise HTTPServerError('Could not fetch changes')
65
 
 
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=history)
70
 
        if query is not None:
71
 
            navigation.query = query
72
 
        util.fill_in_navigation(navigation)
73
 
 
74
 
        # add parent & merge-point branch-nick info, in case it's useful
75
 
        history.get_branch_nicks(changes)
76
 
 
77
 
        # Directory Breadcrumbs
78
 
        directory_breadcrumbs = (
79
 
            util.directory_breadcrumbs(
80
 
                self._branch.friendly_name,
81
 
                self._branch.is_root,
82
 
                'changes'))
83
 
 
84
 
        return {
85
 
            'branch': self._branch,
86
 
            'changes': changes,
87
 
            'util': util,
88
 
            'history': history,
89
 
            'revid': revid,
90
 
            'navigation': navigation,
91
 
            'filter_file_id': filter_file_id,
92
 
            'start_revid': start_revid,
93
 
            'viewing_from': (orig_start_revid is not None) and 
94
 
                            (orig_start_revid != history.last_revid),
95
 
            'query': query,
96
 
            'search_failed': search_failed,
97
 
            'url': self._branch.context_url,
98
 
            'directory_breadcrumbs': directory_breadcrumbs,
99
 
        }
 
68
                    if revid in revid_list: # XXX is this always true?
 
69
                        i = revid_list.index(revid)
 
70
                    else:
 
71
                        i = None
 
72
                    scan_list = revid_list[i:]
 
73
                change_list = scan_list[:pagesize]
 
74
                changes = list(h.get_changes(change_list))
 
75
                h.add_changes(changes)
 
76
            except:
 
77
                self.log.exception('Exception fetching changes')
 
78
                raise InternalError('Could not fetch changes')
 
79
 
 
80
            navigation = util.Container(
 
81
                pagesize=pagesize, revid=revid, start_revid=start_revid,
 
82
                revid_list=revid_list, filter_file_id=filter_file_id,
 
83
                scan_url='/changes', branch=self._branch, feed=True)
 
84
            if query is not None:
 
85
                navigation.query = query
 
86
            util.fill_in_navigation(navigation)
 
87
 
 
88
            # add parent & merge-point branch-nick info, in case it's useful
 
89
            h.get_branch_nicks(changes)
 
90
 
 
91
            # does every change on this page have the same committer?  if so,
 
92
            # tell the template to show committer info in the "details block"
 
93
            # instead of on each line.
 
94
            all_same_author = True
 
95
 
 
96
            if changes:
 
97
                author = changes[0].author
 
98
                for e in changes[1:]:
 
99
                    if e.author != author:
 
100
                        all_same_author = False
 
101
                        break
 
102
 
 
103
            def url(pathargs, **kw):
 
104
                return self._branch.url(pathargs, **kw)
 
105
 
 
106
            vals = {
 
107
                'branch': self._branch,
 
108
                'changes': changes,
 
109
                'util': util,
 
110
                'history': h,
 
111
                'revid': revid,
 
112
                'navigation': navigation,
 
113
                'filter_file_id': filter_file_id,
 
114
                'start_revid': start_revid,
 
115
                'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
 
116
                'query': query,
 
117
                'search_failed': search_failed,
 
118
                'all_same_author': all_same_author,
 
119
                'url': self._branch.context_url,
 
120
            }
 
121
            vals.update(templatefunctions)
 
122
            h.flush_cache()
 
123
            self.log.info('/changes %r: %r secs' % (revid, time.time() - z))
 
124
            return vals
 
125
        finally:
 
126
            h._branch.unlock()