85
85
# Required cap: None (for yourself)
86
86
# Returns a JSON encoded listing of a students is enrollments
88
# userservice/get_active_offerings(req, fields):
90
# Returns all the active offerings for a particular subject
88
94
# PROJECTS AND GROUPS
96
# userservice/get_project_groups
98
# Returns all the project groups in an offering grouped by project set
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)
468
def handle_get_active_offerings(req, fields):
469
"""Required cap: None
470
Returns all the active offerings for a particular subject
475
subjectid = fields.getfirst('subjectid')
476
if subjectid is None:
477
req.throw_error(req.HTTP_BAD_REQUEST,
478
"Required: subjectid")
480
subjectid = int(subjectid)
482
req.throw_error(req.HTTP_BAD_REQUEST,
483
"subjectid must be a integer")
487
offerings = db.get_offering_semesters(subjectid)
491
response = cjson.encode([o for o in offerings if o['active']])
492
req.content_type = "text/plain"
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
502
offeringid = fields.getfirst('offeringid')
503
if offeringid is None:
504
req.throw_error(req.HTTP_BAD_REQUEST,
505
"Required: offeringid")
507
offeringid = int(offeringid)
509
req.throw_error(req.HTTP_BAD_REQUEST,
510
"offeringid must be a integer")
514
projectsets = db.get_projectsets_by_offering(offeringid)
515
for p in projectsets:
516
p['groups'] = db.get_groups_by_projectset(p['projectsetid'])
518
req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR, repr(e))
522
response = cjson.encode(projectsets)
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)
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))
695
762
return(cjson.encode({'response': 'okay'}))
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,