~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: 2010-07-27 09:02:06 UTC
  • mto: This revision was merged to the branch mainline in revision 1824.
  • Revision ID: grantw@unimelb.edu.au-20100727090206-pmf5j6lu6xc892q8
Replace semester.semester with semester.{code,url_name,display_name}.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
        ctx['user'] = req.user
76
76
        ctx['semesters'] = []
77
77
 
78
 
        for semester in req.store.find(Semester).order_by(Desc(Semester.year),
79
 
                                                     Desc(Semester.semester)):
 
78
        for semester in req.store.find(Semester).order_by(
 
79
            Desc(Semester.year), Desc(Semester.display_name)):
80
80
            if req.user.admin:
81
81
                # For admins, show all subjects in the system
82
82
                offerings = list(semester.offerings.find())
104
104
 
105
105
        ctx['subjects'] = req.store.find(Subject).order_by(Subject.name)
106
106
        ctx['semesters'] = req.store.find(Semester).order_by(
107
 
            Semester.year, Semester.semester)
 
107
            Semester.year, Semester.display_name)
108
108
 
109
109
 
110
110
class SubjectShortNameUniquenessValidator(formencode.FancyValidator):
194
194
    """
195
195
    def _to_python(self, value, state):
196
196
        if (state.store.find(
197
 
                Semester, year=value['year'], semester=value['semester']
 
197
                Semester, year=value['year'], url_name=value['url_name']
198
198
                ).one() not in (None, state.existing_semester)):
199
199
            raise formencode.Invalid(
200
200
                'Semester already exists', value, state)
203
203
 
204
204
class SemesterSchema(formencode.Schema):
205
205
    year = URLNameValidator()
206
 
    semester = URLNameValidator()
 
206
    code = formencode.validators.UnicodeString()
 
207
    url_name = URLNameValidator()
 
208
    display_name = formencode.validators.UnicodeString()
207
209
    state = formencode.All(
208
210
        formencode.validators.OneOf(["past", "current", "future"]),
209
211
        formencode.validators.UnicodeString())
238
240
    def save_object(self, req, data):
239
241
        new_semester = Semester()
240
242
        new_semester.year = data['year']
241
 
        new_semester.semester = data['semester']
 
243
        new_semester.code = data['code']
 
244
        new_semester.url_name = data['url_name']
 
245
        new_semester.display_name = data['display_name']
242
246
        new_semester.state = data['state']
243
247
 
244
248
        req.store.add(new_semester)
255
259
    def get_default_data(self, req):
256
260
        return {
257
261
            'year': self.context.year,
258
 
            'semester': self.context.semester,
 
262
            'code': self.context.code,
 
263
            'url_name': self.context.url_name,
 
264
            'display_name': self.context.display_name,
259
265
            'state': self.context.state,
260
266
            }
261
267
 
262
268
    def save_object(self, req, data):
263
269
        self.context.year = data['year']
264
 
        self.context.semester = data['semester']
 
270
        self.context.code = data['code']
 
271
        self.context.url_name = data['url_name']
 
272
        self.context.display_name = data['display_name']
265
273
        self.context.state = data['state']
266
274
 
267
275
        return self.context
358
366
            year = semester = None
359
367
 
360
368
        semester = state.store.find(
361
 
            Semester, year=year, semester=semester).one()
 
369
            Semester, year=year, url_name=semester).one()
362
370
        if semester:
363
371
            return semester
364
372
        else:
418
426
        super(OfferingEdit, self).populate(req, ctx)
419
427
        ctx['subjects'] = req.store.find(Subject).order_by(Subject.name)
420
428
        ctx['semesters'] = req.store.find(Semester).order_by(
421
 
            Semester.year, Semester.semester)
 
429
            Semester.year, Semester.display_name)
422
430
        ctx['force_subject'] = None
423
431
 
424
432
    def populate_state(self, state):
428
436
        return {
429
437
            'subject': self.context.subject.short_name,
430
438
            'semester': self.context.semester.year + '/' +
431
 
                        self.context.semester.semester,
 
439
                        self.context.semester.url_name,
432
440
            'url': self.context.url,
433
441
            'description': self.context.description,
434
442
            'worksheet_cutoff': self.context.worksheet_cutoff,
462
470
        super(OfferingNew, self).populate(req, ctx)
463
471
        ctx['subjects'] = req.store.find(Subject).order_by(Subject.name)
464
472
        ctx['semesters'] = req.store.find(Semester).order_by(
465
 
            Semester.year, Semester.semester)
 
473
            Semester.year, Semester.display_name)
466
474
        ctx['force_subject'] = None
467
475
 
468
476
    def populate_state(self, state):
514
522
        super(OfferingCloneWorksheets, self).populate(req, ctx)
515
523
        ctx['subjects'] = req.store.find(Subject).order_by(Subject.name)
516
524
        ctx['semesters'] = req.store.find(Semester).order_by(
517
 
            Semester.year, Semester.semester)
 
525
            Semester.year, Semester.display_name)
518
526
 
519
527
    def get_default_data(self, req):
520
528
        return {}