예제 #1
0
def approval(request):
    try:
        if request.session['usrtype'] == 1 and request.session["usrp_status"]:
            token = request.session['token']

            #vehicle
            key = vehicle_controller(token)
            data = vehicle_controller.v_deactlist(key)
            vehicle_data = json.loads(data)

            #vendor
            vendor = vendor_controller(token)
            ven_data = vendor_controller.inactive_list(vendor)
            vendor_data = json.loads(ven_data)

            context = {
                "vehicle_data": vehicle_data["data"],
                "vendor_data": vendor_data["data"]
            }
            template = 'adminside/vehicle.html'
            return render(request, template, context)
        else:
            return HttpResponseRedirect('/vendor/login/')
    except:
        return HttpResponseRedirect('/vendor/login/')
예제 #2
0
def vehicle_list(request):
    token = request.session['token']
    print(token)
    vehicle_key = vehicle_controller(token)

    vehicle_list = json.loads(vehicle_controller.v_list(vehicle_key))

    v_list = vehicle_list["data"]

    vl = json.dumps(v_list, indent=4)

    return HttpResponse(vl)
예제 #3
0
def search_vehicles(request):
    token = request.session['token']
    vehicle_key = vehicle_controller(token)

    vehicle_list = json.loads(vehicle_controller.v_list(vehicle_key))
    print("vehicle_list")

    for i in vehicle_list["data"]:
        for e in range(i["imgcount"]):
            count = e
            img = "{plate}_{count}".format(plate=i["platenumber"], count=count)

    geturl = vehicle_controller(id)
    url = vehicle_controller.get_imageurl(geturl)
    print(url)

    context = {"data": vehicle_list["data"], "count": count, "url": url}

    template = 'vendor/z_dummy_search.html'
    response = render(request, template, context)

    return response
예제 #4
0
def reqDeactivate(request, v_id):
    token = request.session['token']

    n = datetime.datetime.now()
    unix_time = int(time.mktime(n.timetuple()))
    exp = request.session['exp']
    uid = request.session['uid']
    usrtype = request.session['usrtype']

    print(usrtype, "USERTYPE")

    if unix_time >= int(exp):
        print("Session Expired")
        response = redirect('/vendor/login/')
    else:
        if usrtype == 2 and request.session['usrp_status'] == 1:
            data_file = jwt.decode(token, verify=False)
            print(data_file)
            for i in data_file["profile"]:
                print(i)
            fullname = ("{} {}".format(i['firstname'], i['lastname']))
            print(fullname)
            address = 'Sitio Avocado Lahug Cebu City'

            if request.POST:
                data = {}
                data["id"] = v_id
                data["particulars"] = request.POST["particulars"]

                if data["particulars"] == "":
                    print("None")
                else:
                    print("Valid")
                    data_req = json.dumps(data)
                    reg = vehicle_controller(data_req, token, v_id)
                    register = vehicle_controller.v_reqdeactivate(reg)
                    print(register)

                return HttpResponseRedirect('../../')

            context = {'address': address, 'fullname': fullname}
            template = "vendor/vehicle_deactivation.html"
            print("Session Started")
            response = render(request, template, context)
        elif usrtype != 2:
            print("You are not a vendor User!")

            response = redirect('/vendor/login/')

    return response
예제 #5
0
def activate(request, id, v_type):

    token = request.session['token']
    v_id = {"id": id}
    vid = json.dumps(v_id)

    if v_type == 'vehicle':
        key = vehicle_controller(vid, token)
        res = vehicle_controller.v_activate(key)
        data = json.loads(res)
        if data['code'] == '200':
            return HttpResponseRedirect('/admin/approval')
    elif v_type == 'vendor':
        key = vendor_controller(vid, token)
        res = vendor_controller.activate(key)
        data = json.loads(res)
        if data['code'] == '200':
            return HttpResponseRedirect('/admin/approval')

    return HttpResponseRedirect('/admin/approval')
예제 #6
0
def home(request):
    template = 'home/homepage.html'
    lis = vehicle_controller.v_type(None)
    datas = json.loads(lis)
    if not request.user.is_authenticated:
        if 'HTTP_AUTHORIZATION' in request.META:
            auth = request.META['HTTP_AUTHORIZATION'].split()
            if len(auth) == 2:
                if auth[0].lower() == "basic":
                    username, password = base64.b64decode(
                        auth[1]).decode('utf-8').split(':')
                    user = authenticate(username=username, password=password)
                    login(request, user)
                    if user is not None and user.is_active:
                        # handle your view here
                        try:
                            if request.session["usrtype"] == 3:

                                token = request.session["token"]
                                uid = request.session["uid"]
                                usrtype = request.session["usrtype"]

                                data = vehicle_controller(token)
                                vehicle = json.loads(
                                    vehicle_controller.v_list(data))

                                data1 = client_controller(token, uid)
                                profile = json.loads(
                                    client_controller.client_profile(data1))

                                client_id = profile["data"][0]["client_id"]

                                context = {
                                    'status': usrtype,
                                    'c_id': client_id,
                                    "vehicle": vehicle["data"],
                                    'datas': datas["data"]
                                }
                                response = render(request, template, context)
                                return response

                        except Exception as e:

                            print(" ")

                        status = 0
                        client_id = 0
                        context = {
                            'c_id': client_id,
                            'status': status,
                            'datas': datas["data"]
                        }
                        response = render(request, template, context)

                        # >>>>>>>>>>>>>>>>>>>>>>>>>
                        return response
        # otherwise ask for authentification
        response = HttpResponse("")
        response.status_code = 401
        response['WWW-Authenticate'] = 'Basic realm="restricted area"'
        return response
    else:
        # handle your view here
        try:
            if request.session["usrtype"] == 3:

                token = request.session["token"]
                uid = request.session["uid"]
                usrtype = request.session["usrtype"]

                data = vehicle_controller(token)
                vehicle = json.loads(vehicle_controller.v_list(data))

                data1 = client_controller(token, uid)
                profile = json.loads(client_controller.client_profile(data1))

                client_id = profile["data"][0]["client_id"]
                fullname = "{fname} {lname}".format(
                    fname=profile["data"][0]["fname"],
                    lname=profile["data"][0]["lname"])

                context = {
                    'status': usrtype,
                    'c_id': client_id,
                    "vehicle": vehicle["data"],
                    'datas': datas["data"],
                    'fullname': fullname
                }
                response = render(request, template, context)
                return response

        except Exception as e:

            print(" ")

        status = 0
        client_id = 0
        context = {'c_id': client_id, 'status': status, 'datas': datas["data"]}
        response = render(request, template, context)

        # >>>>>>>>>>>>>>>>>>>>>>>>>
        return response
예제 #7
0
def updateVehicle(request, v_id):
    # Vehicle category list
    lis = vehicle_controller.v_type(None)
    datas = json.loads(lis)
    # end >.
    vehicle_id = v_id
    token = request.session['token']
    n = datetime.datetime.now()
    unix_time = int(time.mktime(n.timetuple()))
    exp = request.session['exp']
    uid = request.session['uid']
    usrtype = request.session['usrtype']

    print(usrtype, "USERTYPE")

    if unix_time >= int(exp):
        print("Session Expired")
        response = redirect('/vendor/login/')
    else:
        if usrtype == 2 and request.session['usrp_status'] == 1:
            data = jwt.decode(token, verify=False)
            print(data)
            for i in data["profile"]:
                print(i)
            fullname = ("{} {}".format(i['firstname'], i['lastname']))
            print(fullname)
            address = 'Sitio Avocado Lahug Cebu City'

            list = vehicle_controller(token)
            data_list = json.loads(vehicle_controller.v_list(list))

            for i in data_list["data"]:
                print(i["vehicle_id"], "VEHICLE ID")
                print(i["vendor_id"], "VENDOR_ID \n")
                ve_id = i["vehicle_id"]
                ven_id = i["vendor_id"]
                if vehicle_id == i["vehicle_id"]:
                    print(i["vehicle_id"])
                    print("TRUE")
                    single = i
                    print("\n", single, "\n\n")

            print(data_list["data"])

            if request.POST:
                body = {}
                body["vendor_id"] = v_id
                data = {}

                data["vechicle_type"] = request.POST["v_type"]
                data["qty"] = request.POST["qty"]
                data["price"] = request.POST["price"]
                data["description"] = request.POST["des"]
                data["stockonhand"] = request.POST["soh"]
                data["capacity"] = request.POST["capacity"]
                data["unit"] = request.POST["unit"]

                body["vehicle_data"] = [data]

                vehicle_form = json.dumps(body)
                print(vehicle_form, " VEHICLE UPDATE")

                reg = vehicle_controller(vehicle_form, token, v_id)
                register = vehicle_controller.v_update(reg)
                print(register)

                return HttpResponseRedirect('../../')

            context = {
                'address': address,
                'fullname': fullname,
                'i': single,
                "datas": datas["data"]
            }
            template = "vendor/vehicle_update.html"
            print("Session Started")
            response = render(request, template, context)

        elif usrtype != 2:
            print("You are not a vendor User!")

            response = redirect('/vendor/login/')

    return response
예제 #8
0
def addVehicle(request):

    n = datetime.datetime.now()
    unix_time = int(time.mktime(n.timetuple()))
    token = request.session['token']
    exp = request.session['exp']
    uid = request.session['uid']
    usrtype = request.session['usrtype']

    print("USER TYPE : {}".format(usrtype))

    # VENDOR ID
    ven_id = uid

    usrtype = request.session['usrtype']

    if unix_time >= int(exp):
        print("Session Expired")
        response = redirect('/vendor/login/')
    else:
        if usrtype == 2 and request.session['usrp_status'] == 1:
            data = jwt.decode(token, verify=False)
            # print(data)
            for i in data["profile"]:
                # print(i)
                pass
            fullname = ("{} {}".format(i['firstname'], i['lastname']))
            # print(fullname)
            address = 'Sitio Avocado Lahug Cebu City'

            if request.POST:
                body = {}
                body["vendor_id"] = ven_id
                data = {}
                image_file = []

                data["vechicle_type"] = request.POST["v_type"]
                data["qty"] = request.POST["qty"]
                data["price"] = request.POST["price"]
                data["description"] = request.POST["des"]
                data["tankcapacity"] = request.POST["tankcap"]
                data["platenumber"] = request.POST["plate"]
                data["stockonhand"] = request.POST["soh"]
                data["capacity"] = request.POST["capacity"]
                data["unit"] = request.POST["unit"]

                # print(request.POST.getlist('yea'),"FILESSSS")
                for i in request.POST.getlist('images'):
                    q = "{count_image}".format(count_image=i)
                    img = {"img-codex": q}
                    image_file.append(img)

                data["images"] = image_file
                body["vehicle_data"] = [data]

                vehicle_form = json.dumps(body)

                reg = vehicle_controller(vehicle_form, token)
                register = vehicle_controller.v_entry(reg)

                return HttpResponseRedirect('/vendor/vehicle/')

            lis = vehicle_controller.v_type(None)
            datas = json.loads(lis)

            context = {
                'address': address,
                'fullname': fullname,
                'datas': datas["data"]
            }
            template = "vendor/vehicle_add.html"
            print("Session Started")
            response = render(request, template, context)
        elif usrtype != 2:
            print("You are not a vendor User!!")

            response = redirect('/vendor/login/')

    return response
예제 #9
0
def vehicle(request):
    n = datetime.datetime.now()
    unix_time = int(time.mktime(n.timetuple()))
    exp = request.session['exp']
    uid = request.session['uid']
    usrtype = request.session['usrtype']

    print(usrtype, "USERTYPE")
    print(uid, "ID")

    if unix_time >= int(exp):
        print("Session Expired")
        response = redirect('/vendor/login/')
    else:
        if usrtype == 2 and request.session['usrp_status'] == 1:
            # user details/.
            token = request.session['token']
            data = jwt.decode(token, verify=False)
            cont = {}

            print(data)
            for i in data["profile"]:
                print(i)

            fullname = ("{} {}".format(i['firstname'], i['lastname']))
            print(fullname)
            address = 'Sitio Avocado Lahug Cebu City'

            key = vehicle_controller(token)

            data_list = json.loads(vehicle_controller.v_list(key))
            inactive_list = json.loads(vehicle_controller.v_deactlist(key))

            # Context Base Dictionary
            cont = {'address': address, 'fullname': fullname, 'ven_id': uid}

            if data_list["code"] == '200':
                print("DATA LIST ", data_list["code"])
                for i in data_list["data"]:
                    for e in range(i["imgcount"]):

                        count_act = e
                        img = "{plate}_{count}".format(plate=i["platenumber"],
                                                       count=count_act)
                        print(img)
                cont["vehicle_list"] = data_list["data"]
                cont["count_act"] = count_act
                cont["msg_act"] = data_list["code"]
            else:
                print("DATA LIST ", data_list["code"])
                cont["msg_act"] = data_list["code"]

            if inactive_list["code"] == '200':
                print("INACTIVE LIST ", inactive_list["code"])
                for i in inactive_list["data"]:
                    for e in range(i["imgcount"]):

                        count_inact = e
                        img = "{plate}_{count}".format(plate=i["platenumber"],
                                                       count=count_inact)

                cont["vehicle_deactlist"] = inactive_list["data"]
                cont["count_inact"] = count_inact
                cont["msg_deact"] = inactive_list["code"]

            else:
                print("INACTIVE LIST ", inactive_list["code"])
                cont["msg_deact"] = inactive_list["code"]

            geturl = vehicle_controller(id)
            url = vehicle_controller.get_imageurl(geturl)
            cont["endpoint"] = url
            print(url)
            lis = vehicle_controller.v_type(None)
            datas = json.loads(lis)
            cont["datas"] = datas["data"]

            # context dictionary
            context = cont
            # end >.
            print("Session Started")
            template = "vendor/vehicle.html"
            response = render(request, template, context)
        else:
            response = HttpResponseRedirect('/vendor/login/')

    return response
예제 #10
0
def dashboard(request):
    # Set time now /. UNIX TIME
    n = datetime.datetime.now()
    unix_time = int(time.mktime(n.timetuple()))
    # end >.

    exp = request.session['exp']
    uid = request.session['uid']
    usrtype = request.session['usrtype']
    print("USER TYPE : {}".format(usrtype))

    # checking session if Expired /.
    if unix_time >= int(exp):
        print("Session Expired")

        response = redirect('/vendor/login/')
    else:
        if usrtype == 2 and request.session['usrp_status'] == 1:
            print("Session Started")

            # user profile /.
            token = request.session['token']

            print(token)
            data = jwt.decode(token, verify=False)
            for i in data["profile"]:
                pass
            fullname = ("{} {}".format(i['firstname'], i['lastname']))
            address = 'Sitio Avocado Lahug Cebu City'
            # end >.

            book_key = booking_controller(token)
            booking_current = json.loads(
                booking_controller.b_currentlist(book_key))
            booking_future = json.loads(
                booking_controller.b_futurelist(book_key))

            current_booking = booking_current["data"]
            future_booking = booking_future["data"]

            msg_codeC = booking_current["code"]
            msg_codeF = booking_future["code"]

            c_booking = []
            f_booking = []

            if msg_codeC == '200':
                for bc in current_booking:
                    cid = bc['client_id']
                    vid = bc['vehicleID']
                    client_key = client_controller(token, cid)
                    vehicle_key = vehicle_controller(token, vid)

                    client_name = json.loads(
                        client_controller.client_single(client_key))
                    vehicle_type = json.loads(
                        vehicle_controller.v_single(vehicle_key))

                    if vehicle_type["code"] == '204':
                        clientName = ""
                        v_type = ""

                    else:
                        clientName = client_name['data'][0][
                            'lname'] + " " + client_name['data'][0]['fname']

                        v_type = vehicle_type['data'][0]['vechicle_type']

                        c_book = {
                            'client_name': clientName,
                            'start_date': bc["start_date"],
                            'end_date': bc["end_date"],
                            'v_id': bc["vehicleID"],
                            'b_id': bc["bookingID"],
                            'vehicle_type': v_type
                        }

                        c_booking.append(c_book)

            if msg_codeF == '200':
                for bf in future_booking:
                    cid = bf['client_id']
                    vid = bf['vehicleID']

                    client_key = client_controller(token, cid)
                    vehicle_key = vehicle_controller(token, vid)

                    client_name = json.loads(
                        client_controller.client_single(client_key))
                    vehicle_type = json.loads(
                        vehicle_controller.v_single(vehicle_key))

                    if vehicle_type['code'] == '204' or client_name[
                            'code'] == '203':
                        clientName = ""
                        v_type = ""
                    else:
                        clientName = client_name['data'][0][
                            'lname'] + " " + client_name['data'][0]['fname']
                        v_type = vehicle_type['data'][0]['vechicle_type']

                        f_book = {
                            'client_name': clientName,
                            'start_date': bf["start_date"],
                            'end_date': bf["end_date"],
                            'v_id': bf["vehicleID"],
                            'b_id': bf["bookingID"],
                            'vehicle_type': v_type
                        }

                        f_booking.append(f_book)

                context = {
                    'address': address,
                    'fullname': fullname,
                    'c_booked': c_booking,
                    'f_booked': f_booking,
                    'msg_codeC': msg_codeC,
                    'msg_codeF': msg_codeF,
                    'total_booking': len(f_booking)
                }
            else:
                context = {
                    'address': address,
                    'fullname': fullname,
                }
            template = "vendor/dashboard.html"
            response = render(request, template, context)

        else:
            print("You are not a vendor User!")

            response = redirect('/vendor/login/')

    return response
예제 #11
0
def clientVehicleList(request):
    lis = vehicle_controller.v_type(None)
    datas = json.loads(lis)
    print(request.POST, "HOYYY")
    try:
        if request.session["usrtype"] == 3 and request.session["token"]:
            token = request.session["token"]
            uid = request.session["uid"]
            print(uid, "UID")
            usrtype = request.session["usrtype"]

            if request.method == 'POST':
                if request.POST["now"] == "now":
                    body = {}
                    body["vehicle_type"] = request.POST["v_type"]
                    body["picking_time"] = "{}:00".format(
                        request.POST["p_time"])

                    data = json.dumps(body)
                    reqdata = vehicle_controller(data, token)
                    details = json.loads(
                        vehicle_controller.v_asapsearch(reqdata))

                else:
                    body1 = {}
                    body1["vehicle_type"] = request.POST["v_type_later"]

                    sdate = request.POST["s_date_later"]
                    defuse_sd = sdate.split('T')

                    edate = request.POST["e_date_later"]
                    defuse_ed = edate.split('T')

                    body1["start_date"] = "{d} {t}:00".format(d=defuse_sd[0],
                                                              t=defuse_sd[1])
                    body1["end_date"] = "{d} {t}:00".format(d=defuse_ed[0],
                                                            t=defuse_ed[1])
                    body1["picking_time"] = "{d} {t}:00".format(
                        d=defuse_sd[0], t=request.POST["p_time_later"])

                    data = json.dumps(body1)
                    reqdata = vehicle_controller(data, token)
                    details = json.loads(vehicle_controller.v_search(reqdata))

                data1 = client_controller(token, uid)
                profile = json.loads(client_controller.client_profile(data1))

                client_id = profile["data"][0]["client_id"]
                fullname = "{fname} {lname}".format(
                    fname=profile["data"][0]["fname"],
                    lname=profile["data"][0]["lname"])

                geturl = vehicle_controller(id)
                url = vehicle_controller.get_imageurl(geturl)

                if details["code"] == '200':

                    for i in details["data"]:
                        for e in range(i["imgcount"]):
                            count = e
                            img = "{plate}_{count}".format(
                                plate=i["platenumber"], count=count)

                    context = {
                        'status': usrtype,
                        'c_id': client_id,
                        'search': details["data"],
                        'msg': details["code"],
                        'count': count,
                        'url': url,
                        'datas': datas["data"],  # Vehicle category list
                        'fullname': fullname
                    }
                else:
                    context = {
                        'status': usrtype,
                        'c_id': client_id,
                        'search': details["data"],
                        'msg': details["code"],
                        'datas': datas["data"],  # Vehicle category list
                        'fullname': fullname
                    }

                template = 'client/client-vehicleList.html'
                response = render(request, template, context)
            else:
                response = HttpResponseRedirect('/vendor/login')
        return response
    except:
        response = HttpResponseRedirect('/vendor/login')

    return response