def add_driver_details(self, first_name, last_name, gender, phone, birth_date): """ Handles the driver details related to a particular vehicle """ driver = Driver(first_name, last_name, gender, phone, birth_date) driver.save() self.driver_id = driver.id
def delete_driver(current_user, driver_id): """route: /driver/delete POST: Edit a driver for a company, params: name, email, contact_number All params are optional except for id """ Driver.delete(driver_id) return common.to_json({}, "Driver deleted!", 200)
def json_serialize(self): return { 'public_id': self.public_id, 'name': self.name, 'country': self.country, 'contact_number': self.contact_number, 'drivers': Driver.json_serialize_array(self.drivers), 'garbageCans': GarbageCan.json_serialize_list(self.garbageCans), 'truck_count': self.truck_count, 'truck_volume': self.truck_volume, 'latitude': self.latitude, 'longitude': self.longitude }
def edit_driver(current_user, driver_id): """route: /driver/edit POST: Edit a driver for a company, params: name, email, contact_number All params are optional except for id """ name = str(request.data.get('name', '')) email = str(request.data.get('email', '')) contact_number = str(request.data.get('contact_number', '')) if Driver.edit(driver_id, name, email, contact_number): return common.to_json({}, "Driver edited!", 200) else: return common.to_json({}, "Driver edit failed!", 400)
def add_driver(current_user): """route: /driver/new POST: Add a driver for a company, params: name, email, contact_number """ name = str(request.data.get('name', '')) email = str(request.data.get('email', '')) contact_number = str(request.data.get('contact_number', '')) if name and email and contact_number: current_user.company.drivers.append(Driver(name, email, contact_number)) db.session.commit() return common.to_json(current_user.json_serialize(), "Driver Added!", 200) else: return common.to_json({}, "Insufficient details for driver!", 400)
def reprocess_failed_sites(): session = Session() failed_sites = session.query(Screenshot).filter_by(failed=True) for site in failed_sites: site = session.query(Site).get(site.site_id) log_filename = f"screenshot_{file_safe_timestamp()}.log" driver = Driver(log_filename) driver.run(site, session) driver.quit() session.close()
def process_sites(): session = Session() sites = session.query(Site).filter_by(processed=False) for site in sites: log_filename = f"screenshot_{file_safe_timestamp()}.log" driver = Driver(log_filename) driver.run(site, session) driver.quit() session.close()