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

« back to all changes in this revision

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

  • Committer: dcoles
  • Date: 2008-08-09 08:05:13 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1001
Groups: Added the view half of the group admin panel. This lets people with the 
MANAGEGROUPS capibility to see all the project sets and groups in each subject 
offering for that subject. Next is to use the new userservice calls to add and 
modify these groups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
# Required cap: None (for yourself)
86
86
# Returns a JSON encoded listing of a students is enrollments
87
87
 
 
88
# userservice/get_active_offerings(req, fields):
 
89
# Required cap: None
 
90
# Returns all the active offerings for a particular subject
 
91
# Required:
 
92
#   subjectid
 
93
 
88
94
# PROJECTS AND GROUPS
89
95
 
 
96
# userservice/get_project_groups
 
97
# Required cap: None
 
98
# Returns all the project groups in an offering grouped by project set
 
99
# Required:
 
100
#   offeringid
 
101
 
90
102
# userservice/create_project_set
91
103
# Required cap: CAP_MANAGEPROJECTS
92
104
# Creates a project set for a offering
453
465
    req.content_type = "text/plain"
454
466
    req.write(response)
455
467
 
 
468
def handle_get_active_offerings(req, fields):
 
469
    """Required cap: None
 
470
    Returns all the active offerings for a particular subject
 
471
    Required:
 
472
        subjectid
 
473
    """
 
474
 
 
475
    subjectid = fields.getfirst('subjectid')
 
476
    if subjectid is None:
 
477
        req.throw_error(req.HTTP_BAD_REQUEST,
 
478
            "Required: subjectid")
 
479
    try:
 
480
        subjectid = int(subjectid)
 
481
    except:
 
482
        req.throw_error(req.HTTP_BAD_REQUEST,
 
483
            "subjectid must be a integer")
 
484
    
 
485
    db = common.db.DB()
 
486
    try:
 
487
        offerings = db.get_offering_semesters(subjectid)
 
488
    finally:
 
489
        db.close()
 
490
 
 
491
    response = cjson.encode([o for o in offerings if o['active']])
 
492
    req.content_type = "text/plain"
 
493
    req.write(response)
 
494
 
 
495
def handle_get_project_groups(req, fields):
 
496
    """Required cap: None
 
497
    Returns all the project groups in an offering grouped by project set
 
498
    Required:
 
499
        offeringid
 
500
    """
 
501
 
 
502
    offeringid = fields.getfirst('offeringid')
 
503
    if offeringid is None:
 
504
        req.throw_error(req.HTTP_BAD_REQUEST,
 
505
            "Required: offeringid")
 
506
    try:
 
507
        offeringid = int(offeringid)
 
508
    except:
 
509
        req.throw_error(req.HTTP_BAD_REQUEST,
 
510
            "offeringid must be a integer")
 
511
    
 
512
    db = common.db.DB()
 
513
    try:
 
514
        projectsets = db.get_projectsets_by_offering(offeringid)
 
515
        for p in projectsets:
 
516
            p['groups'] = db.get_groups_by_projectset(p['projectsetid'])
 
517
    except Exception, e:
 
518
        req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR, repr(e))
 
519
    finally:
 
520
        db.close()
 
521
 
 
522
    response = cjson.encode(projectsets)
 
523
    req.write(response)
 
524
 
456
525
def handle_create_project_set(req, fields):
457
526
    """Required cap: CAP_MANAGEPROJECTS
458
527
    Creates a project set for a offering - returns the projectsetid
545
614
    req.content_type = "text/plain"
546
615
    req.write(response)
547
616
 
548
 
 
549
617
def handle_create_group(req, fields):
550
618
    """Required cap: CAP_MANAGEGROUPS
551
619
    Creates a project group in a specific project set
691
759
        req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR,
692
760
            "Failure creating repository: %s"%str(usrmgt))
693
761
 
694
 
 
695
762
    return(cjson.encode({'response': 'okay'}))
696
763
 
697
764
# Map action names (from the path)
702
769
    "update_user": handle_update_user,
703
770
    "get_user": handle_get_user,
704
771
    "get_enrolments": handle_get_enrolments,
 
772
    "get_active_offerings": handle_get_active_offerings,
 
773
    "get_project_groups": handle_get_project_groups,
705
774
    "create_project_set": handle_create_project_set,
706
775
    "create_project": handle_create_project,
707
776
    "create_group": handle_create_group,