~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/tutorial/media.py

  • Committer: mattgiuca
  • Date: 2007-12-19 06:01:34 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:85
common/studpath.py: Added url_to_jailpaths.
apps/server: Rewrote parts to now get the UserID and paths relative to jail,
    and pass those off to the interpreter. The interpreter is no longer
    python, but one relative to IVLE (our trampoline). (Currently a test one).
Added bin/tramptest trampoline, called by server temporarily. Just prints out
    its arguments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
48
 
    def get_permissions(self, user, config):
49
 
        return self.context.get_permissions(user, config)
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
 
 
65
 
    def get_permissions(self, user, config):
66
 
        return self.context.get_permissions(user, config)
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