Beispiel #1
0
    def save(self, request):
        newBook = Booking()
        newBook.customer = request.user
        newBook.payment_type = request.POST.get("payment_type")
        newBook.price = request.POST.get("price")
        newBook.total_distance = request.POST.get("total_distance")
        newBook.save()
        self.validated_data['book_id'] = newBook.id

        pickupAddress = Address()
        pickupAddress.title = request.POST.get("pickup_address_title")
        pickupAddress.description = request.POST.get(
            "pickup_address_description")
        pickupAddress.longitude = request.POST.get("pickup_address_longitude")
        pickupAddress.latitude = request.POST.get("pickup_address_latitude")
        pickupAddress.is_pickup_loc = True
        pickupAddress.booking = newBook
        pickupAddress.save()

        arrivalAddress = Address()
        arrivalAddress.title = request.POST.get("arrival_address_title")
        arrivalAddress.description = request.POST.get(
            "arrival_address_description")
        arrivalAddress.longitude = request.POST.get(
            "arrival_address_longitude")
        arrivalAddress.latitude = request.POST.get("arrival_address_latitude")
        arrivalAddress.is_arrival_loc = True
        arrivalAddress.booking = newBook
        arrivalAddress.save()

        #  find nearest userInfo
        # nearestDriverUserInfo = findNearestDriver(latitude=pickupAddress.latitude , longitude=pickupAddress.longitude , filterMaxDistance=10000)
        # newBook.driver = nearestDriverUserInfo.user
        return newBook
Beispiel #2
0
 def create_random():
     return Booking(
         car_id=1,
         person_id=1,
         start_time=datetime.now(),
         end_time=datetime.now() + timedelta(hours=5),
     )
Beispiel #3
0
class DummyBooking:
    person1_car1_available = Booking(
        car_id=1,
        person_id=1,
        start_time=datetime.now(),
        end_time=datetime.now() + timedelta(hours=5),
    )

    @staticmethod
    def create_random():
        return Booking(
            car_id=1,
            person_id=1,
            start_time=datetime.now(),
            end_time=datetime.now() + timedelta(hours=5),
        )

    b1_json = json.dumps({
        'car_id': 1,
        'person_id': 1,
        'start_time': '2020-05-03T21:2',
        'end_time': '2020-05-04T02:2',
    })

    b1_id_json = json.dumps({
        'id': 1,
        'car_id': 1,
        'person_id': 1,
        'start_time': '2020-05-03T21:2',
        'end_time': '2020-05-04T02:2',
    })
Beispiel #4
0
 def get(self):
     prospectSkype = self.request.get("prospectSkype")
     employerSkype = self.request.get("employerSkype")
     for booking in Booking.all():
         if booking.prospect.skype == prospectSkype and booking.employer.skype == employerSkype:
             booking.accepted = True
             booking.put()
Beispiel #5
0
def add_booking_admin():
    """
    Add a new booking

    Returns: Json string of booking, or error

    """

    schema = BookingSchema(exclude=['id'])
    try:
        booking = schema.loads(request.get_json())
    except ValidationError as ve:
        return abort(400, description=ve.messages)  # wow generic message
    # check that references to data in db is valid
    person = Person.query.filter_by(id=booking.person_id).first()
    car = Car.query.filter_by(id=booking.car_id).first()
    if None in [person, car]:
        return abort(403, description='Booking references invalid person/car id(s)')

    # Check that no booking with car is currently active
    if Booking.is_car_busy(booking.start_time, booking.end_time, booking.car_id):
        return abort(403, description=f'A booking with car id {booking.car_id}'
                                      f' is already mad in that time period')

    db.session.add(booking)
    handle_db_operation(db.session.commit)
    return schema.jsonify(booking), 201
Beispiel #6
0
 def post(self, request):
     """Create a booking."""
     fields = ('timeslot_id', 'size')
     rec = prepare_record(request.data, fields)
     tsid = int(rec['timeslot_id'])
     size = int(rec['size'])
     try:
         booking = Booking.book_for(tsid, size)
     except ValueError as err:
         return Http409(err.message)
     return serialize(booking)
Beispiel #7
0
def booking(request, booking_id):
    # GET information about the status of a device.  Some way of securing this so only the app can
    # access it will eventually be needed
    if request.method == 'GET':
        try:
            booking = Booking.objects.get(pk=booking_id)
            return JsonResponse(booking.toJSON())
        except Booking.DoesNotExist:
            return JsonResponse({}, status=404)
        # if(booking):
        #     return JsonResponse(booking.toJSON())
        # else:
        #     return JsonResponse({}, status=404)

    # Make request to turn on a device.  A function should respond back with a value from the arduino
    # indicating success and this can be passed back to app
    elif request.method == 'POST':
        body_unicode = request.body.decode('utf-8')
        body = json.loads(body_unicode)
        StartTime = body.get('StartTime')
        EndTime = body.get('EndTime')
        IDUser = body.get('IDUser')

        if not StartTime:
            return JsonResponse({"REASON": "Invalid StartTime provided"},
                                status=400)
        elif not EndTime:
            return JsonResponse({"REASON": "Invalid EndTime provided"},
                                status=400)
        elif not IDUser:
            return JsonResponse({"REASON": "Invalid IDUser provided"},
                                status=400)
        else:
            # this is our "happy path", once everything checks out, we send call to turn on device
            # Add your code to turn on the device here and the respond back.
            booking = Booking(IDUser=IDUser,
                              StartTime=StartTime,
                              EndTime=EndTime)
            resp = booking.save()
            print(resp)
            return JsonResponse(booking.toJSON())
Beispiel #8
0
 def get(self):
     self.response.headers["Content-Type"] = "text/plain"
     for booking in Booking.all():
         if booking.accepted:
             self.response.out.write("WRIING")
             self.response.out.write(
                 "Introduce "
                 + str(booking.employer.name)
                 + "("
                 + str(booking.employer.email)
                 + ") at "
                 + str(booking.employer.company)
                 + "  to "
                 + str(booking.prospect.name)
                 + " ("
                 + str(booking.prospect.email)
                 + ")"
             )
Beispiel #9
0
 def get(self):
     skype = self.request.get("skype")
     self.response.headers["Content-Type"] = "application/json"
     self.response.out.write(Booking.renderBookings(skype))
Beispiel #10
0
def populate_db(app):

    with app.app_context():
        print('Connecting to db..')
        db.drop_all()
        print('Connection successful!')
        print('db dropped..')
        db.create_all()
        db.session.add_all([
            cm1,
            cm2,
            cm3,
            ct1,
            ct2,
            cc1,
            cc2,
            cc3,
        ])
        db.session.commit()
        print("Required foreign key rows commited..")
        admin = Person(username='******',
                       first_name='Mr. Admin',
                       last_name='Boss',
                       email='*****@*****.**',
                       type=PersonType.ADMIN,
                       password=generate_password_hash('admin'),
                       face=None)
        engineer = Person(username='******',
                          first_name='Engineer',
                          last_name='Person',
                          email='*****@*****.**',
                          type=PersonType.ENGINEER,
                          password=generate_password_hash('engineer'),
                          face=None)
        manager = Person(username='******',
                         first_name='Mr. Manager',
                         last_name='Ad',
                         email='*****@*****.**',
                         type=PersonType.MANAGER,
                         password=generate_password_hash('manager'),
                         face=None)
        p1 = Person(username='******',
                    first_name='Random',
                    last_name='Person',
                    email='*****@*****.**',
                    type=PersonType.CUSTOMER,
                    password=generate_password_hash('as'),
                    face=None)
        p2 = Person(username='******',
                    first_name='Adi',
                    last_name='Lastname',
                    email='*****@*****.**',
                    type=PersonType.CUSTOMER,
                    password=generate_password_hash('abc123'),
                    face=None)

        c1 = Car(
            reg_number='abc123',
            car_manufacturer=cm1.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.8182711',
            longitude='144.9670618',
            hour_rate=290.5,
        )

        c2 = Car(
            reg_number='bbc123',
            car_manufacturer=cm2.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.8',
            longitude='144.96667',
            hour_rate=20.5,
        )

        c3 = Car(
            reg_number='cbc123',
            car_manufacturer=cm1.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-38.21792',
            longitude='145.03876',
            hour_rate=12.5,
        )

        c4 = Car(
            reg_number='dbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.98333',
            longitude='145.2',
            hour_rate=25.5,
        )

        c5 = Car(
            reg_number='ebc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.7983459',
            longitude='144.960974',
            hour_rate=20.5,
        )

        c6 = Car(
            reg_number='fbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.829',
            longitude='144.957',
            hour_rate=27.5,
        )

        c7 = Car(
            reg_number='gbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.8081201',
            longitude='144.9644196',
            hour_rate=11.5,
        )

        c8 = Car(
            reg_number='hbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.6690123',
            longitude='144.8410273',
            hour_rate=99.5,
        )

        c9 = Car(
            reg_number='ibc123',
            car_manufacturer=cm1.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.8332233',
            longitude='144.9124697',
            hour_rate=30.5,
        )

        c10 = Car(
            reg_number='jbc123',
            car_manufacturer=cm1.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='59.9139',
            longitude='10.7522',
            hour_rate=70.5,
        )

        c11 = Car(
            reg_number='kbc123',
            car_manufacturer=cm1.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.7923459',
            longitude='144.960974',
            hour_rate=20.5,
        )

        c12 = Car(
            reg_number='lbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc2.id,
            seats=4,
            latitude='-37.8678765',
            longitude='144.9740049',
            hour_rate=20.5,
        )

        c13 = Car(
            reg_number='mbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-38.21792',
            longitude='144.960974',
            hour_rate=50.5,
        )

        c14 = Car(
            reg_number='nbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.7983459',
            longitude='144.960974',
            hour_rate=20.5,
        )

        c15 = Car(
            reg_number='obc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='37.7983459',
            longitude='144.320974',
            hour_rate=20.5,
        )

        c16 = Car(
            reg_number='pbc123',
            car_manufacturer=cm3.id,
            car_type=ct1.id,
            car_colour=cc1.id,
            seats=4,
            latitude='59.9139',
            longitude='144.110974',
            hour_rate=20.5,
        )

        c17 = Car(
            reg_number='qbc123',
            car_manufacturer=cm3.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='37.7183459',
            longitude='144.230974',
            hour_rate=20.5,
        )

        c18 = Car(
            reg_number='rbc123',
            car_manufacturer=cm3.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.3983459',
            longitude='144.460974',
            hour_rate=20.5,
        )

        c19 = Car(
            reg_number='sbc123',
            car_manufacturer=cm1.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.283459',
            longitude='144.990974',
            hour_rate=20.5,
        )

        c20 = Car(
            reg_number='tbc123',
            car_manufacturer=cm1.id,
            car_type=ct2.id,
            car_colour=cc1.id,
            seats=4,
            latitude='-37.829',
            longitude='144.930974',
            hour_rate=20.5,
        )
        db.session.add_all([
            admin, engineer, manager, p1, p2, c1, c2, c3, c4, c5, c6, c7, c8,
            c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20
        ])
        db.session.commit()
        b1 = Booking(
            car_id=c1.id,
            person_id=p1.id,
            start_time=datetime.now().replace(microsecond=0, second=0) -
            timedelta(days=4),
            end_time=datetime.now().replace(microsecond=0, second=0) -
            timedelta(days=2),
            status=BookingStatusEnum.CANCELLED)
        b2 = Booking(
            car_id=c2.id,
            person_id=p1.id,
            start_time=datetime.now().replace(microsecond=0, second=0) -
            timedelta(days=1),
            end_time=datetime.now().replace(microsecond=0, second=0) -
            timedelta(hours=10),
            status=BookingStatusEnum.FINISHED)
        i1 = CarIssue(car_id=c1.id, issue='There are no tiers')
        i2 = CarIssue(car_id=c2.id, issue='The engine is gone')
        i3 = CarIssue(car_id=c3.id, issue='Can only drive backwards')
        i4 = CarIssue(car_id=c4.id, issue='Totalled')
        db.session.add_all([b1, b2, i1, i2, i3, i4])
        db.session.commit()
        print('All data commited!')
    print('Finished!')
Beispiel #11
0
 def create_booking(self, model: CreateBookingDto):
     booking = Booking()
     booking.booking_reference = model.booking_reference
     booking.flight_id = model.flight_id
     booking.take_off_point = model.take_off_point
     booking.price = model.price
     booking.take_off_time = model.take_off_time
     booking.destination = model.destination
     booking.flight_class = model.flight_class
     booking.name = model.name
     booking.phone = model.phone
     booking.email = model.email
     booking.address = model.address
     booking.save()