~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'
43
    appname = '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
        # The page title should contain the name of the file being browsed
67
        req.title = self.path.rsplit('/', 1)[-1]
68
69
        _, localpath = studpath.url_to_local(self.path)
70
        if localpath is None:
1099.1.93 by William Grant
Remove remaining uses of req.throw_error in the new webapps.
71
            raise NotFound()
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
72
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.
78
        isdir = os.path.isdir(localpath)
79
        ctx['isdir'] = isdir
80
        self.gen_path(req, ctx)
81
        self.gen_actions(req, ctx)
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
82
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
83
        ctx['fileservice_action'] = util.make_path(os.path.join("fileservice", req.path))
84
        ctx['filename'] = cgi.escape(req.path)
85
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
86
    #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.
87
    def gen_path(self, req, ctx):
88
89
        href_path = util.make_path('files')
90
        nav_path = ""
91
        revision = ivle.svn.revision_from_string(
92
                         req.get_fieldstorage().getfirst('r'))
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
93
        try:
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
94
            revno = revision.number
95
        except:
96
            revno = None
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
97
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
98
        ctx['revno'] = revno
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
99
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
100
        # Create all of the paths
101
        pathlist = self.path.split("/")
102
        ctx['paths'] = []
103
        for path_seg in pathlist:
104
            if path_seg == "":
105
                continue
106
            new_seg = {}
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
            nav_path = nav_path + path_seg
109
            href_path = href_path + '/' + path_seg
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
110
111
            new_seg['path'] = path_seg
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
112
            new_seg['nav_path'] = nav_path
113
            new_seg['href_path'] = href_path
114
            if revno is not None:
115
                new_seg['href_path'] += '?r=%d' % revno
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
116
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
117
            ctx['paths'].append(new_seg)
118
119
    def gen_actions(self, req, ctx):
120
        """
121
        Presents a set of links/buttons for the "actions1" row of the top bar.
122
        This is always exactly the same - the JavaScript will customize it later.
123
        """
124
        # Set up our actions. The second field of each group is whether to disable
125
        # the items by default.
126
        ctx['moreactions'] = [
127
          ('Publishing', True, [
128
            ('publish', ['Publish',          'Make it so this directory can be seen by anyone on the web']),
129
            ('share',   ['Share this file',  'Get a link to this published file, to give to friends']),
130
            ('submit',  ['Submit', 'Submit the selected files for an assignment'])
131
          ]),
132
          ('File actions', True, [
133
            ('rename',  ['Rename',           'Change the name of this file']),
134
            ('delete',  ['Delete',           'Delete the selected files']),
135
            ('copy',    ['Copy',             'Prepare to copy the selected files to another directory']),
136
            ('cut',     ['Cut',              'Prepare to move the selected files to another directory'])
137
          ]),
138
          ('Directory actions', False, [
139
            ('paste',   ['Paste',            'Paste the copied or cut files into the current directory']),
140
            ('newfile', ['New File',         'Open a new file for editing in the current directory']),
141
            ('mkdir',   ['New Directory',    'Make a new subdirectory in the current directory']),
142
            ('upload',  ['Upload File',      'Upload a file to the current directory'])
143
          ]),
144
          ('Subversion', True, [
145
            ('svncut',      ['Svn Cut',      'Prepare to move the selected files to another directory, maintaining history']),
146
            ('svncopy',     ['Svn Copy',     'Prepare to copy the selected files to another directory, maintaining history']),
147
            ('svnadd',      ['Add',            'Schedule the selected temporary files to be added permanently']),
148
            ('svnremove',   ['Remove',         'Schedule the selected permanent files to be removed']),
149
            ('svndiff',     ['Diff',           'View any changes to the selected file since its last committed state']),
150
            ('svnrevert',   ['Revert',         'Restore the selected files back to their last committed state']),
151
            ('svnupdate',   ['Update',         'Update your files with changes from the permanent repository']),
152
            ('svncommit',   ['Commit',         'Commit any changes to the permanent repository']),
153
            ('svnresolved', ['Mark Resolved',  'Mark a conflicted file as being resolved']),
154
            ('svnlog',      ['View Log',       'View the log of commits of the selected file']),
155
          ])
156
        ]
1099.1.12 by William Grant
ivle/webapp/browser#BrowserTemplate: Fix some formatting, and redirect properly
157
1099.1.99 by William Grant
Require that plugins providing media subclass MediaPlugin.
158
class Plugin(ViewPlugin, CookiePlugin, MediaPlugin):
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
159
    """
160
    The Plugin class for the user plugin.
161
    """
162
    # Magic attribute: urls
163
    # Sequence of pairs/triples of
164
    # (regex str, handler class, kwargs dict)
165
    # The kwargs dict is passed to the __init__ of the view object
166
    urls = [
167
        ('files/*(path)', BrowserView),
168
        ('files/', BrowserView),
1099.1.119 by William Grant
Add a route from / to the browser redirection view.
169
        ('/', BrowserView),
1099.1.10 by chadnickbok at gmail
ivle.webapp.browser: Add, a port of the old www/apps/browser.
170
    ]
1099.1.68 by William Grant
Move the remaining images to the new framework, in the new ivle.webapp.core
171
1099.1.115 by William Grant
Add tabs to the new framework. Move the app icons into the apps themselves.
172
    tabs = [
173
        ('files', 'Files', 'Gives you access to all of your files and lets '
174
         'you download, upload, edit and run them.', 'browser.png', 'files', 1)
175
    ]
176
1099.1.80 by William Grant
Port the forum app to the new framework. With it also comes new cookie
177
    cookies = {'clipboard': None}
178
1099.1.107 by William Grant
Remove some dummy help files, and register the only remaining one (browser).
179
    help = {'Filesystem': {'Browser': 'help.html'}}
180
1099.1.68 by William Grant
Move the remaining images to the new framework, in the new ivle.webapp.core
181
    media = 'media'