1252
by William Grant
Move BrowserView's path segmentation/linking function into ivle.webapp.filesystem. |
1 |
# IVLE - Informatics Virtual Learning Environment
|
2 |
# Copyright (C) 2007-2009 The University of Melbourne
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17 |
||
18 |
"""Utility functions for filesystem views."""
|
|
19 |
||
1294.2.116
by William Grant
Merge from object-publishing. |
20 |
from ivle.webapp.publisher import ROOT |
1294.2.102
by William Grant
Replace the breadcrumb-h1 with proper breadcrumbs throughout the filesystem views. |
21 |
|
22 |
class FileBreadcrumb(object): |
|
23 |
def __init__(self, req, pathsegments, revno=None, final=False,suffix=None): |
|
24 |
self.req = req |
|
25 |
self.pathsegments = pathsegments |
|
26 |
self.revno = revno |
|
27 |
self.final = final |
|
28 |
self.suffix = suffix |
|
29 |
||
30 |
@property
|
|
31 |
def url(self): |
|
1294.2.118
by William Grant
Merge from object-publishing. |
32 |
url = self.req.publisher.generate(ROOT, None, ('files',) + |
1294.2.102
by William Grant
Replace the breadcrumb-h1 with proper breadcrumbs throughout the filesystem views. |
33 |
self.pathsegments) |
34 |
if self.revno is not None: |
|
35 |
url += '?r=%d' % self.revno |
|
36 |
return url |
|
37 |
||
38 |
@property
|
|
39 |
def text(self): |
|
40 |
text = self.pathsegments[-1] |
|
41 |
if self.final and self.revno is not None: |
|
42 |
text += (' (revision %d)' % self.revno) |
|
43 |
if self.suffix: |
|
44 |
text += ' ' + self.suffix |
|
45 |
return text |
|
46 |
||
47 |
def make_path_breadcrumbs(req, pathsegments, revno=None, suffix=None): |
|
48 |
"""Return breadcrumbs for the segments of the given path."""
|
|
49 |
||
50 |
crumbs = [] |
|
51 |
for i in range(1, len(pathsegments)): |
|
52 |
crumbs.append(FileBreadcrumb(req, pathsegments[:i], revno)) |
|
53 |
crumbs.append(FileBreadcrumb(req, pathsegments, revno, True, suffix)) |
|
54 |
return crumbs |