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

« back to all changes in this revision

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

Semesters now have separate URL name, display name and code attributes.

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 SubjectUniquenessValidator(formencode.FancyValidator):
200
200
    """
201
201
    def _to_python(self, value, state):
202
202
        if (state.store.find(
203
 
                Semester, year=value['year'], semester=value['semester']
 
203
                Semester, year=value['year'], url_name=value['url_name']
204
204
                ).one() not in (None, state.existing_semester)):
205
205
            raise formencode.Invalid(
206
206
                'Semester already exists', value, state)
209
209
 
210
210
class SemesterSchema(formencode.Schema):
211
211
    year = URLNameValidator()
212
 
    semester = URLNameValidator()
 
212
    code = formencode.validators.UnicodeString()
 
213
    url_name = URLNameValidator()
 
214
    display_name = formencode.validators.UnicodeString()
213
215
    state = formencode.All(
214
216
        formencode.validators.OneOf(["past", "current", "future"]),
215
217
        formencode.validators.UnicodeString())
244
246
    def save_object(self, req, data):
245
247
        new_semester = Semester()
246
248
        new_semester.year = data['year']
247
 
        new_semester.semester = data['semester']
 
249
        new_semester.code = data['code']
 
250
        new_semester.url_name = data['url_name']
 
251
        new_semester.display_name = data['display_name']
248
252
        new_semester.state = data['state']
249
253
 
250
254
        req.store.add(new_semester)
261
265
    def get_default_data(self, req):
262
266
        return {
263
267
            'year': self.context.year,
264
 
            'semester': self.context.semester,
 
268
            'code': self.context.code,
 
269
            'url_name': self.context.url_name,
 
270
            'display_name': self.context.display_name,
265
271
            'state': self.context.state,
266
272
            }
267
273
 
268
274
    def save_object(self, req, data):
269
275
        self.context.year = data['year']
270
 
        self.context.semester = data['semester']
 
276
        self.context.code = data['code']
 
277
        self.context.url_name = data['url_name']
 
278
        self.context.display_name = data['display_name']
271
279
        self.context.state = data['state']
272
280
 
273
281
        return self.context
364
372
            year = semester = None
365
373
 
366
374
        semester = state.store.find(
367
 
            Semester, year=year, semester=semester).one()
 
375
            Semester, year=year, url_name=semester).one()
368
376
        if semester:
369
377
            return semester
370
378
        else:
424
432
        super(OfferingEdit, self).populate(req, ctx)
425
433
        ctx['subjects'] = req.store.find(Subject).order_by(Subject.name)
426
434
        ctx['semesters'] = req.store.find(Semester).order_by(
427
 
            Semester.year, Semester.semester)
 
435
            Semester.year, Semester.display_name)
428
436
        ctx['force_subject'] = None
429
437
 
430
438
    def populate_state(self, state):
434
442
        return {
435
443
            'subject': self.context.subject.short_name,
436
444
            'semester': self.context.semester.year + '/' +
437
 
                        self.context.semester.semester,
 
445
                        self.context.semester.url_name,
438
446
            'url': self.context.url,
439
447
            'description': self.context.description,
440
448
            'worksheet_cutoff': self.context.worksheet_cutoff,
468
476
        super(OfferingNew, self).populate(req, ctx)
469
477
        ctx['subjects'] = req.store.find(Subject).order_by(Subject.name)
470
478
        ctx['semesters'] = req.store.find(Semester).order_by(
471
 
            Semester.year, Semester.semester)
 
479
            Semester.year, Semester.display_name)
472
480
        ctx['force_subject'] = None
473
481
 
474
482
    def populate_state(self, state):
520
528
        super(OfferingCloneWorksheets, self).populate(req, ctx)
521
529
        ctx['subjects'] = req.store.find(Subject).order_by(Subject.name)
522
530
        ctx['semesters'] = req.store.find(Semester).order_by(
523
 
            Semester.year, Semester.semester)
 
531
            Semester.year, Semester.display_name)
524
532
 
525
533
    def get_default_data(self, req):
526
534
        return {}