Esempio n. 1
0
    def put(self, name):
        is_admin = Position.is_admin()
        if not is_admin:
            return {'message': 'You are not privileged to continue!'}, 400

        data = Position.parser.parse_args()
        error_validation = validators.position_validator(**data)
        if error_validation['error validation']:
            return error_validation

        user = g.user

        if not user.verify_password(data['password']):
            return {
                'message':
                'You can not update a position because you have typed a wrong password!'
            }, 400

        position = PositionModel.find_by_name(name)
        log = LogModel("update position '{}'".format(name), g.user.username,
                       Position.admin)

        if position is None:
            position = PositionModel(name)
        # else:
        #     position.name = name

        position.save_to_db()
        log.save_to_db()

        return position.json()
Esempio n. 2
0
    def post(self):
        data = Position.parser.parse_args()
        if PositionModel.find_by_position(data["template_id"], data["task_id"],
                                          data["position_no"]):
            return {"message": "A position with this name already exists"}, 400

        position = PositionModel(data["template_id"], data["task_id"],
                                 data["position_no"])

        try:
            position.save_to_db()
        except:
            return {"message": "An error occured editing the position"}, 500

        return position.json(), 201
Esempio n. 3
0
    def put(self):
        data = Position.parser.parse_args()
        if PositionModel.find_by_position(data["template_id"], data["task_id"],
                                          data["position_no"]):
            return (
                {
                    "message":
                    "This position has already been allocated to this template"
                },
                500,
            )

        position = PositionModel(data["template_id"], data["task_id"],
                                 data["position_no"])

        try:
            position.save_to_db()
            return position.json(), 201
        except:
            return {"message": "An error occured inserting the position"}, 500
Esempio n. 4
0
    def post(self, name):
        # begin
        is_admin = Position.is_admin()
        if not is_admin:
            return {'message': 'You are not privileged to continue!'}, 400
        # end

        data = Position.parser.parse_args()
        error_validation = validators.position_validator(**data)
        if error_validation['error validation']:
            return error_validation

        user = g.user  # this

        # start
        if not user.verify_password(data['password']):
            return {
                'message':
                'You can not add a new position because you have typed a wrong password!'
            }, 400
        # end

        if PositionModel.find_by_name(name):
            return {
                'message':
                "A position with name '{}' already exists.".format(name)
            }, 400

        position = PositionModel(name)
        log = LogModel("add position '{}'".format(name), g.user.username,
                       Position.admin)

        try:
            position.save_to_db()
            log.save_to_db()
        except:
            return {
                'message': 'An error occurred while creating the position.'
            }, 500

        return position.json(), 201