def post(self): data = request.form factory_name = data["factory_name"] username = data["logistic_name"] address = data["address"] email = data["email"] factory_hotline = data["factory_hotline"] delegate_phone = data["delegate_phone"] password = User.generate_pass() role = 2 img = request.files['factory_logo'] user = User.query.filter_by(email=email).first() if user: return redirect( url_for('base_blueprint.SignupFactory', error="FAILED: user with entered E-mail already exist!")) user = User.query.filter_by(username=username).first() if user: return redirect(url_for('base_blueprint.SignupFactory', error="user with entered name already exist!")) user = User.query.filter_by(phone=delegate_phone).first() if user: return redirect(url_for('base_blueprint.SignupFactory', error="user with entered phone already exist!")) user = User(username=username, email=email, role=role, password=password, phone=delegate_phone, ) db.session.add(user) fac = Factory.query.filter_by(name=factory_name).first() if fac: return redirect(url_for('base_blueprint.SignupFactory', error="factory with entered name already exist!")) fac = Factory.query.filter_by(address=address).first() if fac: return redirect( url_for('base_blueprint.SignupFactory', error="factory with entered address already exist!")) fac = Factory.query.filter_by(hotline=factory_hotline).first() if fac: return redirect( url_for('base_blueprint.SignupFactory', error="factory with entered hot line already exist!")) _, file_extension = os.path.splitext(img.filename) url = upload_file_to_s3(img, file_name=factory_name + file_extension, folder='factory_logo') fac = Factory(name=factory_name, delegate=user.id, address=address, hotline=factory_hotline, logo=url) db.session.add(fac) db.session.commit() admin_users = User.query.filter_by(role=3).all() for admin in admin_users: if admin.device_token: device_token = admin.device_token message_title = "New Factory" message_body = "There are new Factory!" click_action = "/AdminDashboard/factory" result = notf_service.notify_single_device(registration_id=device_token, message_title=message_title, click_action=click_action, message_body=message_body) return redirect(url_for('base_blueprint.login', message="Successfully Signed up, waiting for Admin approve then you will " "receive Accepted E-mail from us"))
def post(self): car_user = None try: role = 4 data = request.form plate_number = data['plate_number'] car = Car.query.filter_by(number=plate_number).first() if car: return redirect( url_for( 'cars_blueprint_company.route_error', error="Car with entered plate number is already exist") ) car_type = int(data['car_type']) if car_type == 1: maktura_plate_number = data["maktura_plate_number"] else: maktura_plate_number = plate_number car_capacity = data['car_capacity'] car_color = data['car_color'] doc_img = request.files['doc_image'] qr_code = Car.generate_qrcode() owner = Company.query.filter_by(_user_id=current_user.id).first() car_user = User(username=plate_number, email=plate_number, password=qr_code, phone=qr_code[0:11], role=role, account_status=1) db.session.add(car_user) db.session.commit() _, file_extension = os.path.splitext(doc_img.filename) url = upload_file_to_s3(doc_img, file_name=plate_number + file_extension, folder='cars_doc') new_car = Car(user_id=car_user.id, number=plate_number, owner=owner.id, qr_code=qr_code, _type=car_type, capacity=car_capacity, color=car_color, doc_img=url, maktura_plate_number=maktura_plate_number) db.session.add(new_car) db.session.commit() print(new_car.serialize()) return redirect(url_for('cars_blueprint_company.company_cars')) except Exception as e: print("Exception in NewCar: ", e) if car_user: db.session.delete(car_user) db.session.commit() return redirect( url_for( 'cars_blueprint_company.route_error', error="Some thing Wrong happened, please try again later"))
def post(self): data = request.form driver_name = data["driver_name"] phone = data["phone"] license_number = data["license_number"] license_type = data["license_type"] company_id = data["company_id"] img = request.files['license_image'] driver = Driver.query.filter_by(name=driver_name).first() if driver: return redirect( url_for( 'driver_blueprint.route_error', error=f"FAILED: Driver name: {driver_name} already exist!") ) driver = Driver.query.filter_by(phone=phone).first() if driver: return redirect( url_for('driver_blueprint.route_error', error=f"FAILED: phone: {phone} already exist!")) driver = Driver.query.filter_by(license_number=license_number).first() if driver: return redirect( url_for( 'driver_blueprint.route_error', error= f"FAILED: license number: {license_number} already exist!!" )) company = Company.query.get(company_id) if not company: return redirect( url_for( 'driver_blueprint.route_error', error=f"FAILED: Company with code: {company_id} not exist!" )) _, file_extension = os.path.splitext(img.filename) url = upload_file_to_s3(img, file_name=driver_name + file_extension, folder='drivers_license') new_driver = Driver(name=driver_name, phone=phone, company_id=company_id, license_number=license_number, license_type=license_type, license_img=url) db.session.add(new_driver) db.session.commit() return redirect(url_for('driver_blueprint.index'))
def post(self, car_id): data = request.form car = Car.query.get(car_id) car.number = data['plate_number'] car.color = data['car_color'] car.capacity = data['car_capacity'] car._type = int(data['car_type']) if int(data['car_type']) == 1: maktura_plate_number = data["maktura_plate_number"] else: maktura_plate_number = data['plate_number'] car.maktura_plate_number = maktura_plate_number doc_img = request.files['doc_image'] or None if doc_img: _, file_extension = os.path.splitext(doc_img.filename) url = upload_file_to_s3(doc_img, file_name=car.number + file_extension, folder='cars_doc') car.doc_img = url db.session.commit() return redirect(url_for("base_blueprint.car_details", id=car_id))
def post(self, driver_id): driver = Driver.query.get(driver_id) if current_user.isCompany and driver.company_obj._user_id != current_user.id: return redirect(url_for("driver_blueprint_company.index")) else: data = request.form driver_name = data["driver_name"] phone = data["phone"] license_number = data["license_number"] license_type = data["license_type"] img = request.files['license_image'] or None driver.name = driver_name driver.phone = phone driver.license_number = license_number driver.license_type = license_type if img: _, file_extension = os.path.splitext(img.filename) url = upload_file_to_s3(img, file_name=driver_name + file_extension, folder='drivers_license') driver.license_img = url db.session.commit() return redirect(url_for("base_blueprint.driver_details", id=driver_id))
def post(self): data = request.form try: img = request.files['factory_logo'] factory_name = data.get('factory_name') username = data.get('username') email = data.get('email') password = User.generate_pass() # 'factory' address = data.get('address') factory_hotline = data.get('factory_hotline') delegate_phone = data.get('delegate_phone') role = 2 user = User.query.filter_by(email=email).first() # img = request.files['factory_logo'] if user: response_obj = { 'status': 'failed', 'message': 'user with entered E-mail already exist!' } return response_obj, 409 user = User.query.filter_by(username=username).first() if user: response_obj = { 'status': 'failed', 'message': 'user with entered name already exist!' } return response_obj, 409 user = User.query.filter_by(phone=delegate_phone).first() if user: response_obj = { 'status': 'failed', 'message': 'user with entered phone already exist!' } return response_obj, 409 user = User(username=username, email=email, role=role, password=password, phone=delegate_phone) db.session.add(user) fac = Factory.query.filter_by(name=factory_name).first() if fac: response_obj = { 'status': 'failed', 'message': 'factory with entered name already exist!' } return response_obj, 409 fac = Factory.query.filter_by(address=address).first() if fac: response_obj = { 'status': 'failed', 'message': 'factory with entered address already exist!' } return response_obj, 409 fac = Factory.query.filter_by(hotline=factory_hotline).first() if fac: response_obj = { 'status': 'failed', 'message': 'factory with entered hot line already exist!' } return response_obj, 409 _, file_extension = os.path.splitext(img.filename) url = upload_file_to_s3(img, file_name=factory_name + file_extension, folder='factory_logo') fac = Factory(name=factory_name, delegate=user.id, address=address, hotline=factory_hotline,logo=url) # fac = Factory(name=factory_name, delegate=user.id, address=address, hotline=factory_hotline) db.session.add(fac) db.session.commit() admin_users = User.query.filter_by(role=3).all() for admin in admin_users: if admin.device_token: device_token = admin.device_token message_title = "New Factory" message_body = "There are new Factory!" click_action = "/AdminDashboard/factory" result = notf_service.notify_single_device(registration_id=device_token, message_title=message_title, click_action=click_action, message_body=message_body) response_obj = { 'status': 'success', 'message': 'Successfully Signed up' } return response_obj, 201 except Exception as e: print('Exception in factory sign up:', e) response_obj = { 'status': 'failed', 'message': 'Something Wrong, please try again later' } return response_obj, 500
def post(self): data = request.form company_name = data.get('company_name') username = company_name # data.get('username') email = data.get('email') password = User.generate_pass() # data.get('password') address = data.get('address') phone = data.get('company_phone') img = request.files['company_logo'] role = 1 user = User.query.filter_by(email=email).first() if user: return redirect( url_for( 'company_blueprint.route_error', error="FAILED: user with entered E-mail already exist!")) user = User.query.filter_by(username=username).first() if user: return redirect( url_for('company_blueprint.route_error', error="FAILED: user with entered name already exist!")) user = User.query.filter_by(phone=phone).first() if user: return redirect( url_for( 'company_blueprint.route_error', error="FAILED: user with entered phone already exist!")) user = User(username=username, email=email, role=role, password=password, phone=phone) db.session.add(user) com = Company.query.filter_by(name=company_name).first() if com: return redirect( url_for( 'company_blueprint.route_error', error="FAILED: company with entered name already exist!")) com = Company.query.filter_by(address=address).first() if com: return redirect( url_for( 'company_blueprint.route_error', error="FAILED: company with entered address already exist!" )) _, file_extension = os.path.splitext(img.filename) url = upload_file_to_s3(img, file_name=company_name + file_extension, folder='company_logo') com = Company(name=company_name, account=user.id, address=address, logo=url) db.session.add(com) db.session.commit() return redirect(url_for('company_blueprint.index'))
def post(self): data = request.form factory_name = data["factory_name"] username = data["logistic_name"] address = data["address"] email = data["email"] factory_hotline = data["factory_hotline"] delegate_phone = data["delegate_phone"] password = User.generate_pass() img = request.files['factory_logo'] role = 2 user = User.query.filter_by(email=email).first() if user: return redirect( url_for( 'factory_blueprint.route_error', error="FAILED: user with entered E-mail already exist!")) user = User.query.filter_by(username=username).first() if user: return redirect( url_for('factory_blueprint.route_error', error="user with entered name already exist!")) user = User.query.filter_by(phone=delegate_phone).first() if user: return redirect( url_for('factory_blueprint.route_error', error="user with entered phone already exist!")) user = User(username=username, email=email, role=role, password=password, phone=delegate_phone, account_status=1) db.session.add(user) fac = Factory.query.filter_by(name=factory_name).first() if fac: return redirect( url_for('factory_blueprint.route_error', error="factory with entered name already exist!")) fac = Factory.query.filter_by(address=address).first() if fac: return redirect( url_for('factory_blueprint.route_error', error="factory with entered address already exist!")) fac = Factory.query.filter_by(hotline=factory_hotline).first() if fac: return redirect( url_for('factory_blueprint.route_error', error="factory with entered hot line already exist!")) _, file_extension = os.path.splitext(img.filename) url = upload_file_to_s3(img, file_name=factory_name + file_extension, folder='factory_logo') fac = Factory(name=factory_name, delegate=user.id, address=address, hotline=factory_hotline, logo=url) db.session.add(fac) db.session.commit() return redirect(url_for('factory_blueprint.index'))