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

« back to all changes in this revision

Viewing changes to ivle/webapp/admin/subject.py

  • Committer: David Coles
  • Date: 2009-11-27 05:34:33 UTC
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: coles.david@gmail.com-20091127053433-8ki9nm6xrkogxq67
Added diagram of system architecture

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import urlparse
29
29
import cgi
30
30
 
31
 
from storm.locals import Desc, Store
 
31
from storm.locals import Desc
32
32
import genshi
33
33
from genshi.filters import HTMLFormFiller
34
34
from genshi.template import Context, TemplateLoader
36
36
 
37
37
from ivle.webapp.base.xhtml import XHTMLView
38
38
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
39
 
from ivle.webapp import ApplicationRoot
 
39
from ivle.webapp.errors import NotFound
40
40
 
41
41
from ivle.database import Subject, Semester, Offering, Enrolment, User,\
42
42
                          ProjectSet, Project, ProjectSubmission
46
46
from ivle.webapp.admin.projectservice import ProjectSetRESTView,\
47
47
                                             ProjectRESTView
48
48
from ivle.webapp.admin.offeringservice import OfferingRESTView
49
 
from ivle.webapp.admin.traversal import (root_to_subject,
50
 
            subject_to_offering, offering_to_projectset, offering_to_project,
51
 
            subject_url, offering_url, projectset_url, project_url)
 
49
 
52
50
 
53
51
class SubjectsView(XHTMLView):
54
52
    '''The view of the list of subjects.'''
102
100
    tab = 'subjects'
103
101
    permission = 'edit'
104
102
 
 
103
    def __init__(self, req, subject, year, semester):
 
104
        """Find the given offering by subject, year and semester."""
 
105
        self.context = req.store.find(Offering,
 
106
            Offering.subject_id == Subject.id,
 
107
            Subject.short_name == subject,
 
108
            Offering.semester_id == Semester.id,
 
109
            Semester.year == year,
 
110
            Semester.semester == semester).one()
 
111
 
 
112
        if not self.context:
 
113
            raise NotFound()
 
114
 
105
115
    def filter(self, stream, ctx):
106
116
        return stream | HTMLFormFiller(data=ctx['data'])
107
117
 
130
140
    template = 'templates/offering_projects.html'
131
141
    permission = 'edit'
132
142
    tab = 'subjects'
 
143
    
 
144
    def __init__(self, req, subject, year, semester):
 
145
        self.context = req.store.find(Offering,
 
146
            Offering.subject_id == Subject.id,
 
147
            Subject.short_name == subject,
 
148
            Offering.semester_id == Semester.id,
 
149
            Semester.year == year,
 
150
            Semester.semester == semester).one()
 
151
 
 
152
        if not self.context:
 
153
            raise NotFound()
133
154
 
134
155
    def project_url(self, projectset, project):
135
156
        return "/subjects/%s/%s/%s/+projects/%s" % (
186
207
    permission = "edit"
187
208
    tab = 'subjects'
188
209
 
 
210
    def __init__(self, req, subject, year, semester, project):
 
211
        self.context = req.store.find(Project,
 
212
                Project.short_name == project,
 
213
                Project.project_set_id == ProjectSet.id,
 
214
                ProjectSet.offering_id == Offering.id,
 
215
                Offering.semester_id == Semester.id,
 
216
                Semester.year == year,
 
217
                Semester.semester == semester,
 
218
                Offering.subject_id == Subject.id,
 
219
                Subject.short_name == subject).one()
 
220
        if self.context is None:
 
221
            raise NotFound()
 
222
 
189
223
    def build_subversion_url(self, svnroot, submission):
190
224
        princ = submission.assessed.principal
191
225
 
213
247
        ctx['project'] = self.context
214
248
        ctx['user'] = req.user
215
249
 
216
 
class OfferingEnrolmentSet(object):
217
 
    def __init__(self, offering):
218
 
        self.offering = offering
219
 
 
220
250
class Plugin(ViewPlugin, MediaPlugin):
221
 
    forward_routes = (root_to_subject, subject_to_offering,
222
 
                      offering_to_project, offering_to_projectset)
223
 
    reverse_routes = (subject_url, offering_url, projectset_url, project_url)
224
 
 
225
 
    views = [(ApplicationRoot, ('subjects', '+index'), SubjectsView),
226
 
             (Offering, ('+enrolments', '+new'), EnrolView),
227
 
             (Offering, ('+projects', '+index'), OfferingProjectsView),
228
 
             (Project, '+index', ProjectView),
229
 
 
230
 
             (Offering, ('+projectsets', '+new'), OfferingRESTView, 'api'),
231
 
             (ProjectSet, ('+projects', '+new'), ProjectSetRESTView, 'api'),
232
 
             (Project, '+index', ProjectRESTView, 'api'),
233
 
             ]
 
251
    urls = [
 
252
        ('subjects/', SubjectsView),
 
253
        ('subjects/:subject/:year/:semester/+enrolments/+new', EnrolView),
 
254
        ('subjects/:subject/:year/:semester/+projects', OfferingProjectsView),
 
255
        ('subjects/:subject/:year/:semester/+projects/:project', ProjectView),
 
256
        #API Views
 
257
        ('api/subjects/:subject/:year/:semester/+projectsets/+new',
 
258
            OfferingRESTView),
 
259
        ('api/subjects/:subject/:year/:semester/+projectsets/:projectset/+projects/+new',
 
260
            ProjectSetRESTView),
 
261
        ('api/subjects/:subject/:year/:semester/+projects/:project', 
 
262
            ProjectRESTView),
 
263
 
 
264
    ]
234
265
 
235
266
    tabs = [
236
267
        ('subjects', 'Subjects',