535
535
response = cjson.encode(dict_projectsets)
536
536
req.write(response)
538
def handle_create_project_set(req, fields):
539
"""Required cap: CAP_MANAGEPROJECTS
540
Creates a project set for a offering - returns the projectsetid
542
offeringid, max_students_per_group
545
if req.method != "POST":
546
req.throw_error(req.HTTP_METHOD_NOT_ALLOWED,
547
"Only POST requests are valid methods to create_user.")
548
# Check if this user has CAP_MANAGEPROJECTS
549
if not req.user.hasCap(caps.CAP_MANAGEPROJECTS):
550
req.throw_error(req.HTTP_FORBIDDEN,
551
"You do not have permission to manage projects.")
552
# Get required fields
553
offeringid = fields.getfirst('offeringid')
554
max_students_per_group = fields.getfirst('max_students_per_group')
555
if offeringid is None or max_students_per_group is None:
556
req.throw_error(req.HTTP_BAD_REQUEST,
557
"Required: offeringid, max_students_per_group")
561
dbquery = db.return_insert(
563
'offeringid': offeringid,
564
'max_students_per_group': max_students_per_group,
567
frozenset(["offeringid", "max_students_per_group"]),
572
response = cjson.encode(dbquery.dictresult()[0])
574
req.content_type = "text/plain"
577
def handle_create_project(req, fields):
578
"""Required cap: CAP_MANAGEPROJECTS
579
Creates a project in a specific project set
583
synopsis, url, deadline
588
if req.method != "POST":
589
req.throw_error(req.HTTP_METHOD_NOT_ALLOWED,
590
"Only POST requests are valid methods to create_user.")
591
# Check if this user has CAP_MANAGEPROJECTS
592
if not req.user.hasCap(caps.CAP_MANAGEPROJECTS):
593
req.throw_error(req.HTTP_FORBIDDEN,
594
"You do not have permission to manage projects.")
595
# Get required fields
596
projectsetid = fields.getfirst('projectsetid')
597
if projectsetid is None:
598
req.throw_error(req.HTTP_BAD_REQUEST,
599
"Required: projectsetid")
600
# Get optional fields
601
synopsis = fields.getfirst('synopsis')
602
url = fields.getfirst('url')
603
deadline = fields.getfirst('deadline')
604
if deadline is not None:
606
deadline = util.parse_iso8601(deadline).timetuple()
607
except ValueError, e:
608
req.throw_error(req.HTTP_BAD_REQUEST, e.message)
613
dbquery = db.return_insert(
615
'projectsetid': projectsetid,
616
'synopsis': synopsis,
618
'deadline': deadline,
621
frozenset(["projectsetid", "synopsis", "url", "deadline"]),
622
["projectid"], # returns
625
req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR, repr(e))
629
response = cjson.encode(dbquery.dictresult()[0])
631
req.content_type = "text/plain"
634
538
def handle_create_group(req, fields):
635
539
"""Required cap: CAP_MANAGEGROUPS
636
540
Creates a project group in a specific project set
828
732
"get_active_offerings": handle_get_active_offerings,
829
733
"get_project_groups": handle_get_project_groups,
830
734
"get_group_membership": handle_get_group_membership,
831
"create_project_set": handle_create_project_set,
832
"create_project": handle_create_project,
833
735
"create_group": handle_create_group,
834
736
"assign_group": handle_assign_group,