class CustomerPersistence: customers = [ Customer(555555, 'nif', '11223344E', '*****@*****.**', 'Enriqueta', 'Parlem', '668668668'), Customer(555556, 'nif', '44332211F', '*****@*****.**', 'David', 'David Enterprise', '667667667') ] def get_all_customers(self): return self.customers def get_customer_by_id(self, id): for customer in self.customers: if customer._id == id: return customer
def process_registration(): """Process user registration""" first_name = request.form.get("first_name") last_name = request.form.get("last_name") email = request.form.get("email") password = request.form.get("password") password = pbkdf2_sha256.encrypt(password, rounds=20000, salt_size=16) street_address = request.form.get("address") zipcode = request.form.get("zipcode") state = request.form.get("state") phone = request.form.get("phone") user = Customer(first_name=first_name, last_name=last_name, email=email, password_hash=password, street_address=street_address, zipcode=zipcode, state=state, phone=phone) db.session.add(user) db.session.commit() session['email'] = email if session.get('email'): flash("Registration successful! Welcome to Farm to Front Door.") else: flash("Please enable cookies to log in") return redirect("/products")
def customers(): ''' 'GET': show customers table. 'POST': save a new customer or add a car to existing customer. ''' if request.method == 'POST': fullname = (request.form['fullname']).split() last_name = fullname[0] first_name = fullname[1] if len(fullname) == 3: middle_name = fullname[2] else: middle_name = '' phone_number = request.form['phone_number'] car_brand = request.form['car_brand'] car_number = request.form['car_number'] new_customer = Customer( last_name=last_name, first_name=first_name, middle_name=middle_name, phone_number=phone_number, ) new_car = Car( brand=car_brand, number=car_number, customer=new_customer, ) db_session.add(new_customer) db_session.add(new_car) db_session.commit() return redirect(url_for('customers')) else: customers = db_session.query(Customer).all() return render_template('customers.html', customers=customers)
def add_customer(cname, cphno, cemail, caddress): customer = Customer(customer_name=cname, customer_phno=cphno, customer_email=cemail, customer_address=caddress) session.add(customer) session.commit()
def setUp(self): self._frame = CarbonFrame(10, 100) self._frontWheel = RoadWheel("Front RoadWheel", 10, 100) self._backWheel1 = MountainWheel("Back MountainWheel", 10, 100) self._backWheel2 = RoadWheel("Back RoadWheel", 10, 100) self._bike = BicycleModel("Good Build", self._frontWheel, self._backWheel2, self._frame) self._customer = Customer('Customer', 10000)
def create_customer(cname, cphno, caddress): customer = Customer(customer_name=cname, customer_phno=cphno, customer_address=caddress) session.add(customer) session.commit
def create_customer(): f_name = input("First Name: ") l_name = input("Last Name: ") email = input("Email: ") customer = Customer(f_name=f_name, l_name=l_name, email=email) session.add(customer) session.commit() print('created!\n')
def load_customers(): """Load customer from faker into database.""" email_company = ['@gmail.com', '@hotmail.com'] for i in range(0, 43): first_name = fake.first_name_male() last_name = fake.last_name() email = first_name + last_name + random.choice(email_company) customer = Customer(first_name=first_name, last_name=last_name, gender_code='M', phone_number=str(fake.phone_number()), email=email, birth_date=fake.date(pattern="%Y %m %d"), address=fake.street_address(), city=fake.city(), state='CA', zipcode=int(fake.zipcode()), user_id=1) db.session.add(customer) for i in range(0, 57): first_name = fake.first_name_male() last_name = fake.last_name() email = first_name + last_name + random.choice(email_company) customer = Customer(first_name=first_name, last_name=last_name, gender_code='FM', phone_number=str(fake.phone_number()), email=email, birth_date=fake.date(pattern="%Y %m %d"), address=fake.street_address(), city=fake.city(), state='CA', zipcode=int(fake.zipcode()), user_id=1) db.session.add(customer) db.session.commit()
def new_cusotmer(email, password, address, phone, name, data): existing_user = Customer.query.filter_by(email=email).first() if existing_user: return "Email already exist" customer = Customer(email, password, address, phone, name) customer.fb_link = data.get('fb_link') db.session.add(customer) db.session.commit()
def test(self): bravit = self.table.create_customer( Customer(name="Виталий Брагилевский")) cid = bravit.id customer = self.table.find_customer(cid) self.assertEqual(bravit, customer) self.table.delete_customer(cid) customer = self.table.find_customer(cid) self.assertEqual(None, customer)
def customer_create(): form = CustomerForm(request.form) if form.validate_on_submit(): customer = Customer(phone=form.phone.data, email=form.email.data, name=form.name.data) return redirect('/') return render_template('customer/create.html', form=form)
def main(): customers = [] # Manually Generate The first 'Customer' with completely random values. customers.append(Customer()) customers[0].interArrival = None customers[0].state = "In Service" # this loop generates 4 other 'Customers' and appends them to 'customers' list. for i in range(1, 8): new = Customer() _arrivalTime = customers[i - 1].arrivalTime + new.interArrival _serviceBegin = max(customers[i - 1].serviceEnds, _arrivalTime) _serviceEnd = _serviceBegin + new.serviceDuration new.arrivalTime = _arrivalTime new.serviceBegin = _serviceBegin new.serviceEnds = _serviceEnd new.id = i + 1 # check for the customer state. if new.arrivalTime < new.serviceBegin: new.state = new.serviceBegin - new.arrivalTime else: new.state = 0 customers.append(new) """ for customer in customers: print "interArrival => " + str(customer.interArrival) + \ "\t| arrivalTime => " + str(customer.arrivalTime) +\ "\t| Service Begin => " + str(customer.serviceBegin) +\ "\t| Service Duration => " + str(customer.serviceDuration) +\ "\t| Service End => " + str(customer.serviceEnds) """ for cust in customers: cust.points = [] start = cust.arrivalTime end = cust.serviceEnds for i in range(start, end): obj = {"x": i + 1, "y": 1} cust.points.append(obj) return render_template('index.html', customers=customers)
def on_post(self, req, resp): new_customer = Customer(name=req.get_json('name'), dob=req.get_json('dob')) dbsession = self.db.session dbsession.add(new_customer) dbsession.commit() resp.status = falcon.HTTP_201 resp.json = dict(id=new_customer.id, name=new_customer.name, dob=new_customer.dob.strftime('%Y-%d-%m')) dbsession.close()
def customer_new(): form = Form_customer_new() if request.method == 'POST': name = request.form['name'] print(request.form['name']) print(request.form['address']) print(request.form['tel']) c = Customer(name=request.form['name'], address=request.form['address'], tel=request.form['tel']) db.session.add(c) db.session.flush() print(c.id) return render_template('customer_new_result.html', cus=c) return render_template('customer_new.html', form=form)
def load_customers(): """ Load customers from customers.txt to database""" for row in open("seed_data/customers.txt"): row = row.strip() id, name, email, company_id, phone_number, job_title = row.split("|") customer = Customer(id=id.strip(), name=name.strip(), email=email.strip(), company_id=company_id.strip(), phone_number=phone_number.strip(), job_title=job_title.strip()) db.session.add(customer) db.session.commit()
def dispatch_request(self): form = CreateCustomer() if request.method == 'POST': if form.validate_on_submit(): customer = Customer( name=request.form.get("name"), address=request.form.get("address"), email=request.form.get("email"), zip_code=request.form.get("zip_code"), iva_code=request.form.get("iva_code"), phone_number=request.form.get("phone_number"), ) # customer = Customer.from_form_data(request.form) db.session.add(customer) db.session.commit() return redirect('/') return render_template('new_customer.html', form=form)
def read(self): customers = [] with open(self.customersFile, 'r') as f: reader = csv.reader(f) try: for customerRow in reader: customers.append(Customer( forename=customerRow[0], surname=customerRow[1], email=customerRow[2], country=customerRow[3] )) except csv.Error as e: sys.exit( 'file %s, line %d: %s' % ( self.customersFile, reader.line_num, e)) return customers
def customer_menu(): path = open('customer_no.txt', 'r') customer_no = int(path.read()) path.close() Customer.ID = customer_no + 1 global customer customer = Customer() path = open('customer_no.txt', 'w') path.write(f'{customer.ID}') path.close() print(f"Customer Site No.{customer.ID}") print("Choose Your Action") print("\t 1) View Item") print("\t 2) Your Cart") print("\t 3) Check out") print("\t 0) Main Menu") menu_choice = {1: 'view_item', 2: 'cart', 3: 'checkout', 0: 'main_menu'} return menu_choice
def post(self): if (request.headers.get('Authorization')): content = request.get_json() errors = create_RegisterCustomerControllers_schema.load(content) if errors: name = content.get('name') lastname = content.get('lastname') identificationCard = content.get('identificationCard') line = content.get('phone') dateBorn = content.get('dateBorn') identificationCard_bdvali = session.query(Customer).filter_by( customerIdentification=identificationCard).first() if not identificationCard_bdvali: print("entre al if") manage_bd = Customer( namne=name, lastname=lastname, customerIdentification=identificationCard, line=line, dateBorn=dateBorn) session.add(manage_bd) session.commit() manage_bd = Lines( numberline=line, customerIdentification=identificationCard, state='active') session.add(manage_bd) session.commit() for x in range(5): manage_bd = Bill( value=32000, collectionDay='2020-09-22', customerIdentification=identificationCard, numberLine=line) session.add(manage_bd) session.commit() return jsonify({ "Status": "Register customer successfully, Autorizacion por token valida ", }), 200 return jsonify({"Status": "documento ya registrado"}), 403 return jsonify({"Status": "No ha enviado un token"}), 403
def add_customer_to_db(): """Add customer to DB.""" f_name = request.args.get('fname') l_name = request.args.get('lname') zip_code = request.args.get('zipcode') # To add this customer to db: # 1. Create the customer customer = Customer(fname=f_name, lname=l_name, zipcode=zip_code) # 2. Add this customer to session db.session.add(customer) # 3. Commit the changes db.session.commit() # 4. Display a flash message to confirm adding flash("Customer was addded successfully!!!") return redirect("/")
def create_wishlist(cust_id): # """ create the wishlist with the provided id""" """ Create a Wishlist This endpoint will create a Wishlist based on the customer id specified in the path --- tags: - Wishlists consumes: - application/json produces: - application/json parameters: - name: cust_id in: path description: ID of customer who wants to create his/her wishlist required: true type: integer - in: body name: body required: true schema: type: object required: - name - Product List properties: name: type: string description: name for the Wishlist Product List: type: array items: type: string description: the list of products in a Wishlist responses: 201: description: Wishlist created schema: id: Wishlist properties: Customer ID: type: integer description: ID of customer Wishlist: type: object properties: wishlist name: type: string description: the Wishlists's name Product list: type: array items: type: string description: the list of products in a Wishlist 400: description: Bad Request (the posted data was not valid) """ wishlist = Customer(cust_id, "", []) wishlist.deserialize(request.get_json()) message = wishlist.save() location_url = url_for('create_wishlist', cust_id=wishlist.cust_id) return make_response(jsonify(message), status.HTTP_201_CREATED, {'Location': location_url})
def create_customer(self, name: str) -> Customer: customer = self.customer_table.create_customer(Customer(name)) self.connection.commit() return customer
def c_reg(): # if logged in, redirect to profile if "user_id" in session: customer = Customer.query.filter_by( customer_name=session['user_name']).first() staff = Staff.query.filter_by(staff_name=session['user_name']).first() # is user in session is not the customer if customer is None: flash("Only customers can sign up for a new account") # user in session is staff, redirect them to their profile if staff is not None: return redirect( url_for("profile", username=session["user_name"])) #else person in session is the owner, redirect to owner profile else: return redirect( url_for("profile", username=session["user_name"])) #user in session is the customer, ask them to log out to sign up for a new account else: flash("Must log out to sign up for a new account!") return redirect(url_for("profile", username=session["user_name"])) # is not logged in and method is post elif request.method == "POST": customer = Customer.query.filter_by( customer_name=request.form["user"]).first() staff = Staff.query.filter_by(staff_name=request.form["user"]).first() if not request.form['user']: flash('You have to enter a username') return render_template("cusSignupPage.html") elif not request.form['email'] or \ '@' not in request.form['email']: flash('You have to enter a valid email address') return render_template("cusSignupPage.html") elif not request.form['pass']: flash('You have to enter a password') return render_template("cusSignupPage.html") #if name is already in customer table elif customer is not None: flash("Username already taken!") return render_template("cusSignupPage.html") elif staff is not None: flash("Username already taken!") return render_template("cusSignupPage.html") elif request.form['user'] == owner_user: flash("Username already taken!") return render_template("cusSignupPage.html") #else add customer to the customer table else: db.session.add( Customer(request.form['user'], request.form['email'], generate_password_hash(request.form['pass']))) db.session.commit() flash('You were successfully registered and can login now') #session["username"] = request.form["user"] #flash("Successfully registered! Here is your profile") return redirect(url_for("login_controller")) elif request.method == "GET": return render_template("cusSignupPage.html") # if all else fails, offer to log them in return redirect(url_for("login_controller"))
from model import Customer from utils.common import session_provider session = session_provider() customer = Customer() customer.name = 'thanh' customer.phone = '0968452455' customer.address = ' 10 Hai Phong, Thach Thang, Thanh Khe, Da Nang' session.add(customer) session.commit() session.close()
# This module contains the script that shows an example run of the models from model import BicycleManufacturer, BicycleShop, Customer if __name__ == "__main__": manufacturer1 = BicycleManufacturer("Manufacturer 1", 0.1) manufacturer2 = BicycleManufacturer("Manufacturer 2", 0.2) shop = BicycleShop("Freecycle", 0.2, [manufacturer1, manufacturer2]) shop.get_inventory() customer1 = Customer("Customer 1", 200) customer2 = Customer("Customer 2", 500) customer3 = Customer("Customer 3", 1000) customerList = [customer1, customer2, customer3] print "\n" print "====" * 5 print "Welcome to {0}".format(shop.get_name()) print "====" * 5 print "\nCurrent Inventory:" print "-----" * 5 for bike in shop.get_inventory(): print "{0}".format(bike) for customer in customerList: print "\n{0}".format(customer) temp = [] for bike in shop.get_inventory(): if (bike.get_cost() <= customer.get_funds()):
def setUp(self): self._manufacturer1 = BicycleManufacturer("Manufacturer1", 0.2) self._manufacturer2 = BicycleManufacturer("Manufacturer2", 0.3) self._shop = BicycleShop("Shop", 0.2, [self._manufacturer1, self._manufacturer2]) self._customer = Customer('Customer', 10000)
def example_data(): """Create some sample data.""" #add one user for testing. user = User(first_name='sisi', last_name='wang', email='*****@*****.**', password='******') db.session.add(user) db.session.commit() #dd gender type male = Gender(gender_code='M', gender_name='Male') female = Gender(gender_code='FM', gender_name='Female') db.session.add(male) db.session.add(female) db.session.commit() #Load customer from faker into database email_company = ['@gmail.com', '@hotmail.com'] for i in range(0, 1): first_name = fake.first_name_male() last_name = fake.last_name() #email = first_name + last_name + random.choice(email_company) email = '*****@*****.**' customer = Customer(first_name=first_name, last_name=last_name, gender_code='M', phone_number=str(fake.phone_number()), email=email, birth_date=fake.date(pattern="%Y %m %d"), address=fake.street_address(), city=fake.city(), state='CA', zipcode=int(fake.zipcode()), user_id=1) db.session.add(customer) for i in range(0, 10): first_name = fake.first_name_male() last_name = fake.last_name() email = first_name + last_name + random.choice(email_company) customer = Customer(first_name=first_name, last_name=last_name, gender_code='FM', phone_number=str(fake.phone_number()), email=email, birth_date=fake.date(pattern="%Y %m %d"), address=fake.street_address(), city=fake.city(), state='CA', zipcode=int(fake.zipcode()), user_id=1) db.session.add(customer) db.session.commit() #Load categories infomation. clothing = Category(cg_name='clothing') shoes = Category(cg_name='shoes') db.session.add(clothing) db.session.add(shoes) db.session.commit() #Add products product1 = Product(user_id=1, prd_name='nikeshoes', cg_id=2, sale_price=180.99, description='test') product2 = Product(user_id=1, prd_name='gapclothing', cg_id=1, sale_price=180.99, description='test') db.session.add(product1) db.session.add(product2) cg_attr1 = CategoryAttribute(attr_name="brand") cg_attr2 = CategoryAttribute(attr_name="size") db.session.add(cg_attr1) db.session.add(cg_attr2) db.session.commit() cg_dval1 = CategoryDetailValue(cg_attr_id=1, attr_val="nike") cg_dval2 = CategoryDetailValue(cg_attr_id=2, attr_val="6") cg_dval3 = CategoryDetailValue(cg_attr_id=1, attr_val="gap") cg_dval4 = CategoryDetailValue(cg_attr_id=2, attr_val="4") db.session.add(cg_dval1) db.session.add(cg_dval2) db.session.add(cg_dval3) db.session.add(cg_dval4) db.session.commit() cg_d1 = CategoryDetail(cg_id=1, cg_attr_id=1) cg_d2 = CategoryDetail(cg_id=1, cg_attr_id=2) cg_d3 = CategoryDetail(cg_id=2, cg_attr_id=1) cg_d4 = CategoryDetail(cg_id=2, cg_attr_id=2) db.session.add(cg_d1) db.session.add(cg_d2) db.session.add(cg_d3) db.session.add(cg_d4) prd_d1 = ProductDetail(prd_id=1, cg_detailvalue_id=1) prd_d2 = ProductDetail(prd_id=1, cg_detailvalue_id=2) prd_d3 = ProductDetail(prd_id=2, cg_detailvalue_id=3) prd_d4 = ProductDetail(prd_id=2, cg_detailvalue_id=4) db.session.add(prd_d1) db.session.add(prd_d2) db.session.add(prd_d3) db.session.add(prd_d4) db.session.commit() #Load product sale infomation for i in range(0, 20): sale = Sale(cust_id=random.randint(1, 11), prd_id=1, returned_flag=False, transc_at=fake.date_time_between(start_date="-1y", end_date="now", tzinfo=None), transc_price=random.randint(65, 80), quantities=random.randint(1, 5)) db.session.add(sale) for i in range(0, 20): sale = Sale(cust_id=random.randint(1, 11), prd_id=2, returned_flag=False, transc_at=fake.date_time_between(start_date="-1y", end_date="now", tzinfo=None), transc_price=random.randint(160, 180), quantities=random.randint(1, 5)) db.session.add(sale) db.session.commit() # Load purchases infomation for i in range(0, 10): purchase_price = random.randint(40, 50) * 0.99 purchase = Purchase(prd_id=1, purchase_at=fake.date_time_between( start_date="-1y", end_date="now", tzinfo=None), purchase_price=purchase_price, quantities=random.randint(20, 88)) db.session.add(purchase) for i in range(0, 10): purchase_price = random.randint(100, 110) * 0.99 purchase = Purchase(prd_id=2, purchase_at=fake.date_time_between( start_date="-1y", end_date="now", tzinfo=None), purchase_price=purchase_price, quantities=random.randint(20, 40)) db.session.add(purchase) db.session.commit()