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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2009-05-11 04:51:08 UTC
  • mto: (1165.3.65 submissions-admin)
  • mto: This revision was merged to the branch mainline in revision 1247.
  • Revision ID: grantw@unimelb.edu.au-20090511045108-z70ij6oti5cazyo4
Add an ivle-refreshfilesystem script, which currently just rewrites svn(-group).conf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
# A sample / testing application for IVLE.
24
24
 
25
25
import os
26
 
import os.path
27
26
import urllib
28
 
import urlparse
29
27
import cgi
30
28
 
31
 
from storm.locals import Desc, Store
 
29
from storm.locals import Desc
32
30
import genshi
33
31
from genshi.filters import HTMLFormFiller
34
32
from genshi.template import Context, TemplateLoader
36
34
 
37
35
from ivle.webapp.base.xhtml import XHTMLView
38
36
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
39
 
from ivle.webapp import ApplicationRoot
 
37
from ivle.webapp.errors import NotFound
40
38
 
41
39
from ivle.database import Subject, Semester, Offering, Enrolment, User,\
42
40
                          ProjectSet, Project, ProjectSubmission
46
44
from ivle.webapp.admin.projectservice import ProjectSetRESTView,\
47
45
                                             ProjectRESTView
48
46
from ivle.webapp.admin.offeringservice import OfferingRESTView
49
 
from ivle.webapp.admin.publishing import (root_to_subject,
50
 
            subject_to_offering, offering_to_projectset, offering_to_project,
51
 
            subject_url, offering_url, projectset_url, project_url)
52
 
from ivle.webapp.admin.breadcrumbs import (SubjectBreadcrumb,
53
 
            OfferingBreadcrumb, UserBreadcrumb, ProjectBreadcrumb)
 
47
 
54
48
 
55
49
class SubjectsView(XHTMLView):
56
50
    '''The view of the list of subjects.'''
104
98
    tab = 'subjects'
105
99
    permission = 'edit'
106
100
 
 
101
    def __init__(self, req, subject, year, semester):
 
102
        """Find the given offering by subject, year and semester."""
 
103
        self.context = req.store.find(Offering,
 
104
            Offering.subject_id == Subject.id,
 
105
            Subject.short_name == subject,
 
106
            Offering.semester_id == Semester.id,
 
107
            Semester.year == year,
 
108
            Semester.semester == semester).one()
 
109
 
 
110
        if not self.context:
 
111
            raise NotFound()
 
112
 
107
113
    def filter(self, stream, ctx):
108
114
        return stream | HTMLFormFiller(data=ctx['data'])
109
115
 
132
138
    template = 'templates/offering_projects.html'
133
139
    permission = 'edit'
134
140
    tab = 'subjects'
 
141
    
 
142
    def __init__(self, req, subject, year, semester):
 
143
        self.context = req.store.find(Offering,
 
144
            Offering.subject_id == Subject.id,
 
145
            Subject.short_name == subject,
 
146
            Offering.semester_id == Semester.id,
 
147
            Semester.year == year,
 
148
            Semester.semester == semester).one()
 
149
 
 
150
        if not self.context:
 
151
            raise NotFound()
135
152
 
136
153
    def project_url(self, projectset, project):
137
154
        return "/subjects/%s/%s/%s/+projects/%s" % (
188
205
    permission = "edit"
189
206
    tab = 'subjects'
190
207
 
191
 
    def build_subversion_url(self, svnroot, submission):
192
 
        princ = submission.assessed.principal
193
 
 
194
 
        if isinstance(princ, User):
195
 
            path = 'users/%s' % princ.login
196
 
        else:
197
 
            path = 'groups/%s_%s_%s_%s' % (
198
 
                    princ.project_set.offering.subject.short_name,
199
 
                    princ.project_set.offering.semester.year,
200
 
                    princ.project_set.offering.semester.semester,
201
 
                    princ.name
202
 
                    )
203
 
        return urlparse.urljoin(
204
 
                    svnroot,
205
 
                    os.path.join(path, submission.path[1:] if
206
 
                                       submission.path.startswith(os.sep) else
207
 
                                       submission.path))
 
208
    def __init__(self, req, subject, year, semester, project):
 
209
        self.context = req.store.find(Project,
 
210
                Project.short_name == project,
 
211
                Project.project_set_id == ProjectSet.id,
 
212
                ProjectSet.offering_id == Offering.id,
 
213
                Offering.semester_id == Semester.id,
 
214
                Semester.year == year,
 
215
                Semester.semester == semester,
 
216
                Offering.subject_id == Subject.id,
 
217
                Subject.short_name == subject).one()
 
218
        if self.context is None:
 
219
            raise NotFound()
208
220
 
209
221
    def populate(self, req, ctx):
210
 
        self.plugin_styles[Plugin] = ["project.css"]
211
 
 
212
222
        ctx['format_datetime_short'] = ivle.date.format_datetime_for_paragraph
213
 
        ctx['build_subversion_url'] = self.build_subversion_url
214
 
        ctx['svn_addr'] = req.config['urls']['svn_addr']
 
223
 
215
224
        ctx['project'] = self.context
216
 
        ctx['user'] = req.user
 
225
        ctx['assesseds'] = self.context.assesseds
217
226
 
218
 
class OfferingEnrolmentSet(object):
219
 
    def __init__(self, offering):
220
 
        self.offering = offering
 
227
        ctx['submissions'] = []
 
228
        for assessed in self.context.assesseds:
 
229
            if assessed.submissions.count() > 0:
 
230
                ctx['submissions'].append(
 
231
                        assessed.submissions.order_by(
 
232
                            ProjectSubmission.date_submitted)[-1])
 
233
        ctx['assigned'] = self.context.project_set.get_assigned()
221
234
 
222
235
class Plugin(ViewPlugin, MediaPlugin):
223
 
    forward_routes = (root_to_subject, subject_to_offering,
224
 
                      offering_to_project, offering_to_projectset)
225
 
    reverse_routes = (subject_url, offering_url, projectset_url, project_url)
226
 
 
227
 
    views = [(ApplicationRoot, ('subjects', '+index'), SubjectsView),
228
 
             (Offering, ('+enrolments', '+new'), EnrolView),
229
 
             (Offering, ('+projects', '+index'), OfferingProjectsView),
230
 
             (Project, '+index', ProjectView),
231
 
 
232
 
             (Offering, ('+projectsets', '+new'), OfferingRESTView, 'api'),
233
 
             (ProjectSet, ('+projects', '+new'), ProjectSetRESTView, 'api'),
234
 
             (Project, '+index', ProjectRESTView, 'api'),
235
 
             ]
236
 
 
237
 
    breadcrumbs = {Subject: SubjectBreadcrumb,
238
 
                   Offering: OfferingBreadcrumb,
239
 
                   User: UserBreadcrumb,
240
 
                   Project: ProjectBreadcrumb,
241
 
                   }
 
236
    urls = [
 
237
        ('subjects/', SubjectsView),
 
238
        ('subjects/:subject/:year/:semester/+enrolments/+new', EnrolView),
 
239
        ('subjects/:subject/:year/:semester/+projects', OfferingProjectsView),
 
240
        ('subjects/:subject/:year/:semester/+projects/:project', ProjectView),
 
241
        #API Views
 
242
        ('api/subjects/:subject/:year/:semester/+projectsets/+new',
 
243
            OfferingRESTView),
 
244
        ('api/subjects/:subject/:year/:semester/+projectsets/:projectset/+projects/+new',
 
245
            ProjectSetRESTView),
 
246
        ('api/subjects/:subject/:year/:semester/+projects/:project', 
 
247
            ProjectRESTView),
 
248
 
 
249
    ]
242
250
 
243
251
    tabs = [
244
252
        ('subjects', 'Subjects',