def initialize(): DATABASE.create_tables([User, Saloon, Appointment], safe=True) try: User.create(first_name="Felicia", last_name="Mueni", email="*****@*****.**") except IntegrityError: pass try: Saloon.create(name="Mrembo", business_number="9897", opening_time="10:00 am", closing_time="5:00 pm", description="Urembo services", services="Manicure, Pedicure, Haircare", user_id=1, location="George Padimore Lane") except IntegrityError: pass try: no_appointments = Appointment.select().count() if no_appointments < 1: Appointment.create(user_id=1, saloon_id=1, services="Manicure, Pedicure", time_appointment=datetime.datetime.now()) except IntegrityError: pass
def add_saloon(): saloon_data = dict(request.form.items()) Saloon.create(name=saloon_data.get('name', 'Anonymous'), business_number=saloon_data.get('business_number'), opening_time=saloon_data.get('opening_time'), closing_time=saloon_data.get('closing_time'), description=saloon_data.get('description'), services=saloon_data.get('services'), user_id=1) result = {'status': 'success'} return jsonify(result)
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 list_saloons(): saloons = Saloon.select() results = [] for saloon in saloons: results.append({ 'name': saloon.name, 'business_number': saloon.business_number }) return jsonify(results)
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 search(location): saloons = Saloon.select().where(Saloon.location.contains(location)) results = [] for saloon in saloons: results.append({ 'name': saloon.name, 'business_number': saloon.business_number, 'opening_time': saloon.opening_time, 'closing_time': saloon.closing_time, 'description': saloon.description, 'services': saloon.services, 'user_id': saloon.user_id, 'location': saloon.location }) return jsonify(results)
def list_saloons(): saloons = Saloon.select() results = [] for saloon in saloons: results.append({ 'name': saloon.name, 'business_number': saloon.business_number, 'opening_time': saloon.opening_time, 'closing_time': saloon.closing_time, 'description': saloon.description, 'services': saloon.services, 'user_id': saloon.user_id, 'location': saloon.location, }) return jsonify(results)