def caradd(): "Add a car to inventory; restrict to admin or sales only." global vin_cache, vin_tsize, vin_table if "role" not in session.keys() or session["role"] not in ["Admin", "Sales"]: return redirect(url_for("home")) if request.method == "POST": if validate_table(caradd_ft, request.form): vin = request.form[caradd_ft[0]] make = request.form[caradd_ft[1]] model = request.form[caradd_ft[2]] year = request.form[caradd_ft[3]] retail = request.form[caradd_ft[4]] message = "" # validate the form if len(vin) != 17: message = "VIN must be 17 characters long ({})".format(len(vin)) if not 1 <= len(make) <= 30: message = "Make must be 1 to 30 characters long ({})".format(len(make)) if not 1 <= len(model) <= 30: message = "Model must be 1 to 30 characters long ({})".format(len(model)) if len(year) != 4: message = "Year must be 4 characters long ({})".format(len(year)) if not 1 <= len(model) <= 30: message = "Retail price must be 1 to 30 characters long ({})".format(len(model)) # check if form is validated if message == "": # check if car already exist car = Car.query.filter_by(vin=vin).first() if not car: # add the car newcar = Car(vin, make, model, year, retail) db.session.add(newcar) db.session.commit() if vin_cache == True: vin_table.append(vin) vin_tsize += 1 message = "Car added; review the car management list." else: message = "Car failed; {} already exist in database.".format(vin) return redirect(url_for("carmanage", page=1, message=message)) return render_template("cartemps/caradd.html", vin=genvin())
class ServiceInfo(db.Model): "Service class containing service history." "SID | CID | VIN | Description | Charge | Date | Status" __tablename__ = "service_info" sid = db.Column(db.Integer, primary_key=True, autoincrement=True) cid = db.Column(db.Integer, db.ForeignKey("customer_info.cid", onupdate="cascade"), nullable=False) vin = db.Column(db.String(20), db.ForeignKey("car.vin", onupdate="cascade"), nullable=False) sdesc = db.Column(db.String(250)) scost = db.Column(db.String(100)) sdate = db.Column(db.String(100)) stats = db.Column(db.Integer) def __init__(self, cid, vin, sdesc, scost, sdate, stats=1): self.cid = cid self.vin = vin self.sdesc = sdesc self.scost = scost self.sdate = sdate self.stats = stats # ============================================================================== # The VIN table is a in-memory cache to increase searching efficiency. # ============================================================================== if len(argv) <= 1: if vin_cache == True: for car in Car.query: vin_table.append(car.vin) vin_tsize = len(vin_table)