~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
1211 by William Grant
Fixed missing exception import in filebrowser.
31
from ivle.webapp.errors import NotFound
1252 by William Grant
Move BrowserView's path segmentation/linking function into ivle.webapp.filesystem.
32
from ivle.webapp.filesystem import make_path_segments
1294.2.55 by William Grant
Port the filebrowser too.
33
from ivle.webapp import ApplicationRoot
136 by mattgiuca
Added File Browser (browser) application. (Currently just stub).
34
595 by mattgiuca
browser: Removed the browser.js ability to generate path links at the top.
35
import os.path
36
import cgi
37
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
38
import ivle.svn
136 by mattgiuca
Added File Browser (browser) application. (Currently just stub).
39
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
40
class BrowserView(XHTMLView):
41
    """
42
    The view for the browser
43
    """
1099.1.35 by William Grant
ivle.webapp.base.xhtml#XHTMLView: Rename app_template to template (the things
44
    template = 'template.html'
1116 by William Grant
Move the old tutorial views into the 'subjects' tab, so they get the right
45
    tab = 'files'
1099.1.107 by William Grant
Remove some dummy help files, and register the only remaining one (browser).
46
    help = 'Filesystem/Browser'
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
47
1294.2.60 by William Grant
Move the already-ported filesystem views to use subpaths.
48
    subpath_allowed = True
49
1099.1.110 by William Grant
Implement an authorization system in the new framework. This breaks the REST
50
    def authorize(self, req):
51
        return req.user is not None
52
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
53
    def populate(self, req, ctx):
1294.2.60 by William Grant
Move the already-ported filesystem views to use subpaths.
54
        if len(self.path) == 0:
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
55
            # If no path specified, default to the user's home directory
1210 by William Grant
Use Request.make_path everywhere.
56
            redirectPath = req.make_path(os.path.join('files', req.user.login))
57
            req.throw_redirect(redirectPath)
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
58
59
        # Set request attributes
1099.1.68 by William Grant
Move the remaining images to the new framework, in the new ivle.webapp.core
60
        self.plugin_styles[Plugin] = ['browser.css',
61
                                      'listing.css',
62
                                      'editor.css']
63
        self.plugin_scripts[Plugin] = ['browser.js',
64
                                       'listing.js',
65
                                       'editor.js',
1099.1.106 by William Grant
Move codepress into ivle.webapp.filesystem.browser's media directory.
66
                                       'specialhome.js',
67
                                       'codepress/codepress.js']
1282.1.3 by William Grant
Replace req.scripts_init with self.scripts_init in the two users.
68
        self.scripts_init = ["browser_init"]
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
69
70
        # Start writing data
71
1266 by William Grant
Always set isdir = False in the file browser template filling.
72
        # TODO: Set this properly. We can't get into the jail from server-side
73
        # code at the moment, so we can't determine this.
74
        isdir = False
1117 by William Grant
Deal with Unicode paths in BrowserView properly again.
75
1252 by William Grant
Move BrowserView's path segmentation/linking function into ivle.webapp.filesystem.
76
        revision = ivle.svn.revision_from_string(
77
                         req.get_fieldstorage().getfirst('r'))
78
        try:
79
            revno = revision.number
80
        except:
81
            revno = None
82
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
83
        ctx['isdir'] = isdir
1252 by William Grant
Move BrowserView's path segmentation/linking function into ivle.webapp.filesystem.
84
        ctx['revno'] = revno
85
86
        ctx['paths'] = make_path_segments(req.path, revno)
87
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
88
        self.gen_actions(req, ctx)
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
89
1099.1.159 by William Grant
Display the current path as the filebrowser title again. Broke in genshi port.
90
        # The page title should contain the name of the file being browsed
1294.2.60 by William Grant
Move the already-ported filesystem views to use subpaths.
91
        ctx['title'] = os.path.normpath(self.path).rsplit('/', 1)[-1]
1099.1.159 by William Grant
Display the current path as the filebrowser title again. Broke in genshi port.
92
1210 by William Grant
Use Request.make_path everywhere.
93
        ctx['fileservice_action'] = req.make_path(os.path.join("fileservice",
1294.2.60 by William Grant
Move the already-ported filesystem views to use subpaths.
94
                                                               self.path))
95
        ctx['filename'] = cgi.escape(self.path)
96
97
    @property
98
    def path(self):
99
        return os.path.join(*self.subpath) if self.subpath else ''
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
100
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
101
    #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.
102
    def gen_actions(self, req, ctx):
103
        """
104
        Presents a set of links/buttons for the "actions1" row of the top bar.
105
        This is always exactly the same - the JavaScript will customize it later.
106
        """
107
        # Set up our actions. The second field of each group is whether to disable
108
        # the items by default.
109
        ctx['moreactions'] = [
110
          ('Publishing', True, [
111
            ('publish', ['Publish',          'Make it so this directory can be seen by anyone on the web']),
112
            ('share',   ['Share this file',  'Get a link to this published file, to give to friends']),
1165.1.34 by William Grant
Retitle the Submit action to indicate its projectness.
113
            ('submit',  ['Submit', 'Submit the selected files for a project'])
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
114
          ]),
115
          ('File actions', True, [
116
            ('rename',  ['Rename',           'Change the name of this file']),
117
            ('delete',  ['Delete',           'Delete the selected files']),
118
            ('copy',    ['Copy',             'Prepare to copy the selected files to another directory']),
119
            ('cut',     ['Cut',              'Prepare to move the selected files to another directory'])
120
          ]),
121
          ('Directory actions', False, [
122
            ('paste',   ['Paste',            'Paste the copied or cut files into the current directory']),
123
            ('newfile', ['New File',         'Open a new file for editing in the current directory']),
124
            ('mkdir',   ['New Directory',    'Make a new subdirectory in the current directory']),
125
            ('upload',  ['Upload File',      'Upload a file to the current directory'])
126
          ]),
127
          ('Subversion', True, [
128
            ('svncut',      ['Svn Cut',      'Prepare to move the selected files to another directory, maintaining history']),
129
            ('svncopy',     ['Svn Copy',     'Prepare to copy the selected files to another directory, maintaining history']),
130
            ('svnadd',      ['Add',            'Schedule the selected temporary files to be added permanently']),
131
            ('svnremove',   ['Remove',         'Schedule the selected permanent files to be removed']),
132
            ('svndiff',     ['Diff',           'View any changes to the selected file since its last committed state']),
133
            ('svnrevert',   ['Revert',         'Restore the selected files back to their last committed state']),
134
            ('svnupdate',   ['Update',         'Update your files with changes from the permanent repository']),
135
            ('svncommit',   ['Commit',         'Commit any changes to the permanent repository']),
136
            ('svnresolved', ['Mark Resolved',  'Mark a conflicted file as being resolved']),
137
            ('svnlog',      ['View Log',       'View the log of commits of the selected file']),
138
          ])
139
        ]
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
140
1294.2.55 by William Grant
Port the filebrowser too.
141
class BrowserRedirectView(XHTMLView):
142
    def authorize(self, req):
143
        return req.user is not None
144
145
    def render(self, req):
146
        redirect_path = req.make_path(os.path.join('files', req.user.login))
147
        req.throw_redirect(redirect_path)
148
1099.1.99 by William Grant
Require that plugins providing media subclass MediaPlugin.
149
class Plugin(ViewPlugin, CookiePlugin, MediaPlugin):
1294.2.60 by William Grant
Move the already-ported filesystem views to use subpaths.
150
    views = [(ApplicationRoot, 'files', BrowserView),
1294.2.55 by William Grant
Port the filebrowser too.
151
             (ApplicationRoot, '+index', BrowserRedirectView),
152
             ]
1099.1.68 by William Grant
Move the remaining images to the new framework, in the new ivle.webapp.core
153
1099.1.115 by William Grant
Add tabs to the new framework. Move the app icons into the apps themselves.
154
    tabs = [
1118 by matt.giuca
Rewrote tooltips for the four tabs visible by default.
155
        ('files', 'Files', 'Access and edit your files',
156
         'browser.png', 'files', 1)
1099.1.115 by William Grant
Add tabs to the new framework. Move the app icons into the apps themselves.
157
    ]
158
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
159
    cookies = {'clipboard': None}
160
1099.1.107 by William Grant
Remove some dummy help files, and register the only remaining one (browser).
161
    help = {'Filesystem': {'Browser': 'help.html'}}
162
1099.1.68 by William Grant
Move the remaining images to the new framework, in the new ivle.webapp.core
163
    media = 'media'