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

« back to all changes in this revision

Viewing changes to ivle/webapp/fileservice/__init__.py

  • Committer: William Grant
  • Date: 2009-07-04 12:18:42 UTC
  • mto: (1294.4.2 ui-the-third)
  • mto: This revision was merged to the branch mainline in revision 1353.
  • Revision ID: grantw@unimelb.edu.au-20090704121842-z3flcsd3v390vwtd
Port fileservice.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
import ivle.interpret
34
34
from ivle.webapp.base.views import BaseView
35
35
from ivle.webapp.base.plugins import ViewPlugin
 
36
from ivle.webapp.urls import INF
 
37
from ivle.webapp import ApplicationRoot
 
38
 
 
39
class FileserviceFile(object):
 
40
    def __init__(self, root, path):
 
41
        self.root = root
 
42
        self.path = path
36
43
 
37
44
# XXX: Writes to req directly. This is a direct port of the legacy version.
38
45
#      This needs to be rewritten soon.
39
 
 
40
46
class FileserviceView(BaseView):
41
 
    def __init__(self, req, path):
42
 
        # XXX: Still depends on req.path internally.
43
 
        self.path = path
44
 
 
45
47
    def authorize(self, req):
46
48
        return req.user is not None
47
49
 
48
50
    def render(self, req):
49
51
        """Handler for the File Services application."""
50
 
        if len(self.path) == 0:
 
52
        if len(self.context.path) == 0:
51
53
            # If no path specified, default to the user's home directory
52
54
            req.throw_redirect(req.make_path(os.path.join('fileservice',
53
55
                                                          req.user.login)))
61
63
                                               'services/fileservice'),
62
64
                                  interp_object, gentle=False)
63
65
 
 
66
def root_to_fileservicefile(root, *path):
 
67
    return FileserviceFile(root, os.path.join(*path) if path else '')
 
68
 
64
69
class Plugin(ViewPlugin):
65
 
    urls = [
66
 
        ('fileservice/*path', FileserviceView),
67
 
        ('fileservice', FileserviceView, {'path': ''}),
68
 
    ]
 
70
    forward_routes = [(ApplicationRoot, 'fileservice',
 
71
                       root_to_fileservicefile, INF),
 
72
                      ]
 
73
    views = [(FileserviceFile, '+index', FileserviceView)]