~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/inventory_ui.py

  • Committer: Robert Collins
  • Date: 2010-04-08 01:08:33 UTC
  • Revision ID: robertc@robertcollins.net-20100408010833-bdyut0exh4o7dk7a
Merge patch from Toshio Kuratomi to work with mod_wsgi - Content-Length must be strings.

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, HTTPMovedPermanently
 
25
from paste.httpexceptions import HTTPNotFound
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
 
34
36
 
35
37
def dirname(path):
36
38
    if path is not None:
42
44
class InventoryUI(TemplatedBranchView):
43
45
 
44
46
    template_path = 'loggerhead.templates.inventory'
45
 
    supports_json = True
46
47
 
47
 
    def get_filelist(self, inv, path, sort_type, revno_url):
 
48
    def get_filelist(self, inv, path, sort_type):
48
49
        """
49
50
        return the list of all files (and their attributes) within a given
50
51
        path subtree.
57
58
        dir_ie = inv[file_id]
58
59
        file_list = []
59
60
 
60
 
        if dir_ie.kind != 'directory':
61
 
            raise HTTPMovedPermanently(self._branch.context_url(['/view', revno_url, path]))
62
 
 
63
61
        revid_set = set()
64
62
 
65
63
        for filename, entry in dir_ie.children.iteritems():
79
77
                absolutepath = path + '/' + pathname
80
78
            revid = entry.revision
81
79
 
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.
87
80
            file = util.Container(
88
81
                filename=filename, executable=entry.executable,
89
82
                kind=entry.kind, absolutepath=absolutepath,
116
109
        start_revid = kwargs.get('start_revid', None)
117
110
        sort_type = kwargs.get('sort', 'filename')
118
111
 
 
112
        # no navbar for revisions
 
113
        navigation = util.Container()
 
114
 
119
115
        if path is not None:
120
116
            path = path.rstrip('/')
121
117
            file_id = rev_tree.path2id(path)
136
132
        else:
137
133
            updir = dirname(path)
138
134
 
 
135
        # Directory Breadcrumbs
 
136
        directory_breadcrumbs = util.directory_breadcrumbs(
 
137
                self._branch.friendly_name,
 
138
                self._branch.is_root,
 
139
                'files')
 
140
 
139
141
        if not is_null_rev(revid):
 
142
 
140
143
            change = history.get_changes([ revid ])[0]
141
144
            # If we're looking at the tip, use head: in the URL instead
142
145
            if revid == branch.last_revision():
144
147
            else:
145
148
                revno_url = history.get_revno(revid)
146
149
            history.add_branch_nicks(change)
147
 
            filelist = self.get_filelist(rev_tree.inventory, path, sort_type, revno_url)
148
150
 
 
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)
149
154
        else:
150
155
            start_revid = None
151
156
            change = None
152
157
            path = "/"
153
158
            updir = None
154
159
            revno_url = 'head:'
 
160
            branch_breadcrumbs = []
155
161
            filelist = []
156
162
 
157
163
        return {
 
164
            'branch': self._branch,
 
165
            'util': util,
158
166
            'revid': revid,
159
167
            'revno_url': revno_url,
160
168
            'change': change,
161
169
            'path': path,
162
170
            'updir': updir,
163
171
            'filelist': filelist,
 
172
            'navigation': navigation,
 
173
            'url': self._branch.context_url,
164
174
            '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({
188
175
            'fileview_active': True,
189
176
            'directory_breadcrumbs': directory_breadcrumbs,
190
177
            'branch_breadcrumbs': branch_breadcrumbs,
191
 
            'navigation': navigation,
192
 
        })
 
178
        }