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

« back to all changes in this revision

Viewing changes to ivle/webapp/submit/__init__.py

  • Committer: William Grant
  • Date: 2009-03-26 05:33:03 UTC
  • mto: (1165.3.1 submissions)
  • mto: This revision was merged to the branch mainline in revision 1174.
  • Revision ID: grantw@unimelb.edu.au-20090326053303-t1wsjswhk2sl2gml
Start a submission UI in ivle.webapp.submit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# IVLE
 
2
# Copyright (C) 2007-2009 The University of Melbourne
 
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
 
 
18
# Author: Will Grant
 
19
 
 
20
"""Project submissions user interface."""
 
21
 
 
22
from ivle.database import (User, ProjectGroup, Offering, Subject, Semester,
 
23
                           ProjectSet)
 
24
from ivle.webapp.errors import NotFound
 
25
from ivle.webapp.base.xhtml import XHTMLView
 
26
from ivle.webapp.base.plugins import ViewPlugin
 
27
 
 
28
 
 
29
class SubmitView(XHTMLView):
 
30
    """A view to submit a Subversion repository path for a project."""
 
31
    template = 'submit.html'
 
32
    tab = 'files'
 
33
    permission = 'submit_project'
 
34
 
 
35
    def __init__(self, req, rtype, rname, path):
 
36
        # We need to work out which entity owns the repository, so we look
 
37
        # at the first two path segments. The first tells us the type.
 
38
        if rtype == 'users':
 
39
            self.context = User.get_by_login(req.store, rname)
 
40
        elif rtype == 'groups':
 
41
            namebits = rname.split('_', 3)
 
42
            if len(namebits) != 4:
 
43
                raise NotFound()
 
44
            self.context = req.store.find(ProjectGroup,
 
45
                ProjectGroup.name == namebits[3],
 
46
                ProjectGroup.project_set_id == ProjectSet.id,
 
47
                ProjectSet.offering_id == Offering.id,
 
48
                Offering.subject_id == Subject.id,
 
49
                Subject.short_name == namebits[0],
 
50
                Offering.semester_id == Semester.id,
 
51
                Semester.year == namebits[1],
 
52
                Semester.semester == namebits[2]).one()
 
53
        else:
 
54
            raise NotFound()
 
55
 
 
56
        if self.context is None:
 
57
            raise NotFound()
 
58
 
 
59
    def populate(self, req, ctx):
 
60
        pass
 
61
 
 
62
class Plugin(ViewPlugin):
 
63
    urls = [
 
64
        ('+submit/:rtype/:rname/*path', SubmitView),
 
65
    ]