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
from ivle.webapp import ApplicationRoot
41
class BrowserFile(object):
42
def __init__(self, root, path):
39
46
class BrowserView(XHTMLView):
41
48
The view for the browser
48
55
return req.user is not None
50
57
def populate(self, req, ctx):
51
if not hasattr(self, 'path'):
58
if len(self.context.path) == 0:
52
59
# If no path specified, default to the user's home directory
53
60
redirectPath = req.make_path(os.path.join('files', req.user.login))
54
61
req.throw_redirect(redirectPath)
85
92
self.gen_actions(req, ctx)
87
94
# The page title should contain the name of the file being browsed
88
ctx['title'] = os.path.normpath(self.path).rsplit('/', 1)[-1]
95
ctx['title'] = os.path.normpath(self.context.path).rsplit('/', 1)[-1]
90
97
ctx['fileservice_action'] = req.make_path(os.path.join("fileservice",
92
ctx['filename'] = cgi.escape(self.path)
99
ctx['filename'] = cgi.escape(self.context.path)
94
101
#TODO: Move all this logic into the template
95
102
def gen_actions(self, req, ctx):
141
def root_to_browserfile(root, *path):
142
return BrowserFile(root, os.path.join(*path) if path else '')
144
class BrowserRedirectView(XHTMLView):
145
def authorize(self, req):
146
return req.user is not None
148
def render(self, req):
149
redirect_path = req.make_path(os.path.join('files', req.user.login))
150
req.throw_redirect(redirect_path)
134
152
class Plugin(ViewPlugin, CookiePlugin, MediaPlugin):
136
The Plugin class for the user plugin.
138
# Magic attribute: urls
139
# Sequence of pairs/triples of
140
# (regex str, handler class, kwargs dict)
141
# The kwargs dict is passed to the __init__ of the view object
143
('files/*(path)', BrowserView),
144
('files/', BrowserView),
153
forward_routes = [(ApplicationRoot, 'files', root_to_browserfile, INF)]
154
views = [(BrowserFile, '+index', BrowserView),
155
(ApplicationRoot, '+index', BrowserRedirectView),
149
159
('files', 'Files', 'Access and edit your files',