def createService(): serviceId = unicode(uuid.uuid4()) # image = base64.b64decode(request.json['imageEncoded']) # imageUrl = os.path.join("Images", serviceId + "+" + request.json['serviceOwner'] + ".png") # f = open(imageUrl, 'wb') # f.write(image) strServiceType = "" if int(request.json['serviceType']) & 1: strServiceType += "s" if int(request.json['serviceType']) & 2: strServiceType += "t" if int(request.json['serviceType']) & 4: strServiceType += "c" if int(request.json['serviceType']) & 8: strServiceType += "i" priceService = request.json['priceService'] if priceService == "": priceService = -1 priceTire = request.json['priceTire'] if priceTire == "": priceTire = -1 priceChassis = request.json['priceChassis'] if priceChassis == "": priceChassis = -1 priceItp = request.json['priceItp'] if priceItp == "": priceItp = -1 try: service = Service(id=serviceId, logoUrl=request.json['imageDownloadLink'], name=request.json['serviceName'], description=request.json['serviceDescription'], latitude=request.json['latitude'], longitude=request.json['longitude'], address=request.json['serviceAddress'], city=request.json['serviceCity'], rating=0, phoneNumber=request.json['servicePhone'], email=request.json['serviceEmail'], owner=request.json['serviceOwner'], serviceType=strServiceType, acceptedBrand=request.json['serviceAcceptedBrand'], priceService=priceService, priceTire=priceTire, priceChassis=priceChassis, priceItp=priceItp) print(service) db.session.add(service) db.session.commit() except Exception as e: print(e) return make_response(jsonify({"status": "Could not create"}), status.HTTP_409_CONFLICT) return make_response( jsonify({ "status": "Created", "user": service.toDict() }), status.HTTP_201_CREATED)
def create(): if request.method == "GET": return render_template("new-service.html") elif request.method == "POST": form = request.form name = form["name"] yob = form["yob"] phone = form["phone"] gender = form["gender"] new_service = Service(name=name, yob=yob, phone=phone, gender=gender) new_service.save() return redirect(url_for("admin"))
def new(): if request.method == "GET": return render_template('new.html') elif request.method == "POST": form = request.form name = form['name'] game = form['game'] price = form['price'] rate = 0 des = form['des'] new = Service(name=name, game=game, price=price, rate=rate, des=des) new.save() flash('Đã đăng ký xong') return render_template('new.html')
def initialize(): DATABASE.create_tables( [User, Saloon, Appointment, Register, Service, Saloonservices], safe=True) try: User.create( user_name="feliciah", service="haircare", password="******", ) except IntegrityError: pass try: Service.create(service="manicure", price=1000) except IntegrityError: pass try: Saloon.create(name="mrembo", business_number="9887", opening_time="10:00am", closing_time="5:00pm", description="urembo services", services="manicure,pedicure,haircare", user_id=1, location='location') except IntegrityError: pass try: Register.create(user_name="feliciah", email="*****@*****.**", phone_number="0712343647", service="manicure", password="******", confirm_password="******") except IntegrityError: pass try: Appointment.create(user_id=1, salon_id=1, services="haircare,manicure,facial", time_appointment=datetime.datetime.now()) except IntegrityError: pass DATABASE.close()
def add_services(): data = request.get_json() result = {} try: Service.create(services=data.get('services'), price=data.get('price')) result = { 'status': 'success', 'message': '{} is added'.format(data.get('services')) } return jsonify(result) except IntegrityError: result = { 'status': 'failed', 'message': '{} is not added'.format(data.get('services')) } return jsonify(result)
def service(services): saloon = Saloon.select().where(Saloon.user_id**saloon).get() services = Saloonservices.select().where(Saloonservices.user_id == saloon) # saloons = Saloon.select().where(Saloon.services.contains(services)) results = [] for service in services: service = Service.select().where(Service == service).get() results.append({'services': service.services, 'price': service.price}) return jsonify(results)
def update(service_id): service_to_update = Service.objects.with_id(service_id) if service_to_update is not None: if request.method == "GET": return render_template("update.html", service_to_update=service_to_update) elif request.method == "POST": form = request.form name = form["name"] yob = form["yob"] phone = form["phone"] gender = form["gender"] updated_service = Service(name=name, yob=yob, phone=phone, gender=gender) updated_service.save() service_to_update.delete() return redirect(url_for("admin")) else: return "Not Found"
def edit_service(service_id): service = Service.objects().with_id(service_id) if service is None: return "Not found" else: if request.method == "GET": return render_template('edit.html', service=service) elif request.method == "POST": form = request.form name = form['name'] game = form['game'] des = form['des'] price = form['price'] service.update(set__name=name, set__game=game, set__des=des, set__price=price) service.reload() return redirect(url_for('admin'))
def info(service_id): service = Service.objects().with_id(service_id) if service is None: return "not found" else: return render_template('info.html', service=service)
def delete(service_id): if service is None: return "Not found" else: Service.objects(id=service_id).delete() return redirect(url_for('admin'))
def admin(): all_services = Service.objects() return render_template('admin.html', services=all_services)
def search(game): filtered_services = Service.objects(game=game) all_services = Service.objects() return render_template('all.html', all_services=filtered_services)
def admin(): all_service = Service.objects() return render_template("admin.html", all_service=all_service)
def search(g): all_service = Service.objects(gender=g, ) return render_template('search.html', all_service=all_service)
fake = Faker() # for i in range(50): # print("Saving customer", i+1, "......") # new_customer = Customer( # name = fake.name(), # gender = randint(0,1), # email = fake.email(), # phone = fake.phone_number(), # job = fake.job(), # company = fake.company(), # status = choice([True, False]) # ) # new_customer.save() for i in range(50): print("Saving service", i + 1, "......") new_service = Service( name=fake.name(), yob=randint(1990, 2000), height=randint(150, 180), gender=randint(0, 1), address=fake.address(), phone=fake.phone_number(), image= "https://www.google.com.vn/imgres?imgurl=https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/20180602_FIFA_Friendly_Match_Austria_vs._Germany_Joshua_Kimmich_850_0717.jpg/1200px-20180602_FIFA_Friendly_Match_Austria_vs._Germany_Joshua_Kimmich_850_0717.jpg&imgrefurl=https://en.wikipedia.org/wiki/Joshua_Kimmich&h=1800&w=1200&tbnid=6pphxx3pNyygmM:&q=joshua+kimmich&tbnh=186&tbnw=124&usg=AFrqEzeKaH10ftUOSRWsz13rZwUHto1tKw&vet=1&docid=E-SsBYhDOvcMVM&itg=1&sa=X&ved=2ahUKEwj26_mv84XdAhWE7GEKHQXXCUcQ_B0wGXoECAYQCQ", description=["ngoan hiền", "dễ thương", "lễ phép với gia đình"], measurements=[90, 60, 90], status=choice([True, False])) new_service.save()
def list_services(): services = Service.select() results = [] for service in services: results.append({'services': service.services, 'price': service.price}) return jsonify(results)