93
by mattgiuca
New directory hierarchy. |
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: download
|
|
19 |
# Author: Matt Giuca
|
|
243
by mattgiuca
Added common/zip.py. Creates a zip file from paths in the student directory. |
20 |
# Date: 17/1/2008
|
93
by mattgiuca
New directory hierarchy. |
21 |
|
22 |
# Serves content to the user (acting as a web server for students files).
|
|
23 |
# Unlike "serve", all content is served as a static file, and with the
|
|
24 |
# application/octet-stream mime type.
|
|
25 |
# Also can serve directories or multiple files, automatically zipping them up.
|
|
720
by dcoles
download: Fixing the download button. |
26 |
# Uses a large chunk of code from "serve"
|
27 |
||
28 |
from common import studpath |
|
29 |
from apps import server |
|
243
by mattgiuca
Added common/zip.py. Creates a zip file from paths in the student directory. |
30 |
import StringIO |
93
by mattgiuca
New directory hierarchy. |
31 |
|
32 |
# Serve all files as application/octet-stream so the browser presents them as
|
|
33 |
# a download.
|
|
34 |
default_mimetype = "application/octet-stream" |
|
243
by mattgiuca
Added common/zip.py. Creates a zip file from paths in the student directory. |
35 |
zip_mimetype = "application/zip" |
93
by mattgiuca
New directory hierarchy. |
36 |
|
37 |
def handle(req): |
|
38 |
"""Handler for the Download application which serves files for
|
|
39 |
download."""
|
|
40 |
||
41 |
req.write_html_head_foot = False |
|
42 |
||
720
by dcoles
download: Fixing the download button. |
43 |
# Get the username of the student whose work we are browsing, and the path
|
44 |
# on the local machine where the file is stored.
|
|
45 |
(user, path) = studpath.url_to_local(req.path) |
|
46 |
||
47 |
if user is None: |
|
48 |
req.throw_error(req.HTTP_NOT_FOUND, |
|
49 |
"The path specified is invalid.") |
|
50 |
||
51 |
# Use the code from server to avoid duplication
|
|
52 |
server.serve_file(req, user, path, download=True) |