~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 03:06:30 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: grantw@unimelb.edu.au-20090120030630-j7v36q51cnni41ul
www/apps/userservice: Remove create_project(_set). They didn't work, aren't
    used anywhere, and would need significant porting work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
535
535
    response = cjson.encode(dict_projectsets)
536
536
    req.write(response)
537
537
 
538
 
def handle_create_project_set(req, fields):
539
 
    """Required cap: CAP_MANAGEPROJECTS
540
 
    Creates a project set for a offering - returns the projectsetid
541
 
    Required:
542
 
        offeringid, max_students_per_group
543
 
    """
544
 
    
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")
558
 
 
559
 
    # Talk to the DB
560
 
    db = ivle.db.DB()
561
 
    dbquery = db.return_insert(
562
 
        {
563
 
            'offeringid': offeringid,
564
 
            'max_students_per_group': max_students_per_group,
565
 
        },
566
 
        "project_set",
567
 
        frozenset(["offeringid", "max_students_per_group"]),
568
 
        ["projectsetid"],
569
 
    )
570
 
    db.close()
571
 
    
572
 
    response = cjson.encode(dbquery.dictresult()[0])
573
 
 
574
 
    req.content_type = "text/plain"
575
 
    req.write(response)
576
 
 
577
 
def handle_create_project(req, fields):
578
 
    """Required cap: CAP_MANAGEPROJECTS
579
 
    Creates a project in a specific project set
580
 
    Required:
581
 
        projectsetid
582
 
    Optional:
583
 
        synopsis, url, deadline
584
 
    Returns:
585
 
        projectid
586
 
    """
587
 
    
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:
605
 
        try:
606
 
            deadline = util.parse_iso8601(deadline).timetuple()
607
 
        except ValueError, e:
608
 
            req.throw_error(req.HTTP_BAD_REQUEST, e.message)
609
 
 
610
 
    # Talk to the DB
611
 
    db = ivle.db.DB()
612
 
    try:
613
 
        dbquery = db.return_insert(
614
 
            {
615
 
                'projectsetid': projectsetid,
616
 
                'synopsis': synopsis,
617
 
                'url': url,
618
 
                'deadline': deadline,
619
 
            },
620
 
            "project", # table
621
 
            frozenset(["projectsetid", "synopsis", "url", "deadline"]),
622
 
            ["projectid"], # returns
623
 
        )
624
 
    except Exception, e:
625
 
        req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR, repr(e))
626
 
    finally:
627
 
        db.close()
628
 
    
629
 
    response = cjson.encode(dbquery.dictresult()[0])
630
 
 
631
 
    req.content_type = "text/plain"
632
 
    req.write(response)
633
 
 
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,
835
737
}