29
29
from ivle.webapp.base.plugins import ViewPlugin, CookiePlugin, MediaPlugin
30
30
from ivle.webapp.base.xhtml import XHTMLView
31
from ivle.webapp.errors import NotFound
32
from ivle.webapp.filesystem import make_path_segments
35
from ivle import (util, studpath)
37
from ivle import studpath
38
40
class BrowserView(XHTMLView):
49
51
def populate(self, req, ctx):
50
52
if not hasattr(self, 'path'):
51
53
# If no path specified, default to the user's home directory
52
redirectPath = util.make_path(os.path.join('files', req.user.login))
53
req.throw_redirect(util.make_path(redirectPath))
54
redirectPath = req.make_path(os.path.join('files', req.user.login))
55
req.throw_redirect(redirectPath)
55
57
# Set request attributes
56
58
self.plugin_styles[Plugin] = ['browser.css',
85
revision = ivle.svn.revision_from_string(
86
req.get_fieldstorage().getfirst('r'))
88
revno = revision.number
83
92
ctx['isdir'] = isdir
84
self.gen_path(req, ctx)
95
ctx['paths'] = make_path_segments(req.path, revno)
85
97
self.gen_actions(req, ctx)
87
99
# The page title should contain the name of the file being browsed
88
100
ctx['title'] = self.path.rsplit('/', 1)[-1]
90
ctx['fileservice_action'] = util.make_path(os.path.join("fileservice",
102
ctx['fileservice_action'] = req.make_path(os.path.join("fileservice",
92
104
ctx['filename'] = cgi.escape(self.path)
94
106
#TODO: Move all this logic into the template
95
def gen_path(self, req, ctx):
97
href_path = util.make_path('files')
99
revision = ivle.svn.revision_from_string(
100
req.get_fieldstorage().getfirst('r'))
102
revno = revision.number
108
# Create all of the paths
109
pathlist = self.path.split("/")
111
for path_seg in pathlist:
116
nav_path = nav_path + path_seg
117
href_path = href_path + '/' + path_seg
119
new_seg['path'] = path_seg
120
new_seg['nav_path'] = nav_path
121
new_seg['href_path'] = href_path
122
if revno is not None:
123
new_seg['href_path'] += '?r=%d' % revno
125
ctx['paths'].append(new_seg)
127
107
def gen_actions(self, req, ctx):
129
109
Presents a set of links/buttons for the "actions1" row of the top bar.
135
115
('Publishing', True, [
136
116
('publish', ['Publish', 'Make it so this directory can be seen by anyone on the web']),
137
117
('share', ['Share this file', 'Get a link to this published file, to give to friends']),
138
('submit', ['Submit', 'Submit the selected files for an assignment'])
118
('submit', ['Submit', 'Submit the selected files for a project'])
140
120
('File actions', True, [
141
121
('rename', ['Rename', 'Change the name of this file']),