def hobby_search(self, uid): hobby = self.hobbyModel.find_ver2(uid) time = hobby['time_range_id'] court = hobby['court_id'] booking = self.bookingModel.find(time, court) print(str(booking)) if booking['amount'] != 0: return view.TextView("{time} 的 {court} 已經被借走了".format( time=hobby['day_of_week'] + hobby['zone'], court=hobby['name'])) return view.TextView("{time} 的 {court} 可以被租借".format( time=hobby['day_of_week'] + hobby['zone'], court=hobby['name']))
def store(self, uid, student_id): answer = self.accountModel.store(student_id, uid) answer = self.accountModel.find(uid) outputStr = "you register new account : \nLine_id: {line_id}\nstudent_id: {student_id}".format( line_id=answer['line_id'], student_id=answer['student_id']) return view.TextView(outputStr)
def get_booking(self, uid): bookings = self.bookingModel.find_by_uid(uid) answer = "\n你預約的時間有:\n" for booking in bookings: answer += "id= {id}, {time} 的 {court}\n".format( id=str(booking['id']), time=str(booking['day_of_week'] + str(booking['zone'])), court=str(booking['name'])) return view.TextView(answer)
def index(self): courts = self.courtModel.get_courts() answer = "\n目前開放的球場:" for court in courts: answer += "\n\n{name} 位置在 {loc} 數量有 {amount}\n{desc}".format( name=court['name'], loc=court['location'], amount=court['amount'], desc=court['description']) return view.TextView(answer)
def hobby_booking(self, uid): hobby = self.hobbyModel.find_ver2(uid) time = hobby['time_range_id'] court = hobby['court_id'] booking = self.bookingModel.find(time, court) if booking['amount'] == 0: text = "確認預約 {time} 的 {court} ?".format(time=hobby['day_of_week'] + hobby['zone'], court=hobby['name']) return view.BookingConfirmView(text, time, court) return view.TextView("{time} 的 {court} 已經被借走了".format( time=hobby['day_of_week'] + hobby['zone'], court=hobby['name']))
def delete(self, uid, id): self.bookingModel.delete(uid, id) return view.TextView("刪除完成")
def store(self, uid, time, court): self.bookingModel.store(uid, time, court) return view.TextView("預約完成")
def find(self, time, court): answer = self.bookingModel.find(time, court) if answer['amount'] != 0: return view.TextView("這時間的球場有人預約囉") return view.BookingConfirmView("此時段為空 請問要預約嗎?", time, court)
def parser_text(inputText, uid): inputText = str(inputText).lower() inputTextToken = inputText.split('/') # check first token first = inputTextToken.pop(0) if first == 'account': account = controller.AccountController() if not inputTextToken: return view.AccountHelpView() else: second = inputTextToken.pop(0) # account/register/60747021s if second == 'register': if not inputTextToken: return view.TextView( "Example :\naccount/register/[your student id there]") third = inputTextToken.pop(0) answer = account.store(uid, third) return view.TextView("帳號綁定完成\n請輸入 help 回到小幫手清單") # account/hobby/time/1/court/1 elif second == 'hobby': if not inputTextToken: return view.TextView(account.get_hobby(uid)) third = inputTextToken.pop(0) if third == 'time': if not inputTextToken: return view.AccountHobbyTimeHelpView(last_input=inputText) time = inputTextToken.pop(0) if not inputTextToken: return view.AccountHobbyCourtHelpView(last_input=inputText) four = inputTextToken.pop(0) if four == 'court': if not inputTextToken: return view.AccountHelpView() court = inputTextToken.pop(0) return view.TextView(account.set_hobby(uid, time, court)) elif third == 'search': return account.hobby_search(uid) elif third == 'booking': return account.hobby_booking(uid) elif second == 'booking': if not inputTextToken: return view.AccountBookingHelpView() third = inputTextToken.pop(0) if third == 'list': return account.get_booking(uid) elif third == 'delete': if not inputTextToken: return view.TextView( "Example :\naccount/booking/delete/[your want delete id there]" ) booking = controller.BookingController() booking_id = inputTextToken.pop(0) return booking.delete(uid, booking_id) elif first == 'search': search = controller.SearchController() if not inputTextToken: return view.SearchTimeHelpView() second = inputTextToken.pop(0) if second == 'time': if not inputTextToken: return view.SearchTimeHelpView() time = inputTextToken.pop(0) if not inputTextToken: return view.SearchCourtHelpView(last_input='search/time/' + str(time)) third = inputTextToken.pop(0) if third == 'court': if not inputTextToken: return view.SearchCourtHelpView(last_input='search/time/' + str(time)) court = inputTextToken.pop(0) return search.find(time, court) else: return view.SearchTimeHelpView() elif first == 'booking': booking = controller.BookingController() if not inputTextToken: return view.TimeHelpView(title='預約時間', text='請選擇預約時間', last_input='booking') second = inputTextToken.pop(0) if second == 'time': if not inputTextToken: return view.TimeHelpView(title='預約時間', text='請選擇預約時間', last_input='booking') time = inputTextToken.pop(0) if not inputTextToken: return view.CourtHelpView(title='預約地點', text='請選擇預約地點', last_input='booking/time/' + str(time)) third = inputTextToken.pop(0) if third == 'court': if not inputTextToken: return view.CourtHelpView(title='預約地點', text='請選擇預約地點', last_input='booking/time/' + str(time)) court = inputTextToken.pop(0) return booking.store(uid, time, court) else: return view.TimeHelpView(title='預約時間', text='請選擇預約時間', last_input='booking') elif first == 'maintain': if not inputTextToken: return view.MaintainHelpView() maintain = controller.MaintainController() second = inputTextToken.pop(0) if (second == 'all'): return view.TextView(maintain.get_maintains()) elif (second == 'post'): if not inputTextToken: return view.MaintainPostHelpView() court = inputTextToken.pop(0) maintain.post_maintain(court, uid) return view.TextView('報修新增完成') elif first == 'bulletin': bulletin = controller.BulletinController() return view.TextView(bulletin.get_bulletins()) elif first == 'help': return view.HelperView("小幫手", '指令') elif first == 'court': court = controller.CourtController() return court.index() else: return view.HelperView("小幫手", '指令')