def save_seated(user, mobile, table_num, flag=0): print "save_seated" if flag == 0: record = Record.objects.get(user=user, mobile=mobile, waiting=True, take_away=False, directly_seated=False) record.conversion = True record.waiting = False record.seated = True record.table_num = table_num[1:-1] record.save( update_fields=['conversion', 'waiting', 'seated', 'table_num']) elif flag == 1: #Visitor directly seated guest = Guest.objects.get(mobile=mobile) rest_name = table.objects.get(user=user).rest_name record = Record(user=user, seated=True, rest_name=rest_name, date=time_now(), mobile=mobile, age=guest.age, name=guest.name, directly_seated=True, table_num=table_num[1:-1]) record.save()
def noShow(request): print "===========REACHED noShow====================" if request.user.is_authenticated(): if request.method == 'POST': mobile = request.POST.get('mobile', '') print mobile t = table.objects.get(user=request.user) waiting = t.waiting_list['waiting_list'] if mobile not in waiting: return HttpResponseRedirect( '/front/?error=%s not i waiting list' % mobile) waiting.remove(mobile) t.waiting_list = {'waiting_list': waiting} g = Guest.objects.get(mobile=mobile) g.current = "null" g.status = 0 g.last_visited = { 'restuarant': request.user.username, 'date': utils.time_now() } t.save(update_fields=['waiting_list']) g.save(update_fields=['current', 'status', 'last_visited']) signals.save_noshow(request.user, mobile) return HttpResponseRedirect('/front/') return HttpResponseRedirect('/login?msg=%s' % _MSG_CODES['lap'])
def save_waiting(user, mobile, waitingtime): print "Save_waiting" guest = Guest.objects.get(mobile=mobile) rest_name = table.objects.get(user=user).rest_name record = Record(user=user, rest_name=rest_name, date=time_now(), mobile=mobile, age=guest.age, name=guest.name) record.save() pr = PersonalRecord(guest=guest, restuarant=rest_name, date=time_now()) pr.save() message = "Hello, Welcome to %s, your estimated waiting time is %s mins. You will be informed when your table is ready." % ( rest_name, str(waitingtime)) send_sms(mobile, message)
def takeAway(request): print "============Reached takeAway==============" mobile = request.POST.get('mobile', '') name = request.POST.get('name', '') date = utils.time_now() if utils.guest_exists(mobile): g = Guest.objects.get(mobile=mobile) g.last_visited = {'restuarant': request.user.username, 'date': date} print "Saving direct user with: table_no: " g.save(update_fields=['last_visited']) else: print "Creating and Saving takeAway user", g = Guest(mobile=mobile, created_at=date, status=0, name=name, last_visited={ 'restuarant': request.user.username, 'date': date }) g.save() # utils.send_link_to_register(mobile,name) signals.save_takeaway(request.user, mobile, date) print "============ENDING takeAway==============" return HttpResponseRedirect('/front/')
def seatDirectly(request): print "============Reached seatDirectly==============" mydict = request.POST mobile = request.POST.get('mobile', '') name = request.POST.get('name', '') waitingtime = request.POST.get('waitingtime', '') partysize = request.POST.get('partysize', '') tables = [] for key, value in mydict.iteritems(): if key.startswith('table'): tables.append(int(value)) print 'tables selected by user: '******'/front/?error=Please select a table') waiting_list = utils.get_waiting_guests(request.user) seated_list = utils.get_seated_guests(request.user) if (not mobile in waiting_list) and ( not mobile in seated_list ): #Check if he's not already in waiting list or seated if utils.guest_exists(mobile): g = Guest.objects.get(mobile=mobile) g.status = 2 #Seated g.current = request.user.username g.table_no = str(tables)[1:-1] print "Saving direct user with: table_no: " g.save(update_fields=['status', 'current', 'table_no']) signals.save_seated(request.user, mobile, tables, 1) else: print "Creating and Saving direct user with: table_no: ", g = Guest(mobile=mobile, created_at=utils.time_now(), status=2, current=request.user.username, name=name, table_no=str(tables)[1:-1]) g.save() signals.save_seated(request.user, mobile, tables, 1) # utils.send_link_to_register(mobile,name) else: return HttpResponseRedirect('/front/?error=%s' % 'User already in waiting list or seated') #Update table info t = table.objects.get(user=request.user) free = t.status['free'] booked = t.status['booked'] for tab in tables: booked.append(tab) free.remove(tab) booked.sort() free.sort() seated = t.seated['seated'] seated.append(mobile) t.seated = {'seated': seated} t.status = {"booked": booked, "free": free} t.save(update_fields=['status', 'seated']) print "===============FINISHED seatDirectly=================" return HttpResponseRedirect('/front/')
def add(request): errors = [] if request.user.is_authenticated(): if request.method == 'POST': mobile = request.POST.get('mobile', '') errors = [] print mobile, "-------------------------------" waiting_list = utils.get_waiting_guests(request.user) if not mobile in waiting_list: #Check if he's not already in waiting list if utils.guest_exists(mobile): g = Guest.objects.get(mobile=mobile) g.waiting_time = 5 g.start_time = utils.time_now() g.status = 1 #Waiting list g.current = request.user.username g.save(update_fields=[ 'waiting_time', 'start_time', 'status', 'current' ]) else: g = Guest(mobile=mobile, created_at=utils.time_now(), start_time=utils.time_now(), status=1, current=request.user.username, waiting_time=5) g.save() # utils.send_link_to_register(mobile) ##Add user to the waiting list u = User.objects.get(username=request.user.username) utils.update_waiting_list(u, g) signals.save_waiting(request.user, mobile) else: errors.append("%d already in waiting list" % mobile) print errors, "========ERROR================" form = AddGuestForm() waiting = utils.get_waiting_detail(request.user) return render(request, 'clients/add.html', { 'form': form, 'waiting': waiting, 'errors': errors }) else: return HttpResponseRedirect('/login?msg=%s' % _MSG_CODES['lap'])
def checkout(request): if request.user.is_authenticated(): if request.method == 'POST': print "============CHECKOUT STARTED===============" print "Restuarant: ", request.user t_n = int(request.POST.get('checkout_table')) t = table.objects.get(user=request.user) free = t.status['free'] booked = t.status['booked'] seated = t.seated['seated'] print "Currently booked tables: ", booked print "Checkout requested: ", t_n for guest in seated: g = Guest.objects.get(mobile=guest) print "------Seated guests--------" print 'table_no: ', g.table_no if str(t_n) in g.table_no: print "MATCHED" print g.table_no seated.remove(guest) tabs_seated = g.table_no.split(',') print tabs_seated for i in tabs_seated: print i booked.remove(int(i)) free.append(int(i)) free.sort() booked.sort() print "============ booked after remove: ", booked t.status = {"booked": booked, "free": free} g.current = "null" g.status = 0 table_no = '0' restuarant = request.user.username date = utils.time_now() g.last_visited = {'restuarant': restuarant, 'date': date} visited = g.restuarants['visited'] visited.append(restuarant) g.restuarants = {'visited': visited} g.save(update_fields=[ 'current', 'status', 'last_visited', 'restuarants' ]) signals.save_checkout(request.user, g.mobile, 100) t.save(update_fields=['status', 'seated']) print "-------------------------" a = request.META.get('HTTP_REFERER', '') print '============CHECKOUT ENDED=================' if a.split('/')[3] == 'front': return HttpResponseRedirect('/front/') return HttpResponseRedirect('/dashboard/') return render(request, 'clients/checkout.html') return HttpResponseRedirect('/login?msg=%s' % _MSG_CODES['lap'])
def feedback(request, fid, feed_match): print fid, feed_match feed_match = int(feed_match) if request.method == 'POST': print "REACHED POST" rating_qof = request.POST.get('rating_qof', '') rating_qos = int(request.POST.get('rating_qos', '')) rating_sf = int(request.POST.get('rating_sf', '')) rating_ab = int(request.POST.get('rating_ab', '')) rating_oe = int(request.POST.get('rating_oe', '')) print rating_qof, rating_qos, rating_sf, rating_ab, rating_oe r = Record.objects.get(id=fid, feed_match=feed_match) f = Feedback(record=r, user=r.user, mobile=r.mobile, date=utils.time_now(), service=rating_qos, ambience=rating_ab, food=rating_qof, staff_friend=rating_sf, overall_exp=rating_oe) f.save() # utils.send_sms(r.mobile,'Thankyou for Filling the feedback form') return HttpResponseRedirect('/') try: r = Record.objects.get(id=fid) try: f = Feedback.objects.get(record=r) return HttpResponseRedirect('/?msg=Already filled') except Feedback.DoesNotExist: pass if feed_match == r.feed_match: return render(request, 'clients/feedback2.html', { 'place': r.rest_name, 'date': r.date, 'name': r.name }) except Record.DoesNotExist: # return render(request,'clients/feedback2.html') print "Does not exist" return HttpResponseRedirect('/404/')
def feedback_service(request): if request.method == 'POST': print "POST-------------------" table_num = request.POST.get('tableno', '') rating_qof = request.POST.get('rating_qof', '') rating_qos = int(request.POST.get('rating_qos', '')) rating_sf = int(request.POST.get('rating_sf', '')) rating_ab = int(request.POST.get('rating_ab', '')) rating_oe = int(request.POST.get('rating_oe', '')) info_name = request.POST.get('info_name', '') dob_date = request.POST.get('dob_date', '') dob_month = request.POST.get('dob_month', '') dob_year = request.POST.get('dob_year', '') info_contact = request.POST.get('info_contact', '') comments = request.POST.get('comments', '') dob = dob_date + "/" + MONTH[dob_month] + "/" + dob_year print "lmalfmalfmlamf" if (info_contact and info_name): try: if utils.guest_exists(info_contact): pass else: g = Guest(name=info_name, mobile=info_contact, dob=datetime.datetime.strptime(dob, "%d/%m/%Y"), created_at=utils.time_now()) g.save() print rating_qof, rating_qos, rating_sf, rating_ab, rating_oe, table_num, info_name, dob, info_contact, comments fs = FeedbackService(user=request.user, date=utils.time_now(), mobile=info_contact, name=info_name, table_num=table_num, food=rating_qof, service=rating_qos, staff_friend=rating_sf, ambience=rating_ab, overall_exp=rating_oe, dob=dob, comments=comments) fs.save() print "HHAHAHAHAHAH" questions = Questions.objects.filter( user=request.user).exclude(show=0) for q in questions: print q answer = request.POST.get('question_%d' % q.id, '') a = Answers.objects.create(user=request.user, question=q, answer=answer) print "SAVED" except: return HttpResponseRedirect('/feedback?msg=Invalid Input') return HttpResponseRedirect('/feedback?msg=thanks') return HttpResponseRedirect('/feedback?msg=required') client = utils.user_to_client(request.user) try: rating_texts = RatingTexts.objects.get(user=request.user) except RatingTexts.DoesNotExist: rating_texts = RatingTexts.objects.create(user=request.user) questions = Questions.objects.filter(user=request.user).exclude(show=0) return render(request, 'clients/feedback_service.html', { 'client': client, 'rating_texts': rating_texts, 'questions': questions })
def adduser(request): error = [] if request.user.is_authenticated(): if request.method == 'POST': seat = request.POST.get('seat', '') if seat: #Visitor has to be seated directly return seatDirectly(request) takeaway = request.POST.get('takeaway', '') if takeaway: #Visitor came for takeaway return takeAway(request) mobile = request.POST.get('mobile', '') name = request.POST.get('name', '') waitingtime = request.POST.get('waitingtime', '') partysize = request.POST.get('partysize', '') add_to_waiting = request.POST.get('add_to_waiting', '') print mobile, name, waitingtime, partysize, add_to_waiting, "-------------->>>>>>>" waiting_list = utils.get_waiting_guests(request.user) seated_list = utils.get_seated_guests(request.user) if (not mobile in waiting_list) and ( not mobile in seated_list ): #Check if he's not already in waiting list or seated if utils.guest_exists(mobile): g = Guest.objects.get(mobile=mobile) g.waiting_time = waitingtime g.start_time = utils.time_now() g.status = 1 #Waiting list g.current = request.user.username g.save(update_fields=[ 'waiting_time', 'start_time', 'status', 'current' ]) else: g = Guest(mobile=mobile, created_at=utils.time_now(), start_time=utils.time_now(), status=1, current=request.user.username, waiting_time=waitingtime, name=name) g.save() ##Add user to the waiting list u = User.objects.get(username=request.user.username) utils.update_waiting_list(u, g) signals.save_waiting(request.user, mobile, waitingtime) elif (not mobile in waiting_list) and (mobile in seated_list): error = "User already seated" elif (not mobile in seated_list) and (mobile in waiting_list): error = "User already in waiting list" print "========ERROR================" print error print "=============================" if (len(error) != 0): return HttpResponseRedirect('/front?error=%s' % (error)) else: return HttpResponseRedirect('/front/') return HttpResponseRedirect('/front/') # return render(request, 'clients/front.html') else: return HttpResponseRedirect('/login?msg=%s' % _MSG_CODES['lap'])