25
from paste.httpexceptions import HTTPNotFound
25
from paste.httpexceptions import HTTPNotFound, HTTPMovedPermanently
27
27
from bzrlib import errors
28
28
from bzrlib.revision import is_null as is_null_rev
44
42
class InventoryUI(TemplatedBranchView):
46
44
template_path = 'loggerhead.templates.inventory'
48
def get_filelist(self, inv, path, sort_type):
47
def get_filelist(self, inv, path, sort_type, revno_url):
50
49
return the list of all files (and their attributes) within a given
58
57
dir_ie = inv[file_id]
60
if dir_ie.kind != 'directory':
61
raise HTTPMovedPermanently(self._branch.context_url(['/view', revno_url, path]))
63
65
for filename, entry in dir_ie.children.iteritems():
77
79
absolutepath = path + '/' + pathname
78
80
revid = entry.revision
82
# TODO: For the JSON rendering, this inlines the "change" aka
83
# revision information attached to each file. Consider either
84
# pulling this out as a separate changes dict, or possibly just
85
# including the revision id and having a separate request to get
86
# back the revision info.
80
87
file = util.Container(
81
88
filename=filename, executable=entry.executable,
82
89
kind=entry.kind, absolutepath=absolutepath,
109
116
start_revid = kwargs.get('start_revid', None)
110
117
sort_type = kwargs.get('sort', 'filename')
112
# no navbar for revisions
113
navigation = util.Container()
115
119
if path is not None:
116
120
path = path.rstrip('/')
117
121
file_id = rev_tree.path2id(path)
133
137
updir = dirname(path)
135
# Directory Breadcrumbs
136
directory_breadcrumbs = util.directory_breadcrumbs(
137
self._branch.friendly_name,
138
self._branch.is_root,
141
139
if not is_null_rev(revid):
143
140
change = history.get_changes([ revid ])[0]
144
141
# If we're looking at the tip, use head: in the URL instead
145
142
if revid == branch.last_revision():
148
145
revno_url = history.get_revno(revid)
149
146
history.add_branch_nicks(change)
147
filelist = self.get_filelist(rev_tree.inventory, path, sort_type, revno_url)
151
# Create breadcrumb trail for the path within the branch
152
branch_breadcrumbs = util.branch_breadcrumbs(path, rev_tree, 'files')
153
filelist = self.get_filelist(rev_tree.inventory, path, sort_type)
155
150
start_revid = None
159
154
revno_url = 'head:'
160
branch_breadcrumbs = []
164
'branch': self._branch,
167
159
'revno_url': revno_url,
168
160
'change': change,
171
163
'filelist': filelist,
172
'navigation': navigation,
173
'url': self._branch.context_url,
174
164
'start_revid': start_revid,
167
def add_template_values(self, values):
168
super(InventoryUI, self).add_template_values(values)
169
# Directory Breadcrumbs
170
directory_breadcrumbs = util.directory_breadcrumbs(
171
self._branch.friendly_name,
172
self._branch.is_root,
175
path = values['path']
176
revid = values['revid']
177
# no navbar for revisions
178
navigation = util.Container()
180
if is_null_rev(revid):
181
branch_breadcrumbs = []
183
# Create breadcrumb trail for the path within the branch
184
branch = self._history._branch
185
rev_tree = branch.repository.revision_tree(revid)
186
branch_breadcrumbs = util.branch_breadcrumbs(path, rev_tree, 'files')
175
188
'fileview_active': True,
176
189
'directory_breadcrumbs': directory_breadcrumbs,
177
190
'branch_breadcrumbs': branch_breadcrumbs,
191
'navigation': navigation,