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

« back to all changes in this revision

Viewing changes to www/apps/browser/__init__.py

  • Committer: mattgiuca
  • Date: 2008-02-27 04:13:04 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:595
browser: Removed the browser.js ability to generate path links at the top.
    This is now done on the server side (since the client no longer navigates
    around).
    New topbar (work in progress) - now starts by the server generating the
    path links.
    Added trailing slash if it's a directory, which should fix the difficulty
    in realising a single path segment is actually a path (spotted by sb).

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
# simply presents static HTML and JavaScript, and all server-side activities
26
26
# take place in the FileService app (for handling Ajax requests).
27
27
 
 
28
import os.path
 
29
import cgi
 
30
 
28
31
from common import util
29
32
 
 
33
# url path for this app
 
34
THIS_APP = "files"
 
35
 
30
36
def handle(req):
31
37
    """Handler for the File Browser application."""
32
38
 
 
39
    # Work out where we are browsing
 
40
    browsepath = req.path
 
41
    if len(browsepath) == 0:
 
42
        # If no path specified, default to the user's home directory
 
43
        browsepath = req.user.login
 
44
 
33
45
    # Set request attributes
34
46
    req.content_type = "text/html"
35
47
    req.styles = [
46
58
        "media/browser/editor.js",
47
59
    ]
48
60
    req.write_html_head_foot = True     # Have dispatch print head and foot
 
61
    # The page title should contain the name of the file being browsed
 
62
    req.title = browsepath.rsplit('/', 1)[-1]
49
63
 
50
64
    # Start writing data
51
65
    req.write("""
52
66
<!-- Top bar section -->
53
67
 
54
68
<div id="topbar">
55
 
<h2>IVLE File Browser</h2>
56
 
<p id="path"></p>
 
69
  <div id="path">
 
70
    """)
 
71
    # TODO: Work out if this is a directory or not
 
72
    presentpath(req, browsepath, True)
 
73
    req.write("""
 
74
  </div>
 
75
  <div id="actions1"></div>
 
76
  <div id="actions2"></div>
57
77
</div>
58
78
<!-- End topbar -->
59
79
 
66
86
</html>
67
87
""")
68
88
 
 
89
def presentpath(req, path, isdir):
 
90
    """
 
91
    Presents a path list (address bar inside the page) for clicking.
 
92
    Writes to req, expecting to have just written the opening div containing
 
93
    the listing.
 
94
    """
 
95
    href_path = util.make_path(THIS_APP)
 
96
    nav_path = ""
 
97
 
 
98
    # Create all of the paths
 
99
    pathlist = path.split("/")
 
100
    segs_left = len(pathlist)
 
101
    for path_seg in pathlist:
 
102
        if path_seg == "":
 
103
            continue
 
104
        # Write a slash at the end unless this is the last path seg AND
 
105
        # it's not a directory.
 
106
        segs_left -= 1
 
107
        add_slash = segs_left != 0 or isdir
 
108
        # Make an 'a' element
 
109
        href_path = href_path + '/' + path_seg
 
110
        nav_path = nav_path + path_seg
 
111
        if add_slash:
 
112
            nav_path = nav_path + '/'
 
113
        link = '<a href="%s" title="Navigate to %s">%s</a>' % (
 
114
            href_path, nav_path, path_seg)
 
115
        req.write(link)
 
116
        if add_slash:
 
117
            req.write('/')