1294.2.131
by William Grant
Restore SubjectMediaView. |
1 |
# IVLE
|
2 |
# Copyright (C) 2007-2009 The University of Melbourne
|
|
3 |
#
|
|
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.
|
|
8 |
#
|
|
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.
|
|
13 |
#
|
|
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
|
|
17 |
||
18 |
import os.path |
|
19 |
||
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 |
|
24 |
||
25 |
||
26 |
class SubjectMediaFile(object): |
|
27 |
"""A subject content media file.
|
|
28 |
||
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.
|
|
32 |
"""
|
|
33 |
||
34 |
def __init__(self, context, path): |
|
35 |
self.context = context |
|
36 |
self.path = path |
|
37 |
self.version = None |
|
38 |
||
39 |
@property
|
|
40 |
def filename(self): |
|
41 |
"""Calculate just the path under the subject content directory.
|
|
42 |
||
43 |
The view will work out the rest of the path from the config.
|
|
44 |
"""
|
|
45 |
subjectdir = os.path.join(self.context.short_name, 'media') |
|
46 |
return os.path.join(subjectdir, self.path) |
|
47 |
||
1544
by Matt Giuca
Added an argument 'config' to every single get_permissions method throughout the program. All calls to get_permissions pass a config. This is to allow per-site policy configurations on permissions. |
48 |
def get_permissions(self, user, config): |
49 |
return self.context.get_permissions(user, config) |
|
1294.2.131
by William Grant
Restore SubjectMediaView. |
50 |
|
51 |
||
52 |
class SubjectMediaView(MediaFileView): |
|
53 |
'''The view of subject media files.
|
|
54 |
||
55 |
URIs pointing here will just be served directly, from the subject's
|
|
56 |
media directory.
|
|
57 |
'''
|
|
58 |
permission = 'view' |
|
59 |
||
60 |
def get_filename(self, req): |
|
61 |
return os.path.join( |
|
62 |
req.config['paths']['data'], |
|
63 |
'content/subjects', self.context.filename) |
|
64 |
||
1544
by Matt Giuca
Added an argument 'config' to every single get_permissions method throughout the program. All calls to get_permissions pass a config. This is to allow per-site policy configurations on permissions. |
65 |
def get_permissions(self, user, config): |
66 |
return self.context.get_permissions(user, config) |
|
1294.2.131
by William Grant
Restore SubjectMediaView. |
67 |
|
68 |
||
69 |
@forward_route(Subject, '+media', argc=INF) |
|
70 |
def subject_to_media(subject, *segments): |
|
71 |
path = os.path.normpath(os.path.join(*segments)) |
|
72 |
||
73 |
return SubjectMediaFile(subject, path) |
|
74 |