1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2009 The University of Melbourne
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.
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.
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
18
from ivle.database import Offering, ProjectSet, Project, Subject, User
20
from ivle.webapp import ApplicationRoot
21
from ivle.webapp.routing import ROOT
22
from ivle.webapp.routing.decorators import forward_route, reverse_route
24
@forward_route(ApplicationRoot, argc=1)
25
def root_to_user(root, segment):
26
if not segment.startswith('~'):
28
return User.get_by_login(root.store, segment[1:])
30
@forward_route(ApplicationRoot, 'subjects', argc=1)
31
def root_to_subject(root, name):
32
return root.store.find(Subject, short_name=name).one()
34
@forward_route(Subject, argc=2)
35
def subject_to_offering(subject, year, semester):
36
return subject.offering_for_semester(year, semester)
38
@forward_route(Offering, '+projects', argc=1)
39
def offering_to_project(offering, name):
40
return Store.of(offering).find(Project,
41
Project.project_set_id == ProjectSet.id,
42
ProjectSet.offering == offering).one()
44
@forward_route(Offering, '+projectsets', argc=1)
45
def offering_to_projectset(offering, name):
46
return Store.of(offering).find(ProjectSet,
47
ProjectSet.offering == offering).one()
51
return (ROOT, '~' + user)
53
@reverse_route(Subject)
54
def subject_url(subject):
55
return (ROOT, ('subjects', subject.name))
57
@reverse_route(Offering)
58
def offering_url(offering):
59
return (offering.subject, (offering.semester.year,
60
offering.semester.semester))
62
@reverse_route(ProjectSet)
63
def projectset_url(project_set):
64
return (project_set.offering, ('+projectsets', project_set.name))
66
@reverse_route(Project)
67
def project_url(project):
68
return (project.project_set.offering, ('+projects', project.name))