示例#1
0
 def get(self):
     """Returns filtered list of departments from the db using marshal."""
     try:
         search_params = lomarsh(request.args, DepartmentSearchSchema)
         return Operator.get_all(
             Department, search_expr=self._get_search_expr(search_params))
     except ValidationError:
         abort(400)
示例#2
0
    def post(self):
        """Adds a department to the database.

        Returns:
            Department's id using marshal or
            aborts with 404.
        """

        try:
            raw_data = lomarsh(request.form, DepartmentSchema)
            raw_data['id'] = None
            return Operator.insert(Department(**raw_data))
        except IntegrityError:
            abort(400)
示例#3
0
    def post(self):
        """Adds an employee to the database.

        Returns:
            Employee's id using marshal or
            aborts with code 400.
        """

        try:
            raw_data = lomarsh(request.form, EmployeeSchema)
            raw_data['id'] = None
            return Operator.insert(Employee(**raw_data))
        except (IntegrityError, ValidationError):
            abort(400)
示例#4
0
    def put(self, id_):
        """Updates a department from the database by the id.

        Returns:
            True (if the operation was successful)
            or False using marshal or aborts with
            code 400.
        """

        try:
            raw_data = lomarsh(request.form, DepartmentSchema)
            raw_data['id'] = id_
            return Operator.update(Department, raw_data)
        except (IntegrityError, ValidationError):
            abort(400)
示例#5
0
    def put(self, id_):
        """Updates an employee from the database by the id.

        Returns:
            True (if the operation was successful)
            or False using marshal or aborts
            with 400 code.
        """

        try:
            raw_data = lomarsh(request.form, EmployeeSchema)
            raw_data['id'] = id_
            return Operator.update(Employee, raw_data)
        except (IntegrityError, InternalError, ValidationError):
            abort(400)