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

« back to all changes in this revision

Viewing changes to www/apps/userservice/__init__.py

  • Committer: William Grant
  • Date: 2009-01-20 02:58:01 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: grantw@unimelb.edu.au-20090120025801-etj02h3l0uo9dguw
www/apps/userservice: Use Storm rather than get_offering_semesters.
    Also remove a few unneeded DB opens.
ivle.db.get_offering_semesters: Remove. Unused.

Show diffs side-by-side

added added

removed removed

Lines of Context:
454
454
        # If login not specified, update yourself
455
455
        user = req.user
456
456
 
457
 
    db = ivle.db.DB()
458
457
    dict_enrolments = []
459
458
    for e in user.active_enrolments:
460
459
        dict_enrolments.append({
468
467
            'groups':          [{'name': group.name,
469
468
                                 'nick': group.nick} for group in e.groups]
470
469
        })
471
 
    db.close()
472
470
    response = cjson.encode(dict_enrolments)
473
471
    req.content_type = "text/plain"
474
472
    req.write(response)
489
487
    except:
490
488
        req.throw_error(req.HTTP_BAD_REQUEST,
491
489
            "subjectid must be a integer")
492
 
    
493
 
    db = ivle.db.DB()
494
 
    try:
495
 
        offerings = db.get_offering_semesters(subjectid)
496
 
    finally:
497
 
        db.close()
498
 
 
499
 
    response = cjson.encode([o for o in offerings if o['active']])
 
490
 
 
491
    subject = req.store.get(ivle.database.Subject, subjectid)
 
492
 
 
493
    response = cjson.encode([{'offeringid': offering.id,
 
494
                              'subj_name': offering.subject.name,
 
495
                              'year': offering.semester.year,
 
496
                              'semester': offering.semester.semester,
 
497
                              'active': offering.semester.active
 
498
                             } for offering in subject.offerings
 
499
                                    if offering.semester.active])
500
500
    req.content_type = "text/plain"
501
501
    req.write(response)
502
502
 
519
519
 
520
520
    offering = req.store.get(ivle.database.Offering, offeringid)
521
521
 
522
 
    db = ivle.db.DB()
523
522
    dict_projectsets = []
524
523
    try:
525
524
        for p in offering.project_sets:
532
531
            })
533
532
    except Exception, e:
534
533
        req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR, repr(e))
535
 
    finally:
536
 
        db.close()
537
534
 
538
535
    response = cjson.encode(dict_projectsets)
539
536
    req.write(response)