~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-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:
29
29
from ivle.webapp.base.plugins import ViewPlugin, CookiePlugin, MediaPlugin
30
30
from ivle.webapp.base.xhtml import XHTMLView
31
31
from ivle.webapp.errors import NotFound
32
 
from ivle.webapp.filesystem import make_path_segments
 
32
from ivle.webapp.filesystem import make_path_breadcrumbs
 
33
from ivle.webapp import ApplicationRoot
33
34
 
34
35
import os.path
35
36
import cgi
43
44
    template = 'template.html'
44
45
    tab = 'files'
45
46
    help = 'Filesystem/Browser'
 
47
    breadcrumb_text = 'Files'
 
48
 
 
49
    subpath_allowed = True
46
50
 
47
51
    def authorize(self, req):
48
52
        return req.user is not None
49
53
 
50
54
    def populate(self, req, ctx):
51
 
        if not hasattr(self, 'path'):
 
55
        if len(self.path) == 0:
52
56
            # If no path specified, default to the user's home directory
53
57
            redirectPath = req.make_path(os.path.join('files', req.user.login))
54
58
            req.throw_redirect(redirectPath)
80
84
        ctx['isdir'] = isdir
81
85
        ctx['revno'] = revno
82
86
 
83
 
        ctx['paths'] = make_path_segments(self.path, revno)
 
87
        self.extra_breadcrumbs = make_path_breadcrumbs(req, self.subpath,revno)
84
88
 
85
89
        self.gen_actions(req, ctx)
86
90
 
88
92
        ctx['title'] = os.path.normpath(self.path).rsplit('/', 1)[-1]
89
93
 
90
94
        ctx['fileservice_action'] = req.make_path(os.path.join("fileservice",
91
 
                                                                self.path))
 
95
                                                               self.path))
92
96
        ctx['filename'] = cgi.escape(self.path)
93
97
 
 
98
    @property
 
99
    def path(self):
 
100
        return os.path.join(*self.subpath) if self.subpath else ''
 
101
 
94
102
    #TODO: Move all this logic into the template
95
103
    def gen_actions(self, req, ctx):
96
104
        """
132
140
          ])
133
141
        ]
134
142
 
 
143
class BrowserRedirectView(XHTMLView):
 
144
    def authorize(self, req):
 
145
        return req.user is not None
 
146
 
 
147
    def render(self, req):
 
148
        redirect_path = req.make_path(os.path.join('files', req.user.login))
 
149
        req.throw_redirect(redirect_path)
 
150
 
135
151
class Plugin(ViewPlugin, CookiePlugin, MediaPlugin):
136
 
    """
137
 
    The Plugin class for the user plugin.
138
 
    """
139
 
    # Magic attribute: urls
140
 
    # Sequence of pairs/triples of
141
 
    # (regex str, handler class, kwargs dict)
142
 
    # The kwargs dict is passed to the __init__ of the view object
143
 
    urls = [
144
 
        ('files/*(path)', BrowserView),
145
 
        ('files/', BrowserView),
146
 
        ('/', BrowserView),
147
 
    ]
 
152
    views = [(ApplicationRoot, 'files', BrowserView),
 
153
             (ApplicationRoot, '+index', BrowserRedirectView),
 
154
             ]
148
155
 
149
156
    tabs = [
150
157
        ('files', 'Files', 'Access and edit your files',