Ejemplo n.º 1
0
 def post(self):
     args = parser.parse_args()
     with session_scope() as session:
         new_id = insert_vehicle(session, args["requestId"],
                                 args["assetType"], args["startDate"],
                                 args["endDate"])
         return {"success": True, 'id': new_id}
Ejemplo n.º 2
0
 def patch(self):
     args = role_parser.parse_args()
     if args['name'] is None or args['name'] == '':
         return
     with session_scope() as session:
         toggle_role(session, args['name'])
     return
Ejemplo n.º 3
0
 def patch(self):
     args = qualification_parser.parse_args()
     if args['name'] is None or args['name'] == '':
         return
     with session_scope() as session:
         toggle_qualification(session, args['name'])
     return
Ejemplo n.º 4
0
 def post(self):
     args = qualification_parser.parse_args()
     if args['name'] is None or args['name'] == '':
         return
     with session_scope() as session:
         role_id = add_qualification(session, args['name'])
         return {'id': role_id}
Ejemplo n.º 5
0
 def post(self):
     args = parser.parse_args()
     if args["title"] is None:
         return
     with session_scope() as session:
         new_id = new_request(session, args["title"])
         return {"id": new_id}
Ejemplo n.º 6
0
    def get(self):
        args = parser.parse_args()
        if args["requestId"] is None:
            return

        with session_scope() as session:
            asset_requests = []
            vehicles = get_vehicles(session, args['requestId'])
            for vehicle in vehicles:
                vehicle_id, asset_class, start_date, end_date = vehicle
                asset_requests.append({
                    "shiftID": vehicle_id,
                    "assetClass": asset_class,
                    "timeframe": (start_date, end_date)
                })
            volunteers = list_volunteers(session)

            # Get the generated recommendation
            output = schedule(volunteers, asset_requests)

            if not output == []:
                print("Optimisation Succeeded")

            # Persist the optimisation! we don't ask the fkn front end to manage the backends data! This is completely
            # insane and the reason the front end is a cluster fk!
            for vehicle in output:
                vehicle_id = vehicle['shiftID']
                for volunteer in vehicle['volunteers']:
                    volunteer_id = volunteer['ID']
                    if volunteer_id == -1:
                        volunteer_id = None
                    position = volunteer['positionID']
                    role = volunteer['role']
                    add_shift(session, volunteer_id, vehicle_id, position, role)
            return {"results": output}
Ejemplo n.º 7
0
 def patch(self):
     args = asset_type_parser.parse_args()
     if args['code'] is None or args['code'] == '':
         return
     with session_scope() as session:
         toggle_asset_type(session, args['code'])
     return
Ejemplo n.º 8
0
    def patch(self):
        args = parser.parse_args()
        if args["volunteerID"] is None or args["prefHours"] is None:
            return {"success": False}

        with session_scope() as session:
            set_preferred_hours(session, args['volunteerID'], args["prefHours"])
            return {"success": True}
Ejemplo n.º 9
0
    def get(self):
        args = parser.parse_args()
        if args["volunteerID"] is None:
            return {"success": False}

        with session_scope() as session:
            res = get_volunteer(session, args['volunteerID'])
            return {"success": True, "prefHours": res.preferred_hours}
Ejemplo n.º 10
0
 def get(self):
     with session_scope() as session:
         rtn = []
         for row in list_volunteers(session):
             # Access protected _asdict() to return the keyed tuple as a dict to enable flask_restful to marshal
             # it correctly. The alternative method is less tidy.
             rtn.append(row._asdict())
         return {"success": True, "results": rtn}
Ejemplo n.º 11
0
    def get(self):
        args = parser.parse_args()
        if args["volunteerID"] is None:
            return {"success": False}

        with session_scope() as session:
            res = get_volunteer(session, args["volunteerID"])
            return {"success": True, "availability": res.availabilities}
Ejemplo n.º 12
0
 def post(self):
     args = asset_type_parser.parse_args()
     if args['name'] is None or args['name'] == '':
         return
     if args['code'] is None or args['code'] == '':
         return
     with session_scope() as session:
         asset_type_id = add_asset_type(session, args['code'], args['name'])
         return {'id': asset_type_id}
Ejemplo n.º 13
0
    def get(self):
        args = parser.parse_args()
        if args["idVolunteer"] is None or args["idVehicle"] is None:
            return {"status": None, "success": False}

        with session_scope() as session:
            res = get_asset_request_volunteer(session, args["idVolunteer"],
                                              args["idVehicle"])
            return {"success": True, "status": res.status}
Ejemplo n.º 14
0
    def get(self):
        args = parser.parse_args()

        if args["requestId"] is None: return {"success": False}

        with session_scope() as session:
            return {
                "success": (count_vehicles(session, args["requestId"]) > 0)
            }
Ejemplo n.º 15
0
 def post(self):
     request.get_json(force=True)
     args = registration_parser.parse_args()
     auth = AuthenticationService()
     with session_scope() as session:
         result = auth.register(session, args['email'], args['password'],
                                args['given_name'], args['last_name'],
                                args['phone'])
     return jsonify({"result": result.name})
Ejemplo n.º 16
0
    def get(self):
        args = parser.parse_args()
        if args["volunteerID"] is None:
            return {"success": False}

        with session_scope() as session:
            rtn = []
            for row in list_volunteers(session, args["volunteerID"]):
                # Access protected _asdict() to return the keyed tuple as a dict to enable flask_restful to marshal
                # it correctly. The alternative method is less tidy.
                rtn.append(row._asdict())
            return rtn[0]
Ejemplo n.º 17
0
 def patch(self):
     args = parser.parse_args()
     if args["volunteerID"] is None or args["availability"] is None:
         return {"success": False}
     try:
         json.dumps(args["availability"])
     except:
         return {"success": False}
     with session_scope() as session:
         set_availabilities(session, args["volunteerID"],
                            args["availability"])
         return {"success": True}
Ejemplo n.º 18
0
    def patch(self):

        args = parser.parse_args()
        if args["idVolunteer"] is None or args["idVehicle"] is None or args[
                "status"] is None:
            return {"success": False}
        if args['status'] not in ["confirmed", "rejected"]:
            return {"success": False}

        with session_scope() as session:
            set_asset_request_volunteer_status(session, args['status'],
                                               args["idVolunteer"],
                                               args["idVehicle"])
            return {"success": True}
Ejemplo n.º 19
0
 def post(self):
     request.get_json(force=True)
     args = login_parser.parse_args()
     auth = AuthenticationService()
     with session_scope() as session:
         result, token, user = auth.login(session, args['email'],
                                          args['password'])
         if token is None:
             return jsonify({"result": result.name})
         return jsonify({
             "result": result.name,
             "access_token": token,
             "role": user.role.name,
             'id': user.id
         })
Ejemplo n.º 20
0
 def get(self):
     with session_scope() as session:
         res = get_existing_requests(session)
         return {"success": True, "results": res}
Ejemplo n.º 21
0
 def delete(self):
     args = delete_parser.parse_args()
     with session_scope() as session:
         result = delete_request(session, args["requestID"])
         return result
Ejemplo n.º 22
0
 def get(self):
     with session_scope() as session:
         return get_qualifications(session)
Ejemplo n.º 23
0
 def get(self):
     with session_scope() as session:
         return get_roles(session)
Ejemplo n.º 24
0
 def delete(self):
     args = delete_parser.parse_args()
     with session_scope() as session:
         result = delete_vehicle(session, args["requestId"],
                                 args["vehicleID"])
         return {"success": result}
Ejemplo n.º 25
0
 def get(self):
     with session_scope() as session:
         return get_asset_type(session)