~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/filesystem/__init__.py

  • Committer: William Grant
  • Date: 2009-07-05 12:11:48 UTC
  • mto: (1294.4.2 ui-the-third)
  • mto: This revision was merged to the branch mainline in revision 1353.
  • Revision ID: grantw@unimelb.edu.au-20090705121148-9z2x7kk92ox2ncqi
Replace the breadcrumb-h1 with proper breadcrumbs throughout the filesystem views.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Utility functions for filesystem views."""
19
19
 
20
 
def make_path_segments(path, revno=None):
21
 
    """Return a dict representation of information about a paths segments.
22
 
 
23
 
    Splits a path into its segments, and returns useful paths and URLs
24
 
    for each segment.
25
 
    """
26
 
 
27
 
    href_path = '/files'
28
 
    nav_path = ""
29
 
 
30
 
    pathlist = path.split("/")
31
 
    paths = []
32
 
    for path_seg in pathlist:
33
 
        if path_seg == "":
34
 
            continue
35
 
        new_seg = {}
36
 
 
37
 
        nav_path = nav_path + '/' + path_seg
38
 
        href_path = href_path + '/' + path_seg
39
 
 
40
 
        new_seg['path'] = path_seg
41
 
        new_seg['nav_path'] = nav_path
42
 
        new_seg['href_path'] = href_path
43
 
        if revno is not None:
44
 
            new_seg['href_path'] += '?r=%d' % revno
45
 
 
46
 
        paths.append(new_seg)
47
 
    return paths
 
20
from ivle.webapp.routing import ROOT
 
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):
 
32
        url = self.req.router.generate(ROOT, None, ('files',) +
 
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