示例#1
0
def seated(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            guest_num = request.POST.get('guest_num')
            table_num = int(request.POST.get('table_num'))
            t = table.objects.get(user=request.user)
            free = t.status['free']
            booked = t.status['booked']
            booked.append(int(table_num))
            print table_num, "----------------------------------------"
            free.remove(int(table_num))
            booked.sort()
            free.sort()
            seated = t.seated['seated']
            waiting = t.waiting_list['waiting_list']
            seated.append(guest_num)
            waiting.remove(guest_num)
            t.seated = {'seated': seated}
            t.waiting_list = {'waiting_list': waiting}

            t.status = {"booked": booked, "free": free}
            t.save(update_fields=['status', 'waiting_list', 'seated'])
            g = Guest.objects.get(mobile=guest_num)
            g.current = request.user.username
            g.table_no = table_num
            g.status = 2
            signals.save_seated(request.user, guest_num, table_num)
            g.save(update_fields=['current', 'table_no', 'status'])
            return HttpResponseRedirect('/dashboard/')

        waiting_list = utils.get_waiting_guests(request.user)
        return render(request, 'clients/seated.html',
                      {'waiting_list': waiting_list})

    return HttpResponseRedirect('/login?msg=%s' % _MSG_CODES['lap'])
示例#2
0
def dashboard(request):
    if request.user.is_authenticated():
        client = utils.user_to_client(request.user)
        if client.first_login:
            return HttpResponseRedirect('/firstLogin/')
        n_of_tables = table.objects.get(user=request.user)
        seated = len(utils.get_seated_guests(request.user))
        waiting = len(utils.get_waiting_guests(request.user))
        total_guests = utils.get_total_visitors(request.user)
        total_no_show = utils.get_total_no_show(request.user)
        feed_stats = utils.get_feedback_stats(request.user)

        return render(
            request, 'clients/adminpanel/index.html', {
                'client': client,
                'n_of_tables': n_of_tables.n_of_table,
                'status': n_of_tables.status,
                'seated': seated,
                'waiting': waiting,
                'total_guests': total_guests,
                'total_no_show': total_no_show,
                'feed_stats': feed_stats
            })
    else:
        return HttpResponseRedirect('/login?msg=%s' % _MSG_CODES['lap'])
示例#3
0
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/')
示例#4
0
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'])
示例#5
0
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'])