~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-12-08 03:50:24 UTC
  • mfrom: (1294.2.143 ui-the-third)
  • Revision ID: grantw@unimelb.edu.au-20091208035024-wjx8zp54gth15ph8
Merge ui-the-third. This is another UI revamp.

The header is now thin! Thin! The yellow bar is gone. The tabs are gone.
Breadcrumbs are here. Routes is replaced (with an object publishing
mechanism). Views are less repetitive. etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from ivle.webapp.base.xhtml import XHTMLErrorView
35
35
from ivle.webapp.base.plugins import ViewPlugin, PublicViewPlugin
36
36
from ivle.webapp.errors import NotFound, Unauthorized, Forbidden
 
37
from ivle.webapp import ApplicationRoot
37
38
 
38
39
class ServeView(BaseView):
39
 
    def __init__(self, req, path):
40
 
        self.path = path
 
40
    subpath_allowed = True
41
41
 
42
42
    def authorize(self, req):
43
43
        return req.user is not None
46
46
        """Handler for the Server application which serves pages."""
47
47
        # Get the username of the student whose work we are browsing, and the
48
48
        # path on the local machine where the file is stored.
49
 
        (login, jail, path) = studpath.url_to_jailpaths(req.config, self.path)
 
49
        (login, jail, path) = studpath.url_to_jailpaths(req.config,
 
50
                                                        self.path)
50
51
 
51
52
        owner = User.get_by_login(req.store, login)
52
53
        if not owner:
55
56
 
56
57
        self.serve(req, owner, jail, path)
57
58
 
 
59
    @property
 
60
    def path(self):
 
61
        return os.path.join(*self.subpath) if self.subpath else ''
 
62
 
58
63
    def serve(self, req, owner, jail, path):
59
64
        self.serve_file(req, owner, jail, path)
60
65
 
132
137
        req.write(out)
133
138
 
134
139
class DownloadView(ServeView):
135
 
    def __init__(self, req, path):
136
 
        super(DownloadView, self).__init__(req, path)
 
140
    def __init__(self, req, context, subpath=None):
 
141
        super(DownloadView, self).__init__(req, context, subpath)
137
142
        filelist = req.get_fieldstorage().getlist('path')
138
143
        if filelist:
139
144
            self.files = [f.value for f in filelist]
144
149
        self.serve_file(req, owner, jail, path, download=True,files=self.files)
145
150
 
146
151
class PublicServeView(ServeView):
147
 
    def __init__(self, req, path):
148
 
        req.path = path # XXX: Needed because we don't have an app prefix.
149
 
        super(PublicServeView, self).__init__(req, path)
 
152
    def __init__(self, req, context, subpath=None):
 
153
        # XXX: Prepend the username to the path, since the authorization
 
154
        # code expects that, but req.path drops the first path segment
 
155
        # for historical reasons.
 
156
        req.path = os.path.join(context.login, req.path)
 
157
        super(PublicServeView, self).__init__(req, context, subpath)
 
158
 
 
159
    @property
 
160
    def path(self):
 
161
        # XXX: Prepend the username again. See above for explanation.
 
162
        return os.path.join(
 
163
            self.context.login, super(PublicServeView, self).path)
150
164
 
151
165
    def authorize(self, req):
152
166
        # Only accessible in public mode.
158
172
        # in its parent directory.
159
173
        return studpath.authorize_public(req)
160
174
 
161
 
    # We don't want to redirect to a login page on Unauthorized.
162
 
    @classmethod
163
 
    def get_error_view(cls, e):
164
 
        return XHTMLErrorView
165
 
 
166
175
class Plugin(ViewPlugin, PublicViewPlugin):
167
 
    urls = [
168
 
        ('serve/*path', ServeView),
169
 
        ('download/*path', DownloadView),
170
 
    ]
 
176
    views = [(ApplicationRoot, 'serve', ServeView),
 
177
             (ApplicationRoot, 'download', DownloadView)
 
178
             ]
171
179
 
172
 
    public_urls = [
173
 
        ('~*path', PublicServeView),
174
 
    ]
 
180
    public_views = [(User, None, PublicServeView)]