def company_create(): # only admin is allowed to add new companies if not is_admin(current_user): return render_error_page_unauthorized_access() form = RegistrationForm() if form.validate_on_submit(): company = CompanyModel(name=form.company_name.data, email=form.email.data, phone=form.phone.data) company.save_to_db() address = AddressModel(line1=form.line1.data, line2=form.line2.data, city=form.city.data, state=form.state.data, zip=form.zip.data, company_id=company.id, user_id=1) address.save_to_db() return redirect(url_for("company.company_info")) return render_template("company_create.html", form=form)
def post(self): data = self.company_parser.parse_args() company = CompanyModel.find_by_name(data["company_name"]) # auth group: admin only identity = get_jwt_identity() if not identity["auth_level"] == "admin": return {"message": "unauthorized access."}, 500 if company: return {"message": "company with this name already exits."}, 400 company = CompanyModel(data["company_name"], data["email"], data["phone"]) company.save_to_db() line2 = data["line2"] if not line2: line2 = "" address = AddressModel( line1=data["line1"], line2=line2, city=data["city"], state=data["state"], zip=data["zip"], company_id=company.id, user_id=1 # 1=not applicable ) address.save_to_db() return { "message": "company '{}' is created successfully.".format( data["company_name"]) }, 200
def post(self): data = self.adr_parser.parse_args() address = AddressModel( line1=data["line1"], line2=data["line2"], city=data["city"], state=data["state"], zip=data["zip"], company_id=data["company_id"] if data["company_id"] else 1, # 1 = not applicable user_id=data["user_id"] if data["user_id"] else 1 # 1=not applicable ) address.save_to_db() return {"message":"address created sucsessfully."}
def post(self): data = self.adr_parser.parse_args() address = AddressModel.find_by_id(data["address_id"]) if not address: return {"message":"address with id {} not found".format(data["address_id"])},400 return address.json(),200
def address_create(company_id, user_id): form = AddressCreateForm() if form.validate_on_submit(): address = AddressModel(line1=form.line1.data, line2=form.line2.data, city=form.city.data, state=form.state.data, zip=form.zip.data, company_id=company_id, user_id=user_id) address.save_to_db() return redirect(url_for("company.company_info")) return render_template("address_create.html", form=form)
def address_delete(address_id): address = AddressModel.find_by_id(address_id) if address: address.delete_from_db() return redirect(url_for("company.company_info"))
def delete(self): data = self.adr_parser.parse_args() address = AddressModel.find_by_id(data["address_id"]) if not address: return {"message":"address with id {} not found".format(data["address_id"])},400 address.delete_from_db() return {"message":"address deleted successfully."},200
def put(self): data = self.adr_parser.parse_args() address = AddressModel.find_by_id(data["address_id"]) if not address: return {"message":"address with id {} not found".format(data["address_id"])},400 address.line1 = data["line1"] address.line2 = data["line2"] address.city = data["city"] address.state= data["state"] address.zip = data["zip"] address.save_to_db() return {"message":"address updated successfully."},200
def address_update(address_id): form = AddressCreateForm() address = AddressModel.find_by_id(address_id) if form.validate_on_submit(): address.line1 = form.line1.data address.line2 = form.line2.data address.city = form.city.data address.state = form.state.data address.zip = form.zip.data address.save_to_db() return redirect(url_for("company.company_info")) form.line1.data = address.line1 form.line2.data = address.line2 form.city.data = address.city form.state.data = address.state form.zip.data = address.zip return render_template("address_create.html", form=form)