2
# Copyright (C) 2007-2009 The University of Melbourne
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
from ivle.database import Subject
21
from ivle.webapp.media import MediaFileView
22
from ivle.webapp.publisher import INF
23
from ivle.webapp.publisher.decorators import forward_route
26
class SubjectMediaFile(object):
27
"""A subject content media file.
29
Subject media can be dropped in
30
/var/lib/ivle/content/subjects/$shortname/media,
31
and will be served up at http://.../subjects/$shortname/+media.
34
def __init__(self, context, path):
35
self.context = context
41
"""Calculate just the path under the subject content directory.
43
The view will work out the rest of the path from the config.
45
subjectdir = os.path.join(self.context.short_name, 'media')
46
return os.path.join(subjectdir, self.path)
48
def get_permissions(self, user):
49
return self.context.get_permissions(user)
52
class SubjectMediaView(MediaFileView):
53
'''The view of subject media files.
55
URIs pointing here will just be served directly, from the subject's
60
def get_filename(self, req):
62
req.config['paths']['data'],
63
'content/subjects', self.context.filename)
65
def get_permissions(self, user):
66
return self.context.get_permissions(user)
69
@forward_route(Subject, '+media', argc=INF)
70
def subject_to_media(subject, *segments):
71
path = os.path.normpath(os.path.join(*segments))
73
return SubjectMediaFile(subject, path)