~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/filesystem/serve/__init__.py

  • Committer: William Grant
  • Date: 2009-02-17 03:24:50 UTC
  • mto: (1099.1.143 new-dispatch)
  • mto: This revision was merged to the branch mainline in revision 1100.
  • Revision ID: grantw@unimelb.edu.au-20090217032450-r7z6k1k5i9urexe8
Support downloading of a selection of files as a zip.
Again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
        serve_file(req, owner, jail, path)
70
70
 
71
71
class DownloadView(ServeView):
 
72
    def __init__(self, req, path):
 
73
        super(DownloadView, self).__init__(req, path)
 
74
        filelist = req.get_fieldstorage().getlist('path')
 
75
        if filelist:
 
76
            self.files = [f.value for f in filelist]
 
77
        else:
 
78
            self.files = None
 
79
 
72
80
    def serve(self, req, owner, jail, path):
73
 
        serve_file(req, owner, jail, path, download=True)
 
81
        serve_file(req, owner, jail, path, download=True, files=self.files)
74
82
 
75
83
def authorize(req):
76
84
    """Given a request, checks whether req.username is allowed to
87
95
    # their own files, and can access all of them).
88
96
    return studpath.authorize(req, req.user)
89
97
 
90
 
def serve_file(req, owner, jail, path, download=False):
 
98
def serve_file(req, owner, jail, path, download=False, files=None):
91
99
    """Serves a file, using one of three possibilities: interpreting the file,
92
100
    serving it directly, or denying it and returning a 403 Forbidden error.
93
101
    No return value. Writes to req (possibly throwing a server error exception
110
118
    if not authorize(req):
111
119
        raise Unauthorized()
112
120
 
113
 
    args = [path]
 
121
    args = []
114
122
    if download:
115
 
        args.insert(0, '-d')
 
123
        args.append('-d')
 
124
 
 
125
    if files and download:
 
126
        args += [os.path.join(path, f) for f in files]
 
127
    else:
 
128
        args.append(path)
116
129
 
117
130
    # TODO: Download. Content-Disposition, etc.
118
131
    (out, err) = ivle.interpret.execute_raw(req.user, jail, '/home',