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