1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
1 |
# IVLE - Informatics Virtual Learning Environment
|
2 |
# Copyright (C) 2007-2009 The University of Melbourne
|
|
136
by mattgiuca
Added File Browser (browser) application. (Currently just stub). |
3 |
#
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17 |
||
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
18 |
# Author: Matt Giuca, Nick Chadwick
|
19 |
||
20 |
"""
|
|
21 |
The file browser application. Presents an Ajax-based interface to the
|
|
22 |
student's subversion workspace.
|
|
23 |
||
24 |
Note that there is virtually no server-side code for this application. It
|
|
25 |
simply presents static HTML and JavaScript, and all server-side activities
|
|
26 |
take place in the FileService app (for handling Ajax requests).
|
|
27 |
"""
|
|
28 |
||
29 |
from ivle.webapp.base.plugins import BasePlugin |
|
1099.1.34
by William Grant
Split up ivle.webapp.base.views into ivle.webapp.base.{rest,xhtml}, as it was |
30 |
from ivle.webapp.base.xhtml import XHTMLView |
136
by mattgiuca
Added File Browser (browser) application. (Currently just stub). |
31 |
|
595
by mattgiuca
browser: Removed the browser.js ability to generate path links at the top. |
32 |
import os.path |
33 |
import cgi |
|
34 |
||
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
35 |
from ivle import (util, studpath) |
36 |
import ivle.svn |
|
136
by mattgiuca
Added File Browser (browser) application. (Currently just stub). |
37 |
|
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
38 |
class BrowserView(XHTMLView): |
39 |
"""
|
|
40 |
The view for the browser
|
|
41 |
"""
|
|
1099.1.35
by William Grant
ivle.webapp.base.xhtml#XHTMLView: Rename app_template to template (the things |
42 |
template = 'template.html' |
43 |
appname = 'files' |
|
1099.1.12
by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly |
44 |
|
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
45 |
def populate(self, req, ctx): |
1099.1.12
by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly |
46 |
if not hasattr(self, 'path'): |
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
47 |
# If no path specified, default to the user's home directory
|
1099.1.12
by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly |
48 |
redirectPath = util.make_path(os.path.join('files', req.user.login)) |
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
49 |
req.throw_redirect(util.make_path(redirectPath)) |
50 |
||
51 |
# Set request attributes
|
|
52 |
req.styles = [ |
|
53 |
"/media/browser/browser.css", |
|
54 |
"/media/browser/listing.css", |
|
55 |
"/media/browser/editor.css", |
|
56 |
]
|
|
57 |
req.scripts = [ |
|
58 |
"/media/common/json2.js", |
|
59 |
"/media/common/codepress/codepress.js", |
|
60 |
"/media/common/util.js", |
|
61 |
"/media/browser/browser.js", |
|
62 |
"/media/browser/listing.js", |
|
63 |
"/media/browser/editor.js", |
|
64 |
"/media/browser/specialhome.js", |
|
65 |
]
|
|
66 |
req.scripts_init = [ |
|
67 |
"browser_init", |
|
68 |
]
|
|
69 |
||
70 |
# The page title should contain the name of the file being browsed
|
|
71 |
req.title = self.path.rsplit('/', 1)[-1] |
|
72 |
||
73 |
_, localpath = studpath.url_to_local(self.path) |
|
74 |
if localpath is None: |
|
75 |
req.throw_error(req.HTTP_NOT_FOUND, |
|
76 |
"The path specified is invalid.") |
|
77 |
||
78 |
# Start writing data
|
|
79 |
||
80 |
# FIXME: This isn't completely reliable! We're not inside the jail, so we
|
|
81 |
# can't know the type for sure. This is now only used for adding a / to the
|
|
82 |
# end of displayed paths, so I'm leaving this although it will often break.
|
|
83 |
isdir = os.path.isdir(localpath) |
|
84 |
ctx['isdir'] = isdir |
|
85 |
self.gen_path(req, ctx) |
|
86 |
self.gen_actions(req, ctx) |
|
1099.1.12
by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly |
87 |
|
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
88 |
ctx['fileservice_action'] = util.make_path(os.path.join("fileservice", req.path)) |
89 |
ctx['filename'] = cgi.escape(req.path) |
|
90 |
||
1099.1.12
by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly |
91 |
#TODO: Move all this logic into the template
|
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
92 |
def gen_path(self, req, ctx): |
93 |
||
94 |
href_path = util.make_path('files') |
|
95 |
nav_path = "" |
|
96 |
revision = ivle.svn.revision_from_string( |
|
97 |
req.get_fieldstorage().getfirst('r')) |
|
1099.1.12
by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly |
98 |
try: |
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
99 |
revno = revision.number |
100 |
except: |
|
101 |
revno = None |
|
1099.1.12
by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly |
102 |
|
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
103 |
ctx['revno'] = revno |
1099.1.12
by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly |
104 |
|
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
105 |
# Create all of the paths
|
106 |
pathlist = self.path.split("/") |
|
107 |
ctx['paths'] = [] |
|
108 |
for path_seg in pathlist: |
|
109 |
if path_seg == "": |
|
110 |
continue
|
|
111 |
new_seg = {} |
|
1099.1.12
by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly |
112 |
|
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
113 |
nav_path = nav_path + path_seg |
114 |
href_path = href_path + '/' + path_seg |
|
1099.1.12
by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly |
115 |
|
116 |
new_seg['path'] = path_seg |
|
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
117 |
new_seg['nav_path'] = nav_path |
118 |
new_seg['href_path'] = href_path |
|
119 |
if revno is not None: |
|
120 |
new_seg['href_path'] += '?r=%d' % revno |
|
1099.1.12
by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly |
121 |
|
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
122 |
ctx['paths'].append(new_seg) |
123 |
||
124 |
def gen_actions(self, req, ctx): |
|
125 |
"""
|
|
126 |
Presents a set of links/buttons for the "actions1" row of the top bar.
|
|
127 |
This is always exactly the same - the JavaScript will customize it later.
|
|
128 |
"""
|
|
129 |
# Set up our actions. The second field of each group is whether to disable
|
|
130 |
# the items by default.
|
|
131 |
ctx['moreactions'] = [ |
|
132 |
('Publishing', True, [ |
|
133 |
('publish', ['Publish', 'Make it so this directory can be seen by anyone on the web']), |
|
134 |
('share', ['Share this file', 'Get a link to this published file, to give to friends']), |
|
135 |
('submit', ['Submit', 'Submit the selected files for an assignment']) |
|
136 |
]),
|
|
137 |
('File actions', True, [ |
|
138 |
('rename', ['Rename', 'Change the name of this file']), |
|
139 |
('delete', ['Delete', 'Delete the selected files']), |
|
140 |
('copy', ['Copy', 'Prepare to copy the selected files to another directory']), |
|
141 |
('cut', ['Cut', 'Prepare to move the selected files to another directory']) |
|
142 |
]),
|
|
143 |
('Directory actions', False, [ |
|
144 |
('paste', ['Paste', 'Paste the copied or cut files into the current directory']), |
|
145 |
('newfile', ['New File', 'Open a new file for editing in the current directory']), |
|
146 |
('mkdir', ['New Directory', 'Make a new subdirectory in the current directory']), |
|
147 |
('upload', ['Upload File', 'Upload a file to the current directory']) |
|
148 |
]),
|
|
149 |
('Subversion', True, [ |
|
150 |
('svncut', ['Svn Cut', 'Prepare to move the selected files to another directory, maintaining history']), |
|
151 |
('svncopy', ['Svn Copy', 'Prepare to copy the selected files to another directory, maintaining history']), |
|
152 |
('svnadd', ['Add', 'Schedule the selected temporary files to be added permanently']), |
|
153 |
('svnremove', ['Remove', 'Schedule the selected permanent files to be removed']), |
|
154 |
('svndiff', ['Diff', 'View any changes to the selected file since its last committed state']), |
|
155 |
('svnrevert', ['Revert', 'Restore the selected files back to their last committed state']), |
|
156 |
('svnupdate', ['Update', 'Update your files with changes from the permanent repository']), |
|
157 |
('svncommit', ['Commit', 'Commit any changes to the permanent repository']), |
|
158 |
('svnresolved', ['Mark Resolved', 'Mark a conflicted file as being resolved']), |
|
159 |
('svnlog', ['View Log', 'View the log of commits of the selected file']), |
|
160 |
])
|
|
161 |
]
|
|
1099.1.12
by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly |
162 |
|
1099.1.10
by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser. |
163 |
class Plugin(BasePlugin): |
164 |
"""
|
|
165 |
The Plugin class for the user plugin.
|
|
166 |
"""
|
|
167 |
# Magic attribute: urls
|
|
168 |
# Sequence of pairs/triples of
|
|
169 |
# (regex str, handler class, kwargs dict)
|
|
170 |
# The kwargs dict is passed to the __init__ of the view object
|
|
171 |
urls = [ |
|
172 |
('files/*(path)', BrowserView), |
|
173 |
('files/', BrowserView), |
|
174 |
]
|