~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-05 02:57:53 UTC
  • Revision ID: grantw@unimelb.edu.au-20090505025753-a12zc1my6tjowies
Decode console input as UTF-8, until JSONRESTView does it for us.

Unicode input had regressed!

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import cgi
28
28
 
29
29
from storm.locals import Desc
30
 
import genshi
31
30
from genshi.filters import HTMLFormFiller
32
 
from genshi.template import Context, TemplateLoader
33
31
import formencode
34
32
 
35
33
from ivle.webapp.base.xhtml import XHTMLView
36
34
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
37
35
from ivle.webapp.errors import NotFound
38
 
 
39
 
from ivle.database import Subject, Semester, Offering, Enrolment, User,\
40
 
                          ProjectSet, Project, ProjectSubmission
41
 
from ivle import util
42
 
import ivle.date
43
 
 
44
 
from ivle.webapp.admin.projectservice import ProjectSetRESTView,\
45
 
                                             ProjectRESTView
46
 
from ivle.webapp.admin.offeringservice import OfferingRESTView
 
36
from ivle.database import Subject, Semester, Offering, Enrolment, User
47
37
 
48
38
 
49
39
class SubjectsView(XHTMLView):
50
40
    '''The view of the list of subjects.'''
51
 
    template = 'templates/subjects.html'
 
41
    template = 'subjects.html'
52
42
    tab = 'subjects'
53
43
 
54
44
    def authorize(self, req):
94
84
 
95
85
class EnrolView(XHTMLView):
96
86
    """A form to enrol a user in an offering."""
97
 
    template = 'templates/enrol.html'
 
87
    template = 'enrol.html'
98
88
    tab = 'subjects'
99
89
    permission = 'edit'
100
90
 
133
123
        ctx['offering'] = self.context
134
124
        ctx['errors'] = errors
135
125
 
136
 
class OfferingProjectsView(XHTMLView):
137
 
    """View the projects for an offering."""
138
 
    template = 'templates/offering_projects.html'
139
 
    permission = 'edit'
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()
152
 
 
153
 
    def project_url(self, projectset, project):
154
 
        return "/subjects/%s/%s/%s/+projects/%s" % (
155
 
                    self.context.subject.short_name,
156
 
                    self.context.semester.year,
157
 
                    self.context.semester.semester,
158
 
                    project.short_name
159
 
                    )
160
 
 
161
 
    def new_project_url(self, projectset):
162
 
        return "/api/subjects/" + self.context.subject.short_name + "/" +\
163
 
                self.context.semester.year + "/" + \
164
 
                self.context.semester.semester + "/+projectsets/" +\
165
 
                str(projectset.id) + "/+projects/+new"
166
 
    
167
 
    def populate(self, req, ctx):
168
 
        self.plugin_styles[Plugin] = ["project.css"]
169
 
        self.plugin_scripts[Plugin] = ["project.js"]
170
 
        ctx['offering'] = self.context
171
 
        ctx['subject'] = self.context.subject.short_name
172
 
        ctx['year'] = self.context.semester.year
173
 
        ctx['semester'] = self.context.semester.semester
174
 
 
175
 
        ctx['projectsets'] = []
176
 
 
177
 
        #Open the projectset Fragment, and render it for inclusion
178
 
        #into the ProjectSets page
179
 
        #XXX: This could be a lot cleaner
180
 
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
181
 
 
182
 
        set_fragment = os.path.join(os.path.dirname(__file__),
183
 
                "templates/projectset_fragment.html")
184
 
        project_fragment = os.path.join(os.path.dirname(__file__),
185
 
                "templates/project_fragment.html")
186
 
 
187
 
        for projectset in self.context.project_sets:
188
 
            settmpl = loader.load(set_fragment)
189
 
            setCtx = Context()
190
 
            setCtx['group_size'] = projectset.max_students_per_group
191
 
            setCtx['projectset_id'] = projectset.id
192
 
            setCtx['new_project_url'] = self.new_project_url(projectset)
193
 
            setCtx['projects'] = []
194
 
 
195
 
            for project in projectset.projects:
196
 
                projecttmpl = loader.load(project_fragment)
197
 
                projectCtx = Context()
198
 
                projectCtx['project'] = project
199
 
                projectCtx['project_url'] = self.project_url(projectset, project)
200
 
 
201
 
                setCtx['projects'].append(
202
 
                        projecttmpl.generate(projectCtx))
203
 
 
204
 
            ctx['projectsets'].append(settmpl.generate(setCtx))
205
 
 
206
 
 
207
 
class ProjectView(XHTMLView):
208
 
    """View the submissions for a ProjectSet"""
209
 
    template = "templates/project.html"
210
 
    permission = "edit"
211
 
    tab = 'subjects'
212
 
 
213
 
    def __init__(self, req, subject, year, semester, project):
214
 
        self.context = req.store.find(Project,
215
 
                Project.short_name == project,
216
 
                Project.project_set_id == ProjectSet.id,
217
 
                ProjectSet.offering_id == Offering.id,
218
 
                Offering.semester_id == Semester.id,
219
 
                Semester.year == year,
220
 
                Semester.semester == semester,
221
 
                Offering.subject_id == Subject.id,
222
 
                Subject.short_name == subject).one()
223
 
        if self.context is None:
224
 
            raise NotFound()
225
 
 
226
 
    def populate(self, req, ctx):
227
 
        ctx['format_datetime_short'] = ivle.date.format_datetime_for_paragraph
228
 
 
229
 
        ctx['project'] = self.context
230
 
        ctx['assesseds'] = self.context.assesseds
231
 
 
232
 
        ctx['submissions'] = []
233
 
        for assessed in self.context.assesseds:
234
 
            if assessed.submissions.count() > 0:
235
 
                ctx['submissions'].append(
236
 
                        assessed.submissions.order_by(ProjectSubmission.date_submitted)[-1])
237
 
 
238
126
 
239
127
class Plugin(ViewPlugin, MediaPlugin):
240
128
    urls = [
241
129
        ('subjects/', SubjectsView),
242
130
        ('subjects/:subject/:year/:semester/+enrolments/+new', EnrolView),
243
 
        ('subjects/:subject/:year/:semester/+projects', OfferingProjectsView),
244
 
        ('subjects/:subject/:year/:semester/+projects/:project', ProjectView),
245
 
        #API Views
246
 
        ('api/subjects/:subject/:year/:semester/+projectsets/+new',
247
 
            OfferingRESTView),
248
 
        ('api/subjects/:subject/:year/:semester/+projectsets/:projectset/+projects/+new',
249
 
            ProjectSetRESTView),
250
 
        ('api/subjects/:subject/:year/:semester/+projects/:project', 
251
 
            ProjectRESTView),
252
 
 
253
131
    ]
254
132
 
255
133
    tabs = [