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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2009-07-04 13:26:01 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-20090704132601-ree3krvgipef4uqz
Move the already-ported filesystem views to use subpaths.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from ivle.webapp.base.xhtml import XHTMLView
31
31
from ivle.webapp.errors import NotFound
32
32
from ivle.webapp.filesystem import make_path_segments
33
 
from ivle.webapp.urls import INF
34
33
from ivle.webapp import ApplicationRoot
35
34
 
36
35
import os.path
38
37
 
39
38
import ivle.svn
40
39
 
41
 
class BrowserFile(object):
42
 
    def __init__(self, root, path):
43
 
        self.root = root
44
 
        self.path = path
45
 
 
46
40
class BrowserView(XHTMLView):
47
41
    """
48
42
    The view for the browser
51
45
    tab = 'files'
52
46
    help = 'Filesystem/Browser'
53
47
 
 
48
    subpath_allowed = True
 
49
 
54
50
    def authorize(self, req):
55
51
        return req.user is not None
56
52
 
57
53
    def populate(self, req, ctx):
58
 
        if len(self.context.path) == 0:
 
54
        if len(self.path) == 0:
59
55
            # If no path specified, default to the user's home directory
60
56
            redirectPath = req.make_path(os.path.join('files', req.user.login))
61
57
            req.throw_redirect(redirectPath)
92
88
        self.gen_actions(req, ctx)
93
89
 
94
90
        # The page title should contain the name of the file being browsed
95
 
        ctx['title'] = os.path.normpath(self.context.path).rsplit('/', 1)[-1]
 
91
        ctx['title'] = os.path.normpath(self.path).rsplit('/', 1)[-1]
96
92
 
97
93
        ctx['fileservice_action'] = req.make_path(os.path.join("fileservice",
98
 
                                                            self.context.path))
99
 
        ctx['filename'] = cgi.escape(self.context.path)
 
94
                                                               self.path))
 
95
        ctx['filename'] = cgi.escape(self.path)
 
96
 
 
97
    @property
 
98
    def path(self):
 
99
        return os.path.join(*self.subpath) if self.subpath else ''
100
100
 
101
101
    #TODO: Move all this logic into the template
102
102
    def gen_actions(self, req, ctx):
138
138
          ])
139
139
        ]
140
140
 
141
 
def root_to_browserfile(root, *path):
142
 
    return BrowserFile(root, os.path.join(*path) if path else '')
143
 
 
144
141
class BrowserRedirectView(XHTMLView):
145
142
    def authorize(self, req):
146
143
        return req.user is not None
150
147
        req.throw_redirect(redirect_path)
151
148
 
152
149
class Plugin(ViewPlugin, CookiePlugin, MediaPlugin):
153
 
    forward_routes = [(ApplicationRoot, 'files', root_to_browserfile, INF)]
154
 
    views = [(BrowserFile, '+index', BrowserView),
 
150
    views = [(ApplicationRoot, 'files', BrowserView),
155
151
             (ApplicationRoot, '+index', BrowserRedirectView),
156
152
             ]
157
153