~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/inventory_ui.py

  • Committer: Jelmer Vernooij
  • Date: 2011-11-02 01:56:02 UTC
  • mto: This revision was merged to the branch mainline in revision 458.
  • Revision ID: jelmer@samba.org-20111102015602-088uv5bi6m4ac2mr
Fix comment.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import posixpath
23
23
import urllib
24
24
 
25
 
from paste.httpexceptions import HTTPNotFound
 
25
from paste.httpexceptions import HTTPNotFound, HTTPMovedPermanently
26
26
 
27
27
from bzrlib import errors
28
28
from bzrlib.revision import is_null as is_null_rev
31
31
from loggerhead.controllers import TemplatedBranchView
32
32
 
33
33
 
34
 
log = logging.getLogger("loggerhead.controllers")
35
 
 
36
34
 
37
35
def dirname(path):
38
36
    if path is not None:
44
42
class InventoryUI(TemplatedBranchView):
45
43
 
46
44
    template_path = 'loggerhead.templates.inventory'
 
45
    supports_json = True
47
46
 
48
 
    def get_filelist(self, inv, path, sort_type):
 
47
    def get_filelist(self, inv, path, sort_type, revno_url):
49
48
        """
50
49
        return the list of all files (and their attributes) within a given
51
50
        path subtree.
58
57
        dir_ie = inv[file_id]
59
58
        file_list = []
60
59
 
 
60
        if dir_ie.kind != 'directory':
 
61
            raise HTTPMovedPermanently(self._branch.context_url(['/view', revno_url, path]))
 
62
 
61
63
        revid_set = set()
62
64
 
63
65
        for filename, entry in dir_ie.children.iteritems():
77
79
                absolutepath = path + '/' + pathname
78
80
            revid = entry.revision
79
81
 
 
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')
111
118
 
112
 
        # no navbar for revisions
113
 
        navigation = util.Container()
114
 
 
115
119
        if path is not None:
116
120
            path = path.rstrip('/')
117
121
            file_id = rev_tree.path2id(path)
132
136
        else:
133
137
            updir = dirname(path)
134
138
 
135
 
        # Directory Breadcrumbs
136
 
        directory_breadcrumbs = util.directory_breadcrumbs(
137
 
                self._branch.friendly_name,
138
 
                self._branch.is_root,
139
 
                'files')
140
 
 
141
139
        if not is_null_rev(revid):
142
 
 
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():
147
144
            else:
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)
150
148
 
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)
154
149
        else:
155
150
            start_revid = None
156
151
            change = None
157
152
            path = "/"
158
153
            updir = None
159
154
            revno_url = 'head:'
160
 
            branch_breadcrumbs = []
161
155
            filelist = []
162
156
 
163
157
        return {
164
 
            'branch': self._branch,
165
 
            'util': util,
166
158
            'revid': revid,
167
159
            'revno_url': revno_url,
168
160
            'change': change,
169
161
            'path': path,
170
162
            'updir': updir,
171
163
            'filelist': filelist,
172
 
            'navigation': navigation,
173
 
            'url': self._branch.context_url,
174
164
            'start_revid': start_revid,
 
165
        }
 
166
 
 
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,
 
173
                'files')
 
174
 
 
175
        path = values['path']
 
176
        revid = values['revid']
 
177
        # no navbar for revisions
 
178
        navigation = util.Container()
 
179
 
 
180
        if is_null_rev(revid):
 
181
            branch_breadcrumbs = []
 
182
        else:
 
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')
 
187
        values.update({
175
188
            'fileview_active': True,
176
189
            'directory_breadcrumbs': directory_breadcrumbs,
177
190
            'branch_breadcrumbs': branch_breadcrumbs,
178
 
        }
 
191
            'navigation': navigation,
 
192
        })