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

« back to all changes in this revision

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

  • Committer: me at id
  • Date: 2009-01-15 05:35:42 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1159
www/apps/groups: Use User.active_enrolments rather than ivle.db.get_enrolment.
www/apps/userservice: Same as 'groups'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
439
439
    ##fullpowers = req.user.hasCap(caps.CAP_GETUSER)
440
440
 
441
441
    try:
442
 
        login = fields.getfirst('login')
443
 
        if login is None:
 
442
        user = ivle.database.User.get_by_login(req.store,
 
443
                    fields.getfirst('login'))
 
444
        if user is None:
444
445
            raise AttributeError()
445
 
        if not fullpowers and login != req.user.login:
 
446
        if not fullpowers and user != req.user:
446
447
            # Not allowed to edit other users
447
448
            req.throw_error(req.HTTP_FORBIDDEN,
448
449
            "You do not have permission to see another user's subjects.")
449
450
    except AttributeError:
450
451
        # If login not specified, update yourself
451
 
        login = req.user.login
 
452
        user = req.user
452
453
 
453
 
    # Just talk direct to the DB
454
454
    db = ivle.db.DB()
455
 
    enrolments = db.get_enrolment(login)
456
 
    for e in enrolments:
457
 
        e['groups'] = db.get_enrolment_groups(login, e['offeringid'])
 
455
    dict_enrolments = []
 
456
    for e in user.active_enrolments:
 
457
        dict_enrolments.append({
 
458
            'offeringid':      e.offering.id,
 
459
            'subj_code':       e.offering.subject.code,
 
460
            'subj_name':       e.offering.subject.name,
 
461
            'subj_short_name': e.offering.subject.short_name,
 
462
            'url':             e.offering.subject.url,
 
463
            'year':            e.offering.semester.year,
 
464
            'semester':        e.offering.semester.semester,
 
465
            'groups':          db.get_enrolment_groups(user.login,
 
466
                                        e.offering.id),
 
467
        })
458
468
    db.close()
459
 
    response = cjson.encode(enrolments)
 
469
    response = cjson.encode(dict_enrolments)
460
470
    req.content_type = "text/plain"
461
471
    req.write(response)
462
472