~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-06 10:06:33 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-20090706100633-i5b9iwz4a4bjijpk
Shrink and unembolden h2s.

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.routing 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
70
70
                return None
71
71
 
72
72
            # Unless it's a whitelisted path, we don't want to hear about it.
73
 
            # If the whitelist is None (not []), we allow all.
74
 
            if extern[1] is not None and self.path not in extern[1]:
 
73
            if self.path not in extern[1]:
75
74
                return None
76
75
 
77
76
            # Grab the admin-configured path for this particular external dep.
95
94
            return os.path.join(plugindir, mediadir, self.path)
96
95
 
97
96
class MediaFileView(BaseView):
98
 
    def authorize(self, req):
99
 
        return True
 
97
    permission = None
100
98
 
101
99
    def render(self, req):
102
100
        # If it begins with ".." or separator, it's illegal. Die.
104
102
           self.context.path.startswith('/'):
105
103
            raise Forbidden()
106
104
 
107
 
        filename = self.get_filename(req)
 
105
        filename = self.context.filename
108
106
        if filename is None:
109
107
            raise NotFound()
110
108
 
129
127
        req.content_type = type
130
128
        req.sendfile(filename)
131
129
 
132
 
    def get_filename(self, req):
133
 
        return self.context.filename
 
130
    def get_permissions(self, user):
 
131
        return set()
134
132
 
135
133
def root_to_media(root, *segments):
136
134
    if segments[0].startswith('+'):
162
160
class Plugin(ViewPlugin, PublicViewPlugin):
163
161
    forward_routes = [(ApplicationRoot, '+media', root_to_media, INF)]
164
162
    views = [(MediaFile, '+index', MediaFileView)]
165
 
    public_forward_routes = forward_routes
166
 
    public_views = views