~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-30 08:50:35 UTC
  • mfrom: (1297 ivle)
  • 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-20090730085035-np5s9ghrgymmya8b
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
# This maps a media namespace to an external dependency directory (in this
35
35
# case specified by the configuration option media/externals/jquery) and a
36
36
# list of permitted subpaths.
37
 
EXTERNAL_MEDIA_MAP = {'jquery': ('jquery', ['jquery.js']),
38
 
                      'codemirror': ('codemirror', None),
39
 
                      }
 
37
EXTERNAL_MEDIA_MAP = {'jquery': ('jquery', ['jquery.js'])}
40
38
 
41
39
def media_url(req, plugin, path):
42
40
    '''Generates a URL to a media file.
72
70
                return None
73
71
 
74
72
            # Unless it's a whitelisted path, we don't want to hear about it.
75
 
            # If the whitelist is None (not []), we allow all.
76
 
            if extern[1] is not None and self.path not in extern[1]:
 
73
            if self.path not in extern[1]:
77
74
                return None
78
75
 
79
76
            # Grab the admin-configured path for this particular external dep.
97
94
            return os.path.join(plugindir, mediadir, self.path)
98
95
 
99
96
class MediaFileView(BaseView):
100
 
    def authorize(self, req):
101
 
        return True
 
97
    permission = None
102
98
 
103
99
    def render(self, req):
104
100
        # If it begins with ".." or separator, it's illegal. Die.
106
102
           self.context.path.startswith('/'):
107
103
            raise Forbidden()
108
104
 
109
 
        filename = self.get_filename(req)
 
105
        filename = self.context.filename
110
106
        if filename is None:
111
107
            raise NotFound()
112
108
 
131
127
        req.content_type = type
132
128
        req.sendfile(filename)
133
129
 
134
 
    def get_filename(self, req):
135
 
        return self.context.filename
 
130
    def get_permissions(self, user):
 
131
        return set()
136
132
 
137
133
def root_to_media(root, *segments):
138
134
    if segments[0].startswith('+'):
164
160
class Plugin(ViewPlugin, PublicViewPlugin):
165
161
    forward_routes = [(ApplicationRoot, '+media', root_to_media, INF)]
166
162
    views = [(MediaFile, '+index', MediaFileView)]
167
 
    public_forward_routes = forward_routes
168
 
    public_views = views