136
by mattgiuca
Added File Browser (browser) application. (Currently just stub). |
1 |
# IVLE
|
2 |
# Copyright (C) 2007-2008 The University of Melbourne
|
|
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 |
||
18 |
# App: File Browser
|
|
19 |
# Author: Matt Giuca
|
|
20 |
# Date: 9/1/2008
|
|
21 |
||
22 |
# The file browser application. Presents an Ajax-based interface to the
|
|
23 |
# student's subversion workspace.
|
|
185
by mattgiuca
Integrated the (second) Prototype browser (HTML+CSS but no code) into the main |
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).
|
|
136
by mattgiuca
Added File Browser (browser) application. (Currently just stub). |
27 |
|
595
by mattgiuca
browser: Removed the browser.js ability to generate path links at the top. |
28 |
import os.path |
29 |
import cgi |
|
30 |
||
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
31 |
from ivle import (util, studpath) |
32 |
import ivle.svn |
|
136
by mattgiuca
Added File Browser (browser) application. (Currently just stub). |
33 |
|
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
34 |
import genshi |
35 |
import genshi.core |
|
36 |
import genshi.template |
|
37 |
||
595
by mattgiuca
browser: Removed the browser.js ability to generate path links at the top. |
38 |
# url path for this app
|
39 |
THIS_APP = "files" |
|
40 |
||
136
by mattgiuca
Added File Browser (browser) application. (Currently just stub). |
41 |
def handle(req): |
42 |
"""Handler for the File Browser application."""
|
|
43 |
||
595
by mattgiuca
browser: Removed the browser.js ability to generate path links at the top. |
44 |
# Work out where we are browsing
|
45 |
browsepath = req.path |
|
46 |
if len(browsepath) == 0: |
|
47 |
# If no path specified, default to the user's home directory
|
|
752
by dcoles
Browser: Redirect to 'files/LOGIN' when URL is just 'files' rather than just |
48 |
redirectPath = util.make_path(os.path.join(THIS_APP,req.user.login)) |
49 |
req.throw_redirect(util.make_path(redirectPath)) |
|
595
by mattgiuca
browser: Removed the browser.js ability to generate path links at the top. |
50 |
|
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
51 |
ctx = genshi.template.Context() |
52 |
||
136
by mattgiuca
Added File Browser (browser) application. (Currently just stub). |
53 |
# Set request attributes
|
54 |
req.content_type = "text/html" |
|
383
by mattgiuca
Split media/browser/browser.css into 3 files (listing.css and editor.css). |
55 |
req.styles = [ |
56 |
"media/browser/browser.css", |
|
57 |
"media/browser/listing.css", |
|
58 |
"media/browser/editor.css", |
|
59 |
]
|
|
170
by mattgiuca
browser: Added CSS and JS files (not much in them). |
60 |
req.scripts = [ |
61 |
"media/common/json2.js", |
|
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
62 |
"media/common/codepress/codepress.js", |
171
by mattgiuca
Added "util.js" in common. Contains useful utility functions. |
63 |
"media/common/util.js", |
170
by mattgiuca
browser: Added CSS and JS files (not much in them). |
64 |
"media/browser/browser.js", |
209
by mattgiuca
browser.js: Split out dir-listing code into listing.js (it's going to get |
65 |
"media/browser/listing.js", |
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
66 |
"media/browser/editor.js", |
944
by dcoles
Special Home Directory: Work to create a special home directory that shows the |
67 |
"media/browser/specialhome.js", |
170
by mattgiuca
browser: Added CSS and JS files (not much in them). |
68 |
]
|
849
by dcoles
Browser: Ported Browser to the new scripts_init framework. Started to decouple |
69 |
req.scripts_init = [ |
70 |
"browser_init", |
|
71 |
]
|
|
713
by dcoles
browser: Added console and run button to allow Python files to be executed in |
72 |
|
136
by mattgiuca
Added File Browser (browser) application. (Currently just stub). |
73 |
req.write_html_head_foot = True # Have dispatch print head and foot |
595
by mattgiuca
browser: Removed the browser.js ability to generate path links at the top. |
74 |
# The page title should contain the name of the file being browsed
|
75 |
req.title = browsepath.rsplit('/', 1)[-1] |
|
136
by mattgiuca
Added File Browser (browser) application. (Currently just stub). |
76 |
|
609
by mattgiuca
browser: Now stats the file requested before doing anything else. |
77 |
_, localpath = studpath.url_to_local(browsepath) |
78 |
if localpath is None: |
|
79 |
req.throw_error(req.HTTP_NOT_FOUND, |
|
80 |
"The path specified is invalid.") |
|
81 |
||
136
by mattgiuca
Added File Browser (browser) application. (Currently just stub). |
82 |
# Start writing data
|
185
by mattgiuca
Integrated the (second) Prototype browser (HTML+CSS but no code) into the main |
83 |
|
835
by wagrant
Cleanup from the last revision. Don't pass isdir if not necessary. |
84 |
# FIXME: This isn't completely reliable! We're not inside the jail, so we
|
85 |
# can't know the type for sure. This is now only used for adding a / to the
|
|
86 |
# end of displayed paths, so I'm leaving this although it will often break.
|
|
609
by mattgiuca
browser: Now stats the file requested before doing anything else. |
87 |
isdir = os.path.isdir(localpath) |
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
88 |
ctx['isdir'] = isdir |
89 |
gen_path(req, browsepath, ctx) |
|
90 |
gen_actions(req, ctx) |
|
91 |
||
92 |
ctx['fileservice_action'] = util.make_path(os.path.join("fileservice", req.path)) |
|
93 |
ctx['filename'] = cgi.escape(req.path) |
|
94 |
||
95 |
loader = genshi.template.TemplateLoader(".", auto_reload=True) |
|
96 |
tmpl = loader.load(util.make_local_path("apps/browser/template.html")) |
|
97 |
||
98 |
req.write(tmpl.generate(ctx).render('html')) #'xhtml', doctype='xhtml')) |
|
99 |
||
100 |
#TODO: Move all this logic into the template
|
|
101 |
def gen_path(req, path, ctx): |
|
102 |
||
595
by mattgiuca
browser: Removed the browser.js ability to generate path links at the top. |
103 |
href_path = util.make_path(THIS_APP) |
104 |
nav_path = "" |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
105 |
revision = ivle.svn.revision_from_string( |
907
by wagrant
browser: Display the current revision next to the current path if the |
106 |
req.get_fieldstorage().getfirst('r')) |
107 |
try: |
|
108 |
revno = revision.number |
|
109 |
except: |
|
110 |
revno = None |
|
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
111 |
|
112 |
ctx['revno'] = revno |
|
113 |
||
595
by mattgiuca
browser: Removed the browser.js ability to generate path links at the top. |
114 |
# Create all of the paths
|
115 |
pathlist = path.split("/") |
|
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
116 |
ctx['paths'] = [] |
595
by mattgiuca
browser: Removed the browser.js ability to generate path links at the top. |
117 |
for path_seg in pathlist: |
118 |
if path_seg == "": |
|
119 |
continue
|
|
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
120 |
new_seg = {} |
121 |
||
122 |
nav_path = nav_path + path_seg |
|
595
by mattgiuca
browser: Removed the browser.js ability to generate path links at the top. |
123 |
href_path = href_path + '/' + path_seg |
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
124 |
|
125 |
new_seg['path'] = path_seg |
|
126 |
new_seg['nav_path'] = nav_path |
|
127 |
new_seg['href_path'] = href_path |
|
128 |
if revno is not None: |
|
129 |
new_seg['href_path'] += '?r=%d' % revno |
|
130 |
||
131 |
ctx['paths'].append(new_seg) |
|
132 |
||
133 |
||
134 |
def gen_actions(req, ctx): |
|
596
by mattgiuca
browser: In the Python code, writes out all required HTML contents for the top |
135 |
"""
|
136 |
Presents a set of links/buttons for the "actions1" row of the top bar.
|
|
137 |
This is always exactly the same - the JavaScript will customize it later.
|
|
138 |
"""
|
|
861
by wagrant
browser: Refactor the server side of actions1 generation. We now take |
139 |
# Set up our actions. The second field of each group is whether to disable
|
140 |
# the items by default.
|
|
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
141 |
ctx['moreactions'] = [ |
861
by wagrant
browser: Refactor the server side of actions1 generation. We now take |
142 |
('Publishing', True, [ |
143 |
('publish', ['Publish', 'Make it so this directory can be seen by anyone on the web']), |
|
144 |
('share', ['Share this file', 'Get a link to this published file, to give to friends']), |
|
864
by wagrant
browser: Fix moreactions' Submit option's name. |
145 |
('submit', ['Submit', 'Submit the selected files for an assignment']) |
861
by wagrant
browser: Refactor the server side of actions1 generation. We now take |
146 |
]),
|
147 |
('File actions', True, [ |
|
148 |
('rename', ['Rename', 'Change the name of this file']), |
|
149 |
('delete', ['Delete', 'Delete the selected files']), |
|
150 |
('copy', ['Copy', 'Prepare to copy the selected files to another directory']), |
|
151 |
('cut', ['Cut', 'Prepare to move the selected files to another directory']) |
|
152 |
]),
|
|
153 |
('Directory actions', False, [ |
|
154 |
('paste', ['Paste', 'Paste the copied or cut files into the current directory']), |
|
155 |
('newfile', ['New File', 'Open a new file for editing in the current directory']), |
|
156 |
('mkdir', ['New Directory', 'Make a new subdirectory in the current directory']), |
|
157 |
('upload', ['Upload File', 'Upload a file to the current directory']) |
|
158 |
]),
|
|
159 |
('Subversion', True, [ |
|
1086
by chadnickbok
This commit fixes issue #10 and part of issue #9 |
160 |
('svncut', ['Svn Cut', 'Prepare to move the selected files to another directory, maintaining history']), |
161 |
('svncopy', ['Svn Copy', 'Prepare to copy the selected files to another directory, maintaining history']), |
|
162 |
('svnadd', ['Add', 'Schedule the selected temporary files to be added permanently']), |
|
163 |
('svnremove', ['Remove', 'Schedule the selected permanent files to be removed']), |
|
164 |
('svndiff', ['Diff', 'View any changes to the selected file since its last committed state']), |
|
165 |
('svnrevert', ['Revert', 'Restore the selected files back to their last committed state']), |
|
166 |
('svnupdate', ['Update', 'Update your files with changes from the permanent repository']), |
|
167 |
('svncommit', ['Commit', 'Commit any changes to the permanent repository']), |
|
168 |
('svnresolved', ['Mark Resolved', 'Mark a conflicted file as being resolved']), |
|
169 |
('svnlog', ['View Log', 'View the log of commits of the selected file']), |
|
861
by wagrant
browser: Refactor the server side of actions1 generation. We now take |
170 |
])
|
171 |
]
|