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

« back to all changes in this revision

Viewing changes to ivle/webapp/filesystem/browser/__init__.py

  • Committer: William Grant
  • Date: 2009-07-04 12:29:54 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-20090704122954-hckugmzgxvx9x4nt
Port the filebrowser too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from ivle.webapp.base.xhtml import XHTMLView
31
31
from ivle.webapp.errors import NotFound
32
32
from ivle.webapp.filesystem import make_path_segments
 
33
from ivle.webapp.urls import INF
 
34
from ivle.webapp import ApplicationRoot
33
35
 
34
36
import os.path
35
37
import cgi
36
38
 
37
39
import ivle.svn
38
40
 
 
41
class BrowserFile(object):
 
42
    def __init__(self, root, path):
 
43
        self.root = root
 
44
        self.path = path
 
45
 
39
46
class BrowserView(XHTMLView):
40
47
    """
41
48
    The view for the browser
48
55
        return req.user is not None
49
56
 
50
57
    def populate(self, req, ctx):
51
 
        if not hasattr(self, 'path'):
 
58
        if len(self.context.path) == 0:
52
59
            # If no path specified, default to the user's home directory
53
60
            redirectPath = req.make_path(os.path.join('files', req.user.login))
54
61
            req.throw_redirect(redirectPath)
85
92
        self.gen_actions(req, ctx)
86
93
 
87
94
        # The page title should contain the name of the file being browsed
88
 
        ctx['title'] = os.path.normpath(self.path).rsplit('/', 1)[-1]
 
95
        ctx['title'] = os.path.normpath(self.context.path).rsplit('/', 1)[-1]
89
96
 
90
97
        ctx['fileservice_action'] = req.make_path(os.path.join("fileservice",
91
 
                                                                self.path))
92
 
        ctx['filename'] = cgi.escape(self.path)
 
98
                                                            self.context.path))
 
99
        ctx['filename'] = cgi.escape(self.context.path)
93
100
 
94
101
    #TODO: Move all this logic into the template
95
102
    def gen_actions(self, req, ctx):
131
138
          ])
132
139
        ]
133
140
 
 
141
def root_to_browserfile(root, *path):
 
142
    return BrowserFile(root, os.path.join(*path) if path else '')
 
143
 
 
144
class BrowserRedirectView(XHTMLView):
 
145
    def authorize(self, req):
 
146
        return req.user is not None
 
147
 
 
148
    def render(self, req):
 
149
        redirect_path = req.make_path(os.path.join('files', req.user.login))
 
150
        req.throw_redirect(redirect_path)
 
151
 
134
152
class Plugin(ViewPlugin, CookiePlugin, MediaPlugin):
135
 
    """
136
 
    The Plugin class for the user plugin.
137
 
    """
138
 
    # Magic attribute: urls
139
 
    # Sequence of pairs/triples of
140
 
    # (regex str, handler class, kwargs dict)
141
 
    # The kwargs dict is passed to the __init__ of the view object
142
 
    urls = [
143
 
        ('files/*(path)', BrowserView),
144
 
        ('files/', BrowserView),
145
 
        ('/', BrowserView),
146
 
    ]
 
153
    forward_routes = [(ApplicationRoot, 'files', root_to_browserfile, INF)]
 
154
    views = [(BrowserFile, '+index', BrowserView),
 
155
             (ApplicationRoot, '+index', BrowserRedirectView),
 
156
             ]
147
157
 
148
158
    tabs = [
149
159
        ('files', 'Files', 'Access and edit your files',