예제 #1
0
파일: views.py 프로젝트: fredwilliam/PMO
    def post(req):
        # delete notification if a delete button was pressed.
        if req.POST.get("delete", ""):
            pk = resource.pk
            resource.delete()

            transaction.commit()
            return message(req, "Resource %d deleted" % (pk), link="/resources")
        else:
            # check the form for errors
            notice_errors = check_resource_form(req)

            # if any fields were missing, abort.
            missing = notice_errors["missing"]
            exists = notice_errors["exists"]

            if missing:
                transaction.rollback()
                return message(req, "Missing Field(s): %s" % comma(missing), link="/resources/add")

            try:
                # create the resource object from the form
                cat = ResourceCategory.objects.get(pk=req.POST.get("category", ""))
                resource.category = cat

                status = Status.objects.get(pk=req.POST.get("status", ""))
                resource.status = status

                pk = req.POST.get("facility", "")
                if pk != "":
                    facility = Facility.objects.get(pk=req.POST.get("facility", ""))
                    resource.facility = facility
                else:
                    resource.facility = None

                resource.name = req.POST.get("name", "")
                resource.code = req.POST.get("code", "")

                # save the changes to the db
                resource.save()
                transaction.commit()

                # full-page notification
                return message(req, "A resource %s updated" % (resource.pk), link="/resources")

            except Exception, err:
                transaction.rollback()
                raise
예제 #2
0
파일: views.py 프로젝트: fredwilliam/PMO
    def post(req):
        # check the form for errors
        notice_errors = check_resource_form(req)

        # if any fields were missing, abort.
        missing = notice_errors["missing"]
        exists = notice_errors["exists"]

        if missing:
            transaction.rollback()
            return message(req, "Missing Field(s): %s" % comma(missing), link="/resources/add")
        # if a resource with the same code is already register abort
        if exists:
            transaction.rollback()
            return message(req, "%s already exist" % comma(exists), link="/resources/add")

        # TODO: Finish adding a resource.
        try:
            # create the resource object from the form
            resource = Resource()

            cat = ResourceCategory.objects.get(pk=req.POST.get("category", ""))
            resource.category = cat

            status = Status.objects.get(pk=req.POST.get("status", ""))
            resource.status = status

            facility = Facility.objects.get(pk=req.POST.get("facility", ""))
            resource.facility = facility

            resource.name = req.POST.get("name", "")
            resource.code = req.POST.get("code", "")

            # save the changes to the db
            resource.save()
            transaction.commit()

            # full-page notification
            return message(req, "A resource %s added" % (resource.pk), link="/resources")

        except Exception, err:
            transaction.rollback()
            raise