~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 06:09:54 UTC
  • mto: (1165.3.1 submissions)
  • mto: This revision was merged to the branch mainline in revision 1174.
  • Revision ID: grantw@unimelb.edu.au-20090326060954-8931c8n83xdovyiw
Split SubmitView.__init__ into new subclasses, {User,Group}SubmitView.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    tab = 'files'
33
33
    permission = 'submit_project'
34
34
 
35
 
    def __init__(self, req, rtype, rname, path):
 
35
    def __init__(self, req, name, path):
36
36
        # We need to work out which entity owns the repository, so we look
37
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()
 
38
        self.context = self.get_repository_owner(req.store, name)
55
39
 
56
40
        if self.context is None:
57
41
            raise NotFound()
58
42
 
 
43
    def get_repository_owner(self, store, name):
 
44
        """Return the owner of the repository given the name and a Store."""
 
45
        raise NotImplementedError()
 
46
 
59
47
    def populate(self, req, ctx):
60
48
        pass
61
49
 
 
50
 
 
51
class UserSubmitView(SubmitView):
 
52
    def get_repository_owner(self, store, name):
 
53
        '''Resolve the user name into a user.'''
 
54
        return User.get_by_login(store, name)
 
55
 
 
56
 
 
57
class GroupSubmitView(SubmitView):
 
58
    def get_repository_owner(self, store, name):
 
59
        '''Resolve the subject_year_semester_group name into a group.'''
 
60
        namebits = name.split('_', 3)
 
61
        if len(namebits) != 4:
 
62
            return None
 
63
 
 
64
        # Find the project group with the given name in any project set in the
 
65
        # offering of the given subject in the semester with the given year
 
66
        # and semester.
 
67
        return store.find(ProjectGroup,
 
68
            ProjectGroup.name == namebits[3],
 
69
            ProjectGroup.project_set_id == ProjectSet.id,
 
70
            ProjectSet.offering_id == Offering.id,
 
71
            Offering.subject_id == Subject.id,
 
72
            Subject.short_name == namebits[0],
 
73
            Offering.semester_id == Semester.id,
 
74
            Semester.year == namebits[1],
 
75
            Semester.semester == namebits[2]).one()
 
76
 
 
77
 
62
78
class Plugin(ViewPlugin):
63
79
    urls = [
64
 
        ('+submit/:rtype/:rname/*path', SubmitView),
 
80
        ('+submit/users/:name/*path', UserSubmitView),
 
81
        ('+submit/groups/:name/*path', GroupSubmitView),
65
82
    ]