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

1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2009 The University of Melbourne
136 by mattgiuca
Added File Browser (browser) application. (Currently just stub).
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
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
18
# Author: Matt Giuca, Nick Chadwick
19
20
"""
21
The file browser application. Presents an Ajax-based interface to the
22
student's subversion workspace.
23
24
Note that there is virtually no server-side code for this application. It
25
simply presents static HTML and JavaScript, and all server-side activities
26
take place in the FileService app (for handling Ajax requests).
27
"""
28
1099.1.99 by William Grant
Require that plugins providing media subclass MediaPlugin.
29
from ivle.webapp.base.plugins import ViewPlugin, CookiePlugin, MediaPlugin
1099.1.34 by William Grant
Split up ivle.webapp.base.views into ivle.webapp.base.{rest,xhtml}, as it was
30
from ivle.webapp.base.xhtml import XHTMLView
136 by mattgiuca
Added File Browser (browser) application. (Currently just stub).
31
595 by mattgiuca
browser: Removed the browser.js ability to generate path links at the top.
32
import os.path
33
import cgi
34
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
35
from ivle import (util, studpath)
36
import ivle.svn
136 by mattgiuca
Added File Browser (browser) application. (Currently just stub).
37
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
38
class BrowserView(XHTMLView):
39
    """
40
    The view for the browser
41
    """
1099.1.35 by William Grant
ivle.webapp.base.xhtml#XHTMLView: Rename app_template to template (the things
42
    template = 'template.html'
1116 by William Grant
Move the old tutorial views into the 'subjects' tab, so they get the right
43
    tab = 'files'
1099.1.107 by William Grant
Remove some dummy help files, and register the only remaining one (browser).
44
    help = 'Filesystem/Browser'
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
45
1099.1.110 by William Grant
Implement an authorization system in the new framework. This breaks the REST
46
    def authorize(self, req):
47
        return req.user is not None
48
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
49
    def populate(self, req, ctx):
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
50
        if not hasattr(self, 'path'):
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
51
            # If no path specified, default to the user's home directory
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
52
            redirectPath = util.make_path(os.path.join('files', req.user.login))
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
53
            req.throw_redirect(util.make_path(redirectPath))
54
55
        # Set request attributes
1099.1.68 by William Grant
Move the remaining images to the new framework, in the new ivle.webapp.core
56
        self.plugin_styles[Plugin] = ['browser.css',
57
                                      'listing.css',
58
                                      'editor.css']
59
        self.plugin_scripts[Plugin] = ['browser.js',
60
                                       'listing.js',
61
                                       'editor.js',
1099.1.106 by William Grant
Move codepress into ivle.webapp.filesystem.browser's media directory.
62
                                       'specialhome.js',
63
                                       'codepress/codepress.js']
1099.1.68 by William Grant
Move the remaining images to the new framework, in the new ivle.webapp.core
64
        req.scripts_init = ["browser_init"]
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
65
66
        _, localpath = studpath.url_to_local(self.path)
67
        if localpath is None:
1099.1.93 by William Grant
Remove remaining uses of req.throw_error in the new webapps.
68
            raise NotFound()
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
69
1117 by William Grant
Deal with Unicode paths in BrowserView properly again.
70
        if isinstance(localpath, unicode):
71
            localpath = localpath.encode('utf-8')
72
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
73
        # Start writing data
74
75
        # FIXME: This isn't completely reliable! We're not inside the jail, so we
76
        # can't know the type for sure. This is now only used for adding a / to the
77
        # end of displayed paths, so I'm leaving this although it will often break.
1117 by William Grant
Deal with Unicode paths in BrowserView properly again.
78
        try:
79
            isdir = os.path.isdir(localpath)
80
        except OSError:
81
            isdir = False
82
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
83
        ctx['isdir'] = isdir
84
        self.gen_path(req, ctx)
85
        self.gen_actions(req, ctx)
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
86
1099.1.159 by William Grant
Display the current path as the filebrowser title again. Broke in genshi port.
87
        # The page title should contain the name of the file being browsed
88
        ctx['title'] = self.path.rsplit('/', 1)[-1]
89
1117 by William Grant
Deal with Unicode paths in BrowserView properly again.
90
        ctx['fileservice_action'] = util.make_path(os.path.join("fileservice",
91
                                                                self.path))
92
        ctx['filename'] = cgi.escape(self.path)
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
93
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
94
    #TODO: Move all this logic into the template
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
95
    def gen_path(self, req, ctx):
96
97
        href_path = util.make_path('files')
98
        nav_path = ""
99
        revision = ivle.svn.revision_from_string(
100
                         req.get_fieldstorage().getfirst('r'))
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
101
        try:
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
102
            revno = revision.number
103
        except:
104
            revno = None
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
105
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
106
        ctx['revno'] = revno
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
107
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
108
        # Create all of the paths
109
        pathlist = self.path.split("/")
110
        ctx['paths'] = []
111
        for path_seg in pathlist:
112
            if path_seg == "":
113
                continue
114
            new_seg = {}
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
115
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
116
            nav_path = nav_path + path_seg
117
            href_path = href_path + '/' + path_seg
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
118
119
            new_seg['path'] = path_seg
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
120
            new_seg['nav_path'] = nav_path
121
            new_seg['href_path'] = href_path
122
            if revno is not None:
123
                new_seg['href_path'] += '?r=%d' % revno
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
124
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
125
            ctx['paths'].append(new_seg)
126
127
    def gen_actions(self, req, ctx):
128
        """
129
        Presents a set of links/buttons for the "actions1" row of the top bar.
130
        This is always exactly the same - the JavaScript will customize it later.
131
        """
132
        # Set up our actions. The second field of each group is whether to disable
133
        # the items by default.
134
        ctx['moreactions'] = [
135
          ('Publishing', True, [
136
            ('publish', ['Publish',          'Make it so this directory can be seen by anyone on the web']),
137
            ('share',   ['Share this file',  'Get a link to this published file, to give to friends']),
138
            ('submit',  ['Submit', 'Submit the selected files for an assignment'])
139
          ]),
140
          ('File actions', True, [
141
            ('rename',  ['Rename',           'Change the name of this file']),
142
            ('delete',  ['Delete',           'Delete the selected files']),
143
            ('copy',    ['Copy',             'Prepare to copy the selected files to another directory']),
144
            ('cut',     ['Cut',              'Prepare to move the selected files to another directory'])
145
          ]),
146
          ('Directory actions', False, [
147
            ('paste',   ['Paste',            'Paste the copied or cut files into the current directory']),
148
            ('newfile', ['New File',         'Open a new file for editing in the current directory']),
149
            ('mkdir',   ['New Directory',    'Make a new subdirectory in the current directory']),
150
            ('upload',  ['Upload File',      'Upload a file to the current directory'])
151
          ]),
152
          ('Subversion', True, [
153
            ('svncut',      ['Svn Cut',      'Prepare to move the selected files to another directory, maintaining history']),
154
            ('svncopy',     ['Svn Copy',     'Prepare to copy the selected files to another directory, maintaining history']),
155
            ('svnadd',      ['Add',            'Schedule the selected temporary files to be added permanently']),
156
            ('svnremove',   ['Remove',         'Schedule the selected permanent files to be removed']),
157
            ('svndiff',     ['Diff',           'View any changes to the selected file since its last committed state']),
158
            ('svnrevert',   ['Revert',         'Restore the selected files back to their last committed state']),
159
            ('svnupdate',   ['Update',         'Update your files with changes from the permanent repository']),
160
            ('svncommit',   ['Commit',         'Commit any changes to the permanent repository']),
161
            ('svnresolved', ['Mark Resolved',  'Mark a conflicted file as being resolved']),
162
            ('svnlog',      ['View Log',       'View the log of commits of the selected file']),
163
          ])
164
        ]
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
165
1099.1.99 by William Grant
Require that plugins providing media subclass MediaPlugin.
166
class Plugin(ViewPlugin, CookiePlugin, MediaPlugin):
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
167
    """
168
    The Plugin class for the user plugin.
169
    """
170
    # Magic attribute: urls
171
    # Sequence of pairs/triples of
172
    # (regex str, handler class, kwargs dict)
173
    # The kwargs dict is passed to the __init__ of the view object
174
    urls = [
175
        ('files/*(path)', BrowserView),
176
        ('files/', BrowserView),
1099.1.119 by William Grant
Add a route from / to the browser redirection view.
177
        ('/', BrowserView),
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
178
    ]
1099.1.68 by William Grant
Move the remaining images to the new framework, in the new ivle.webapp.core
179
1099.1.115 by William Grant
Add tabs to the new framework. Move the app icons into the apps themselves.
180
    tabs = [
1118 by matt.giuca
Rewrote tooltips for the four tabs visible by default.
181
        ('files', 'Files', 'Access and edit your files',
182
         'browser.png', 'files', 1)
1099.1.115 by William Grant
Add tabs to the new framework. Move the app icons into the apps themselves.
183
    ]
184
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
185
    cookies = {'clipboard': None}
186
1099.1.107 by William Grant
Remove some dummy help files, and register the only remaining one (browser).
187
    help = {'Filesystem': {'Browser': 'help.html'}}
188
1099.1.68 by William Grant
Move the remaining images to the new framework, in the new ivle.webapp.core
189
    media = 'media'