def yogaclasses(member): sql = """ SELECT yogaclasses.* FROM yogaclasses INNER JOIN bookings ON yogaclasses.id = bookings.yogaclass_id WHERE member_id = %s """ values = [member.id] results = run_sql(sql, values) yogaclasses = [] for row in results: instructor = instructor_repository.select(row['instructor_id']) yogaclass = YogaClass(row['name'], row['duration'], row['description'], instructor, row['date'], row['time'], row['capacity'], row['active'], row['id']) yogaclasses.append(yogaclass) return yogaclasses
def update_yogaclass(id): name = request.form["name"] duration = request.form["duration"] description = request.form["description"] instructor_id = request.form["instructor"] date = request.form["date"] time = request.form["time"] capacity = request.form["capacity"] active = request.form["active"] instructor = instructor_repository.select(instructor_id) yogaclass = YogaClass(name, duration, description, instructor, date, time, capacity, active, id) yogaclass_repository.update(yogaclass) return redirect(f'/yogaclasses/{id}')
def create_yogaclass(): name = request.form["name"] duration = request.form["duration"] description = request.form["description"] instructor_id = request.form["instructor"] date = request.form["date"] time = request.form["time"] capacity = request.form["capacity"] instructor = instructor_repository.select(instructor_id) yogaclass = YogaClass(name, duration, description, instructor, date, time, capacity) yogaclass_repository.save(yogaclass) return redirect('/yogaclasses')
def select(id): yogaclass = None sql = "SELECT * FROM yogaclasses WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: instructor = instructor_repository.select(result['instructor_id']) yogaclass = YogaClass(result['name'], result['duration'], result['description'], instructor, result['date'], result['time'], result['capacity'], result['active'], result['id']) return yogaclass
def select_all(): yogaclasses = [] sql = "SELECT * FROM yogaclasses" results = run_sql(sql) for row in results: instructor = instructor_repository.select(row['instructor_id']) yogaclass = YogaClass(row['name'], row['duration'], row['description'], instructor, row['date'], row['time'], row['capacity'], row['active'], row['id']) yogaclasses.append(yogaclass) return yogaclasses
class TestYogaClass(unittest.TestCase): def setUp(self): self.instructor1 = Instructor("Schmidt", "07912 123456") self.yogaclass = YogaClass( "Aerial Yoga", 45, "Yoga whle being supported by a hammock to help with deeper stretches and greater flexibility.", self.instructor1, "2021-03-23", "18:00", 5) def test_can_count_members(self): members = [1, 2, 3, 4, 5] self.yogaclass.count_members(members) self.assertEqual(5, len(self.yogaclass.members)) def test_can_check_if_capacity__no_capacity(self): members = [1, 2, 3, 4, 5] self.yogaclass.check_if_capacity(members) self.assertEqual(False, self.yogaclass.available) def test_can_check_if_capacity__capacity(self): members = [1, 2, 3, 4] self.yogaclass.check_if_capacity(members) self.assertEqual(True, self.yogaclass.available)
member1 = Member( "https://a1cf74336522e87f135f-2f21ace9a6cf0052456644b80fa06d4f.ssl.cf2.rackcdn.com/images/characters_opt/p-New-Girl-Zooey-Deschanel.jpg", "Jessica Day", "1982-02-13", 6540003, memb_type1, "The Loft, LA", "07911 123444") member_repository.save(member1) member2 = Member( "https://mediaproxy.salon.com/width/1200/https://media.salon.com/2012/10/jake_johnson_square.jpg", "Nick Miller", "1990-09-29", 7800643, memb_type1, "The Loft, LA", "07912 123456") member_repository.save(member2) instructor1 = Instructor( "https://media.gq.com/photos/57f2d9a9c63464861a63ddf9/4:3/w_1459,h_1094,c_limit/max-greenfield.jpg", "Schmidt", "07912 123456") instructor_repository.save(instructor1) yogaclass1 = YogaClass( "Aerial Yoga", 45, "Yoga whle being supported by a hammock to help with deeper stretches and greater flexibility.", instructor1, "2021-03-23", "18:00", 10) yogaclass_repository.save(yogaclass1) yogaclass2 = YogaClass( "Power Yoga", 45, "Fast paced class focussing more on core and upper body work to increase stamina, flexibility and strength.", instructor1, "2021-03-23", "13:00", 10) yogaclass_repository.save(yogaclass2) pdb.set_trace()
def setUp(self): self.instructor1 = Instructor("Schmidt", "07912 123456") self.yogaclass = YogaClass( "Aerial Yoga", 45, "Yoga whle being supported by a hammock to help with deeper stretches and greater flexibility.", self.instructor1, "2021-03-23", "18:00", 5)