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

« back to all changes in this revision

Viewing changes to ivle/webapp/media.py

  • Committer: William Grant
  • Date: 2009-07-04 08:08:25 UTC
  • mto: (1294.4.2 ui-the-third)
  • mto: This revision was merged to the branch mainline in revision 1353.
  • Revision ID: grantw@unimelb.edu.au-20090704080825-1t3l832ep4bjpkg6
Make tests pass.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from ivle.webapp.base.views import BaseView
29
29
from ivle.webapp.base.plugins import PublicViewPlugin, ViewPlugin, MediaPlugin
30
30
from ivle.webapp.errors import NotFound, Forbidden
31
 
from ivle.webapp.publisher import INF
 
31
from ivle.webapp.urls import INF
32
32
from ivle.webapp import ApplicationRoot
33
33
 
34
34
# This maps a media namespace to an external dependency directory (in this
96
96
class MediaFileView(BaseView):
97
97
    permission = None
98
98
 
 
99
    def __init__(self, req, context):
 
100
        self.context = context
 
101
 
99
102
    def render(self, req):
100
103
        # If it begins with ".." or separator, it's illegal. Die.
101
104
        if self.context.path.startswith("..") or \
102
105
           self.context.path.startswith('/'):
103
106
            raise Forbidden()
104
107
 
105
 
        filename = self.get_filename(req)
 
108
        filename = self.context.filename
106
109
        if filename is None:
107
110
            raise NotFound()
108
111
 
127
130
        req.content_type = type
128
131
        req.sendfile(filename)
129
132
 
130
 
    def get_filename(self, req):
131
 
        return self.context.filename
132
 
 
133
 
    def get_permissions(self, user, config):
 
133
    def get_permissions(self, user):
134
134
        return set()
135
135
 
136
136
def root_to_media(root, *segments):
153
153
        path = segments
154
154
 
155
155
    if version is not None and version != root.config['media']['version']:
156
 
        return None
 
156
        raise RoutingError()
157
157
 
158
158
    ns = path[0]
159
159
    path = os.path.normpath(os.path.join(*path[1:]))
163
163
class Plugin(ViewPlugin, PublicViewPlugin):
164
164
    forward_routes = [(ApplicationRoot, '+media', root_to_media, INF)]
165
165
    views = [(MediaFile, '+index', MediaFileView)]
166
 
    public_forward_routes = forward_routes
167
 
    public_views = views