def delete_documents(): print('\n\033[01m## Deletion ##\033[0m') make_test(lambda: MemberController.delete_member(3))( MemberTest, 'existing document', False) make_test(lambda: MemberController.delete_member(3))( MemberTest, 'non existing document', True)
def deleteView(context, args, mid): if args == "Booking": BookingController.remove(mid) elif args == "Fees": FeesController.remove(mid) elif args == "Field": FieldController.remove(mid) elif args == "Member": MemberController.remove(mid) elif args == "Schedule": ScheduleController.remove(mid) elif args == "Session": SessionController.remove(mid) context.destroy() masterView(args)
def create_members(): print('\033[01m## Creation ##\033[0m') make_test(lambda: MemberController.create_member({ "password": "******", "firstName": "John", "lastName": "Connor", "email": "*****@*****.**", "birthday": "1967-01-20", "gradeYear": 3, "telephone": 116316425, "positions": [{ 'id': 1, 'year': 2014 }, { 'id': 3, 'year': 2018 }] }))(MemberTest, 'all needed attributes', False) make_test(lambda: MemberController.create_member({ "password": "******", "firstName": "Louis", "lastName": "Rodolphe", "email": "*****@*****.**", "birthday": "1967-01-20", "gradeYear": 3, "telephone": 116316425, "positions": [{ 'id': 2, 'year': 2015 }, { 'id': 3, 'year': 2017 }] }))(MemberTest, 'all needed attributes', False) make_test(lambda: MemberController.create_member({ "password": "******", "firstName": "Lucie", "lastName": "Connor", "email": "*****@*****.**", "birthday": "1967-01-20", "gradeYear": 3, "telephone": 116316425 }))(MemberTest, 'all needed attributes', False) '''make_test(lambda: MemberController.create_document({
def updateValidation(value): if value is None: toast("Field empty") else: if args == "Booking": BookingController.update(mid, value) elif args == "Fees": FeesController.update(mid, value) elif args == "Field": FieldController.update(mid, value) elif args == "Member": MemberController.update(mid, value) elif args == "Schedule": ScheduleController.update(mid, value) elif args == "Session": SessionController.update(mid, value)
def read_documents(): print('\n\033[01m## Reading ##\033[0m') make_test(lambda: MemberController.get_members({}))( MemberTest, 'all documents', False) make_test(lambda: MemberController.get_members({ 'firstName': 'John' }))( MemberTest, 'specific documents', False) make_test(lambda: MemberController.get_member_by_id(2))( MemberTest, 'document with existing id', False) make_test(lambda: MemberController.get_member_by_id(-1))( MemberTest, 'document with non existing id', True)
def masterView(args): global selectedItem if isLogin: view = Toplevel() view.title('System') list_box = Listbox(view, width=65) list_box.grid(row=1, columnspan=2) if args == "Booking": for data in BookingController.get()['booking']: list_box.insert( int(data['id']), data['id'] + '.field_id: ' + data['field_id'] + '.schedule_id: ' + data['schedule_id'] + '.session_id: ' + data['session_id'] + '.user_id: ' + data['user_id'] + '.booking_time: ' + data['booking_time']) elif args == "Fees": for data in FeesController.get()['fees']: list_box.insert(int(data['id']), data['id'] + '.rate: ' + data['rate']) elif args == "Field": for data in FieldController.get()['field']: list_box.insert(int(data['id']), data['id'] + '.name: ' + data['name']) elif args == "Member": for data in MemberController.get()['member']: list_box.insert(int(data['id']), data['id'] + '.name: ' + data['name']) elif args == "Schedule": for data in ScheduleController.get()['schedule']: list_box.insert(int(data['id']), data['id'] + '.date: ' + data['date']) elif args == "Session": for data in SessionController.get()['session']: list_box.insert(int(data['id']), data['id'] + '.time: ' + data['time']) list_box.bind('<<ListboxSelect>>', onSelectItem) Button(view, text='Create', width=25, command=lambda: createView(view, args)) \ .grid(row=2, columnspan=2) Button(view, text='Update', width=25, command=lambda: updateView(view, args, selectedItem)) \ .grid(row=4, columnspan=2) Button(view, text='Delete', width=25, command=lambda: deleteView(view, args, selectedItem)) \ .grid(row=5, columnspan=2) else: toast("Please Login first")
def updateView(context, args, mid): view = Toplevel() view.title('Edit') Label(view, text='Edit Existing Data').grid(row=0, columnspan=2) if args == "Booking": Label(view, text='field_id').grid(row=1) p1 = Entry(view) p1.insert(0, BookingController.read(mid)['field_id']) p1.grid(row=1, column=1) Label(view, text='schedule_id').grid(row=2) p2 = Entry(view) p2.insert(0, BookingController.read(mid)['schedule_id']) p2.grid(row=2, column=1) Label(view, text='session_id').grid(row=3) p3 = Entry(view) p3.insert(0, BookingController.read(mid)['session_id']) p3.grid(row=3, column=1) Label(view, text='user_id').grid(row=4) p4 = Entry(view) p4.insert(0, BookingController.read(mid)['user_id']) p4.grid(row=4, column=1) Button(view, text='Update', width=25, command=lambda: updateValidation( p1.get() + ' ' + p2.get() + ' ' + p3.get() + ' ' + p4.get() + ' ' + Time.TimeHelper.returnTimeNow())) \ .grid(row=5, columnspan=2) Button(view, text='Done', width=25, command=lambda: done()).grid(row=6, columnspan=2) elif args == "Fees": Label(view, text='Rate').grid(row=1) p = Entry(view) p.insert(0, FeesController.read(mid)['rate']) p.grid(row=1, column=1) Button(view, text='Update', width=25, command=lambda: updateValidation(p.get())) \ .grid(row=2, columnspan=2) Button(view, text='Done', width=25, command=lambda: done()).grid(row=3, columnspan=2) elif args == "Field": Label(view, text='Field').grid(row=1) p = Entry(view) p.insert(0, FieldController.read(mid)['name']) p.grid(row=1, column=1) Button(view, text='Update', width=25, command=lambda: updateValidation(p.get())) \ .grid(row=2, columnspan=2) Button(view, text='Done', width=25, command=lambda: done()).grid(row=3, columnspan=2) elif args == "Member": Label(view, text='Name').grid(row=1) p = Entry(view) p.insert(0, MemberController.read(mid)['name']) p.grid(row=1, column=1) Button(view, text='Update', width=25, command=lambda: updateValidation(p.get())) \ .grid(row=2, columnspan=2) Button(view, text='Done', width=25, command=lambda: done()).grid(row=3, columnspan=2) elif args == "Schedule": Label(view, text='Date').grid(row=1) p = Entry(view) p.insert(0, ScheduleController.read(mid)['date']) p.grid(row=1, column=1) Button(view, text='Update', width=25, command=lambda: updateValidation(p.get())) \ .grid(row=2, columnspan=2) Button(view, text='Done', width=25, command=lambda: done()).grid(row=3, columnspan=2) elif args == "Session": Label(view, text='Time').grid(row=1) p = Entry(view) p.insert(0, SessionController.read(mid)['time']) p.grid(row=1, column=1) Button(view, text='Update', width=25, command=lambda: updateValidation(p.get())) \ .grid(row=2, columnspan=2) Button(view, text='Done', width=25, command=lambda: done()).grid(row=3, columnspan=2) def updateValidation(value): if value is None: toast("Field empty") else: if args == "Booking": BookingController.update(mid, value) elif args == "Fees": FeesController.update(mid, value) elif args == "Field": FieldController.update(mid, value) elif args == "Member": MemberController.update(mid, value) elif args == "Schedule": ScheduleController.update(mid, value) elif args == "Session": SessionController.update(mid, value) def done(): view.destroy() context.destroy() masterView(args)
def paymentView(): global selectedMemberItem global selectedItem loadedBooking = [] if isLogin: view = Toplevel() view.title('System') member_list_box = Listbox(view, width=80) member_list_box.grid(row=1, columnspan=2) for data in MemberController.get()['member']: member_list_box.insert(int(data['id']), data['id'] + '.name: ' + data['name']) member_list_box.bind('<<ListboxSelect>>', onSelectMemberItem) Button(view, text='Checkout', width=25, command=lambda: loadData()) \ .grid(row=2) list_box = Listbox(view, width=80) list_box.grid(row=3, columnspan=2) list_box.bind('<<ListboxSelect>>', onSelectItem) Button(view, text='Payment', width=25, command=lambda: payment_confirmation()) \ .grid(row=4) else: toast("Please Login first") def loadData(): if selectedMemberItem == 0: toast('Please select member first') else: list_box.delete(0, END) loadedBooking.clear() for booking in BookingController.get()['booking']: if booking['status'] != 'done' and booking[ 'user_id'] == selectedMemberItem: loadedBooking.append(booking) list_box.insert( int(booking['id']), booking['id'] + '.field: ' + str(FieldController.read(booking['field_id'])['name']) + '.schedule: ' + str( ScheduleController.read( booking['schedule_id'])['date']) + '.session: ' + str( SessionController.read( booking['session_id'])['time']) + '.user_id: ' + booking['user_id'] + '.booking_time: ' + booking['booking_time']) def payment_confirmation(): rate = FeesController.read('1')['rate'] payment_view = Toplevel() payment_view.title('Payment') detail = 'Payment for:\n' for item in loadedBooking: detail += 'Booking id: ' + str(item['id']) +\ ' Field: ' + str(FieldController.read(item['field_id'])['name']) +\ ' Schedule: ' + str(ScheduleController.read(item['schedule_id'])['date']) +\ ' Session: ' + str(SessionController.read(item['session_id'])['time']) + '\n' Label(payment_view, text=detail).pack() Label(payment_view, text='Total price : ' + str(int(rate) * len(loadedBooking))).pack() Button(payment_view, text='Pay', command=lambda: payment(payment_view)).pack() def payment(context): for pay in loadedBooking: BookingController\ .update(pay['id'], pay['field_id'] + ' ' + pay['schedule_id'] + ' ' + pay['session_id'] + ' ' + pay['user_id'] + ' ' + pay['booking_time'] + ' ' + 'done') context.destroy() loadData()
def bookingView(): global selectedScheduleItem global selectedFieldItem global selectedSessionItem global selectedMemberItem if isLogin: view = Toplevel() view.title('System') schedule_list_box = Listbox(view) schedule_list_box.grid(row=1, column=1) for data in ScheduleController.get()['schedule']: schedule_list_box.insert(int(data['id']), data['id'] + '.date: ' + data['date']) schedule_list_box.bind('<<ListboxSelect>>', onSelectScheduleItem) field_list_box = Listbox(view) field_list_box.grid(row=1, column=2) for data in FieldController.get()['field']: field_list_box.insert(int(data['id']), data['id'] + '.name: ' + data['name']) field_list_box.bind('<<ListboxSelect>>', onSelectFieldItem) session_list_box = Listbox(view) session_list_box.grid(row=2, column=1) session_list_box.bind('<<ListboxSelect>>', onSelectSessionItem) Button(view, text='Check Session', command=lambda: checkAvailableSession()) \ .grid(row=3, column=1) Button(view, text='Book Session', command=lambda: bookSession()) \ .grid(row=3, column=2) member_list_box = Listbox(view) member_list_box.grid(row=2, column=2) for data in MemberController.get()['member']: member_list_box.insert(int(data['id']), data['id'] + '.name: ' + data['name']) member_list_box.bind('<<ListboxSelect>>', onSelectMemberItem) else: toast("Please Login first") def checkAvailableSession(): if selectedScheduleItem == 0 and selectedFieldItem == 0: toast('Please select item first') else: taken_session = [] session_list_box.delete(0, END) for b in BookingController.get()['booking']: if b['schedule_id'] == selectedScheduleItem and b[ 'field_id'] == selectedFieldItem: taken_session.append(b['session_id']) for session in SessionController.get()['session']: if session['id'] not in taken_session: session_list_box.insert( int(session['id']), session['id'] + '.time: ' + session['time']) def bookSession(): if selectedSessionItem == 0: toast('Please make sure you have selected session item') elif selectedMemberItem == 0: toast('Please make sure you have selected member item') else: booking = str(selectedFieldItem) \ + ' ' + str(selectedScheduleItem) \ + ' ' + str(selectedSessionItem) \ + ' ' + str(selectedMemberItem) \ + ' ' + str(Time.TimeHelper.returnTimeNow()) \ + ' ' + 'book' BookingController.create(booking) toast('Session booked') checkAvailableSession() clearSelection() def clearSelection(): global selectedSessionItem selectedSessionItem = 0 global selectedMemberItem selectedMemberItem = 0
def create_member(): return send_response( lambda: MemberController.create_member(request.get_json()), is_admin, request.headers.get('Authorization'))()
def get_position(): return send_response(lambda: MemberController.get_positions(), is_connected, request.headers.get('Authorization'))()
def delete_member(member_id): return send_response(lambda: MemberController.delete_member(member_id), is_admin, request.headers.get('Authorization'))()
def update_temp_pass(): return send_response( lambda: MemberController.update_temp_pass(request.get_json()))()
def update_member(member_id): return send_response( lambda: MemberController.update_member(member_id, request.get_json()), is_own_resource, request.headers.get('Authorization'), member_id)()
def get_member(member_id): return send_response(lambda: MemberController.get_member_by_id(member_id), is_connected, request.headers.get('Authorization'))()
def update_connected_member(): return send_response( lambda: MemberController.update_member( get_my_id(request.headers.get('Authorization')), request.get_json( )), )()
def import_data(file): if not re.match(r'\w*\.(xlsx|xlsm)', file.filename): raise FormatError excel_file = pd.ExcelFile(file) position = pd.read_excel(excel_file, sheet_name='Positions') position['id'] = position.index + 1 position = position.rename(columns={'position': 'label'}) member = pd.read_excel(excel_file, sheet_name='Members') member = member.rename( columns={ 'prénom': 'firstName', 'nom': 'lastName', 'genre': 'gender', 'anniversaire': 'birthday', 'année diplôme': 'gradeYear' }) member.index += 2 # id 1 is for the admin member['id'] = member.index max_position_nb = len(member.filter(like='position').columns.values) m_positions_df = [ member.filter(['id', f'position{i}', f'year{i}']).rename(columns={ 'id': 'member_id', f'position{i}': 'position', f'year{i}': 'year' }) for i in range(1, max_position_nb + 1) ] member = member.drop(list(member.filter(regex='year\d|position\d')), axis=1) member['username'] = member['email'].apply(lambda x: x.split('@')[0]) m_position = pd.concat(m_positions_df, ignore_index=True) used_positions = m_position.dropna()['position'].values for i in used_positions: if i not in position['label'].values: raise FormatError m_position = m_position.merge(position, left_on='position', right_on='label') m_position = m_position.filter(['member_id', 'id', 'year']) Controller.recreate_tables() position.to_sql(name='position', con=engine, if_exists='append', index=False) error_members = [] for mb in member.to_dict('records'): # remove null value mb = {k: v for k, v in mb.items() if not pd.isna(v)} # filter the member's positions m_pos = m_position.loc[m_position['member_id'] == mb['id']] mb['positions'] = \ m_pos.filter(['id', 'year']).to_dict('records') try: MemberController.create_member(mb) except: error_members.append(mb) stats = { 'totalMembers': len(member), 'errorMembers': len(error_members) } return stats
def login_member(): return send_response(lambda: MemberController.login(request.get_json()))()