~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/revision_ui.py

  • Committer: Matt Nordhoff
  • Date: 2009-10-21 13:21:02 UTC
  • Revision ID: mnordhoff@mattnordhoff.com-20091021132102-t9zuspd8y52u8klr
Mention bug #348308 in NEWS.

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 simplejson
 
20
try:
 
21
    import simplejson
 
22
except ImportError:
 
23
    import json as simplejson
21
24
import urllib
22
25
 
23
26
from paste.httpexceptions import HTTPServerError
36
39
class RevisionUI(TemplatedBranchView):
37
40
 
38
41
    template_path = 'loggerhead.templates.revision'
39
 
    supports_json = True
40
42
 
41
43
    def get_values(self, path, kwargs, headers):
42
44
        h = self._history
45
47
        filter_file_id = kwargs.get('filter_file_id', None)
46
48
        start_revid = h.fix_revid(kwargs.get('start_revid', None))
47
49
        query = kwargs.get('q', None)
 
50
        remember = h.fix_revid(kwargs.get('remember', None))
48
51
        compare_revid = h.fix_revid(kwargs.get('compare_revid', None))
49
52
 
50
 
        # TODO: This try/except looks to date before real exception handling
51
 
        # and should be removed
52
53
        try:
53
54
            revid, start_revid, revid_list = h.get_view(revid,
54
55
                                                        start_revid,
57
58
        except:
58
59
            self.log.exception('Exception fetching changes')
59
60
            raise HTTPServerError('Could not fetch changes')
60
 
        # XXX: Some concern about namespace collisions. These are only stored
61
 
        # here so they can be expanded into the template later. Should probably
62
 
        # be stored in a specific dict/etc.
63
 
        self.revid_list = revid_list
64
 
        self.compare_revid = compare_revid
65
 
        self.path = path
66
 
        kwargs['start_revid'] = start_revid
 
61
 
 
62
        navigation = util.Container(
 
63
            revid_list=revid_list, revid=revid, start_revid=start_revid,
 
64
            filter_file_id=filter_file_id, pagesize=1,
 
65
            scan_url='/revision', branch=self._branch, feed=True, history=h)
 
66
        if query is not None:
 
67
            navigation.query = query
 
68
        util.fill_in_navigation(navigation)
67
69
 
68
70
        change = h.get_changes([revid])[0]
69
71
 
73
75
            file_changes = h.file_changes_for_revision_ids(
74
76
                compare_revid, change.revid)
75
77
 
76
 
        h.add_branch_nicks(change)
77
 
 
78
 
        if '.' in change.revno:
79
 
            # Walk "up" though the merge-sorted graph until we find a
80
 
            # revision with merge depth 0: this is the revision that merged
81
 
            # this one to mainline.
82
 
            ri = self._history._rev_info
83
 
            i = self._history._rev_indices[change.revid]
84
 
            while ri[i][0][2] > 0:
85
 
                i -= 1
86
 
            merged_in = ri[i][0][3]
87
 
        else:
88
 
            merged_in = None
89
 
 
90
 
        return {
91
 
            'revid': revid,
92
 
            'change': change,
93
 
            'file_changes': file_changes,
94
 
            'merged_in': merged_in,
95
 
        }
96
 
 
97
 
    def add_template_values(self, values):
98
 
        super(RevisionUI, self).add_template_values(values)
99
 
        remember = self._history.fix_revid(self.kwargs.get('remember', None))
100
 
        query = self.kwargs.get('q', None)
101
 
        filter_file_id = self.kwargs.get('filter_file_id', None)
102
 
        start_revid = self.kwargs['start_revid']
103
 
        navigation = util.Container(
104
 
            revid_list=self.revid_list, revid=values['revid'],
105
 
            start_revid=start_revid,
106
 
            filter_file_id=filter_file_id, pagesize=1,
107
 
            scan_url='/revision', branch=self._branch, feed=True,
108
 
            history=self._history)
109
 
        if query is not None:
110
 
            navigation.query = query
111
 
        util.fill_in_navigation(navigation)
112
 
        path = self.path
113
78
        if path in ('', '/'):
114
79
            path = None
115
80
 
116
 
 
117
 
        file_changes = values['file_changes']
118
81
        link_data = {}
119
82
        path_to_id = {}
120
83
        if path:
130
93
                    dq(item.new_revision), dq(item.old_revision), dq(item.file_id))
131
94
                path_to_id[item.filename] = 'diff-' + str(i)
132
95
 
 
96
        h.add_branch_nicks(change)
 
97
 
 
98
        if '.' in change.revno:
 
99
            # Walk "up" though the merge-sorted graph until we find a
 
100
            # revision with merge depth 0: this is the revision that merged
 
101
            # this one to mainline.
 
102
            ri = self._history._rev_info
 
103
            i = self._history._rev_indices[change.revid]
 
104
            while ri[i][0][2] > 0:
 
105
                i -= 1
 
106
            merged_in = ri[i][0][3]
 
107
        else:
 
108
            merged_in = None
 
109
 
133
110
        # Directory Breadcrumbs
134
111
        directory_breadcrumbs = (
135
112
            util.directory_breadcrumbs(
136
113
                self._branch.friendly_name,
137
114
                self._branch.is_root,
138
115
                'changes'))
139
 
        can_export = self._branch.export_tarballs
140
116
 
141
 
        values.update({
142
 
            'history': self._history,
 
117
        return {
 
118
            'branch': self._branch,
 
119
            'revid': revid,
 
120
            'change': change,
 
121
            'file_changes': file_changes,
 
122
            'diff_chunks': diff_chunks,
143
123
            'link_data': simplejson.dumps(link_data),
 
124
            'specific_path': path,
144
125
            'json_specific_path': simplejson.dumps(path),
145
126
            'path_to_id': simplejson.dumps(path_to_id),
146
 
            'directory_breadcrumbs': directory_breadcrumbs,
 
127
            'start_revid': start_revid,
 
128
            'filter_file_id': filter_file_id,
 
129
            'util': util,
 
130
            'history': h,
 
131
            'merged_in': merged_in,
147
132
            'navigation': navigation,
 
133
            'query': query,
148
134
            'remember': remember,
149
 
            'compare_revid': self.compare_revid,
150
 
            'filter_file_id': filter_file_id,
151
 
            'diff_chunks': diff_chunks,
152
 
            'query': query,
153
 
            'can_export': can_export,
154
 
            'specific_path': path,
155
 
            'start_revid': start_revid,
156
 
        })
 
135
            'compare_revid': compare_revid,
 
136
            'url': self._branch.context_url,
 
137
            'directory_breadcrumbs': directory_breadcrumbs,
 
138
        }