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

« back to all changes in this revision

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

  • Committer: Matt Giuca
  • Date: 2009-05-19 02:54:08 UTC
  • mfrom: (1258 trunk)
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: matt.giuca@gmail.com-20090519025408-19c7cjl7w6ot6frm
MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
from ivle.webapp.base.plugins import ViewPlugin, CookiePlugin, MediaPlugin
30
30
from ivle.webapp.base.xhtml import XHTMLView
 
31
from ivle.webapp.errors import NotFound
 
32
from ivle.webapp.filesystem import make_path_segments
31
33
 
32
34
import os.path
33
35
import cgi
34
36
 
35
 
from ivle import (util, studpath)
 
37
from ivle import studpath
36
38
import ivle.svn
37
39
 
38
40
class BrowserView(XHTMLView):
49
51
    def populate(self, req, ctx):
50
52
        if not hasattr(self, 'path'):
51
53
            # If no path specified, default to the user's home directory
52
 
            redirectPath = util.make_path(os.path.join('files', req.user.login))
53
 
            req.throw_redirect(util.make_path(redirectPath))
 
54
            redirectPath = req.make_path(os.path.join('files', req.user.login))
 
55
            req.throw_redirect(redirectPath)
54
56
 
55
57
        # Set request attributes
56
58
        self.plugin_styles[Plugin] = ['browser.css',
80
82
        except OSError:
81
83
            isdir = False
82
84
 
 
85
        revision = ivle.svn.revision_from_string(
 
86
                         req.get_fieldstorage().getfirst('r'))
 
87
        try:
 
88
            revno = revision.number
 
89
        except:
 
90
            revno = None
 
91
 
83
92
        ctx['isdir'] = isdir
84
 
        self.gen_path(req, ctx)
 
93
        ctx['revno'] = revno
 
94
 
 
95
        ctx['paths'] = make_path_segments(req.path, revno)
 
96
 
85
97
        self.gen_actions(req, ctx)
86
98
 
87
99
        # The page title should contain the name of the file being browsed
88
100
        ctx['title'] = self.path.rsplit('/', 1)[-1]
89
101
 
90
 
        ctx['fileservice_action'] = util.make_path(os.path.join("fileservice",
 
102
        ctx['fileservice_action'] = req.make_path(os.path.join("fileservice",
91
103
                                                                self.path))
92
104
        ctx['filename'] = cgi.escape(self.path)
93
105
 
94
106
    #TODO: Move all this logic into the template
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'))
101
 
        try:
102
 
            revno = revision.number
103
 
        except:
104
 
            revno = None
105
 
 
106
 
        ctx['revno'] = revno
107
 
 
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 = {}
115
 
 
116
 
            nav_path = nav_path + path_seg
117
 
            href_path = href_path + '/' + path_seg
118
 
 
119
 
            new_seg['path'] = path_seg
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
124
 
 
125
 
            ctx['paths'].append(new_seg)
126
 
 
127
107
    def gen_actions(self, req, ctx):
128
108
        """
129
109
        Presents a set of links/buttons for the "actions1" row of the top bar.
135
115
          ('Publishing', True, [
136
116
            ('publish', ['Publish',          'Make it so this directory can be seen by anyone on the web']),
137
117
            ('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'])
 
118
            ('submit',  ['Submit', 'Submit the selected files for a project'])
139
119
          ]),
140
120
          ('File actions', True, [
141
121
            ('rename',  ['Rename',           'Change the name of this file']),