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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2009-12-08 03:50:24 UTC
  • mfrom: (1294.2.143 ui-the-third)
  • Revision ID: grantw@unimelb.edu.au-20091208035024-wjx8zp54gth15ph8
Merge ui-the-third. This is another UI revamp.

The header is now thin! Thin! The yellow bar is gone. The tabs are gone.
Breadcrumbs are here. Routes is replaced (with an object publishing
mechanism). Views are less repetitive. etc.

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):
 
49
        return self.context.get_permissions(user)
 
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):
 
66
        return self.context.get_permissions(user)
 
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