示例#1
0
def book(rego):
    car = system.get_car(rego)
    if car is None:
        abort(404)
    if request.method == 'POST':
        date_format = "%Y-%m-%d"
        start_date = datetime.strptime(request.form['start_date'], date_format)
        end_date = datetime.strptime(request.form['end_date'], date_format)
        diff = (end_date - start_date).days
        if 'check' in request.form:
            fee = car.get_fee(diff)
            return render_template('booking_form.html',
                                   confirmation=True,
                                   form=request.form,
                                   car=car,
                                   fee=fee)
        elif 'confirm' in request.form:
            location = Location(request.form['start'], request.form['end'])
            try:
                booking = system.make_booking(current_user, diff, car,
                                              location)
                return render_template('booking_confirm.html', booking=booking)

            except BookingError as error:
                return render_template('booking_form.html', error=error.msg)

    return render_template('booking_form.html', car=car)
示例#2
0
def book(rego):
    car = system.get_car(rego)

    if not car:
        abort(404)

    if request.method == 'POST':
        date_format = "%Y-%m-%d"
        start_date = datetime.strptime(request.form['start_date'], date_format)
        end_date = datetime.strptime(request.form['end_date'], date_format)

        num_days = (end_date - start_date).days + 1

        if 'check' in request.form:
            fee = car.get_fee(num_days)

            return render_template('booking_form.html',
                                   confirmation=True,
                                   form=request.form,
                                   car=car,
                                   fee=fee)

        elif 'confirm' in request.form:
            location = Location(request.form['start'], request.form['end'])
            booking = system.make_booking(current_user, num_days, car,
                                          location)

            return render_template('booking_confirm.html', booking=booking)

    return render_template('booking_form.html', car=car)
示例#3
0
def book(rego):
    car = system.get_car(rego)

    if car is None:
        abort(404)
    if request.method == 'POST':
        date_format = "%Y-%m-%d"
        location = Location(request.form['start'], request.form['end'])

        try:
            start_date = datetime.strptime(request.form['start_date'],
                                           date_format)
            end_date = datetime.strptime(request.form['end_date'], date_format)
            diff = end_date - start_date
            booking = system.make_booking(current_user, diff, car, location)

        except ValueError as error:
            print("error: {0}".format(error))
            error = "Date can not be empty"
            flash(error)
            return render_template('booking_form.html', car=car, error=error)
        except BookingError as error:
            flash(error.msg)
            return render_template('booking_form.html', car=car, error=error)

        if 'check' in request.form:
            fee = car.get_fee(diff.days)
            return render_template('booking_form.html',
                                   confirmation=True,
                                   form=request.form,
                                   car=car,
                                   fee=fee)
        elif 'confirm' in request.form:
            return render_template('booking_confirm.html', booking=booking)
    return render_template('booking_form.html', car=car)
示例#4
0
def book(rego):
    car = system.get_car(rego)
    if car is None:
        abort(404)
    if request.method == 'POST':
        date_format = "%Y-%m-%d"
        
        try:
            start_date = convert_time(request.form['start_date'], 0)
            end_date = convert_time(request.form['end_date'], 1)
        except BookingError as err:
            error_string = err.msg
            return render_template('booking_form.html', car=car, errmsg = err.msg)

        diff = end_date - start_date
        if 'check' in request.form:
            fee = car.get_fee(diff.days)
            return render_template(
                'booking_form.html',
                confirmation=True,  
                form=request.form,
                car=car,
                fee=fee
            )
        elif 'confirm' in request.form:
            location = Location(request.form['start'], request.form['end'])
            booking = system.make_booking(current_user, diff, car, location)
            if isinstance(booking, BookingError):
                return render_template('booking_form.html', car=car, errmsg = booking.msg)

            return render_template('booking_confirm.html', booking=booking)
    return render_template('booking_form.html', car=car)
示例#5
0
def car(rego):
    car = system.get_car(rego)

    if not car:
        abort(404)

    return render_template('car_details.html', car=car)
示例#6
0
def car_bookings(rego):
    """
    Task 3: This should render a new template that shows a list of all
    the bookings associated with the car represented by 'rego'
    """
    car = system.get_car(rego)
    bookings = car.bookings
    return render_template('bookings.html', bookings=bookings)
示例#7
0
def car_bookings(rego):
    """
    Task 3: This should render a new template that shows a list of all
    the bookings associated with the car represented by 'rego'
    The bookings.html template is intended for this route
    """
    car = system.get_car(rego)
    bookings = car.get_bookings()
    #print(bookings)
    return render_template('bookings.html', car=car, bookings=bookings)
示例#8
0
文件: rr.py 项目: namsu-kim-unsw/lab8
def book(rego):
    car = system.get_car(rego)
    if car is None:
        abort(404)
    if request.method == 'POST':
        form_start_date = request.form['start_date']
        form_end_date   = request.form['end_date']

        if 'check' in request.form:
            try:
                period = system.check_booking_period(form_start_date, form_end_date)
            except BookingError as err:
                return render_template (
                    'booking_form.html',
                    form=request.form, #gives access to form for use in booking_form.html through jinja :
                    car=car,
                    error_message = err.error_message,
                    error = True
                )
            except ValueError as err:
                error_message = "Incorrectly formatted date. Required date format: YYYY-MM-DD"
                return render_template (
                    'booking_form.html',
                    form=request.form, #gives access to form for use in booking_form.html through jinja :
                    car=car,
                    error_message = error_message,
                    error = True
                )
            
            fee = car.get_fee(period)
 
            return render_template(
                'booking_form.html',
                confirmation=True,
                form=request.form,
                car=car,
                fee=fee,
            )
        elif 'confirm' in request.form:
            location = Location(request.form['start'], request.form['end'])
            period = system.check_booking_period(form_start_date, form_end_date)
            try:
                booking = system.make_booking(current_user, period, car, location)
            except BookingError as err:
                return render_template (
                    'booking_form.html',
                    form=request.form, #gives access to form for use in booking_form.html through jinja :
                    car=car,
                    error_message = err.error_message,
                    error = True
                )
            return render_template('booking_confirm.html', booking=booking)
    return render_template('booking_form.html', car=car)
示例#9
0
文件: routes.py 项目: A-Dajon/lab09
def car(rego):
    car = system.get_car(rego)
    #rating = 5
    if not car:
        abort(404)
    

    #ratings_list = system.add_rating(rating)
    #new_rating = sum(ratings_list)/len(ratings_list)
    #rating = new_rating

    return render_template('car_details.html', car=car)
示例#10
0
def book(rego):
    car = system.get_car(rego)

    if car is None:
        abort(404)
    if request.method == 'POST':

        try:
            errors = check_input_fields_booking(request.form['start_location'],
                                                request.form['end_location'],
                                                request.form['start_date'],
                                                request.form['end_date'])
            if errors:
                raise BookingException(errors)
            else:
                date_format = "%Y-%m-%d"
                start_date = datetime.strptime(request.form['start_date'],
                                               date_format)
                end_date = datetime.strptime(request.form['end_date'],
                                             date_format)
                diff = end_date - start_date
                if 'check' in request.form:
                    fee = car.get_fee(diff.days)
                    return render_template('booking_form.html',
                                           confirmation=True,
                                           form=request.form,
                                           car=car,
                                           fee=fee,
                                           errors={})
                elif 'confirm' in request.form:
                    #debug = open("debug.txt", 'a+')
                    #debug.write("IN BOOKING")
                    #debug.close()
                    location = Location(request.form['start_location'],
                                        request.form['end_location'])
                    booking = system.make_booking(current_user, diff.days, car,
                                                  location)

                    return render_template('booking_confirm.html',
                                           booking=booking,
                                           errors={})
        except BookingException as be:
            return render_template('booking_form.html',
                                   form=request.form,
                                   car=car,
                                   errors=be.errors)
    return render_template('booking_form.html', car=car, errors={})
示例#11
0
def book(rego):
    car = system.get_car(rego)

    if not car:
        abort(404)

    if request.method == 'POST':
        #---------added start----------

        ## date_format = "%Y-%m-%d"
        ## start_date  = datetime.strptime(request.form['start_date'], date_format)
        ## end_date    = datetime.strptime(request.form['end_date'],   date_format)
        ##num_days = (end_date - start_date).days + 1

        if 'check' in request.form:
            ##fee = car.get_fee(num_days)
            try:
                fee = system.check_fee(car, request.form['start_date'],
                                       request.form['end_date'])

                return render_template('booking_form.html',
                                       confirmation=True,
                                       form=request.form,
                                       car=car,
                                       fee=fee)

            except BookingError as e:
                return render_template('booking_form.html',
                                       error_message=e.message)
        elif 'confirm' in request.form:
            #-------------added start---------------
            ##location = Location(request.form['start'], request.form['end'])
            ##booking  = system.make_booking(current_user, num_days, car, location)
            try:
                booking = system.make_booking(current_user,
                                              request.form['start_date'],
                                              request.form['end_date'], car,
                                              request.form['start'],
                                              request.form['end'])
                return render_template('booking_confirm.html', booking=booking)

            except BookingError as e:
                return render_template('booking_form.html',
                                       error_message=e.message)
        #-------------added end-------------

    return render_template('booking_form.html', car=car)
示例#12
0
文件: routes.py 项目: A-Dajon/lab09
def book(rego):
    car = system.get_car(rego)

    if not car:
        abort(404)
    
    if request.method == 'POST':
        date_format = "%Y-%m-%d"
        
  
        s_date = request.form['start_date']
        e_date = request.form['end_date']
        if s_date == '':
            return render_template('booking_form.html', error = 'Specify a valid start date')
        elif e_date == '':
            return render_template('booking_form.html', error = 'Specify a valid end date')
           
        start_date  = datetime.strptime(request.form['start_date'], date_format)
        end_date    = datetime.strptime(request.form['end_date'],   date_format)
        start_loc = request.form['start']
        end_loc = request.form['end']
        
        num_days = (end_date - start_date).days + 1

        if 'check' in request.form:
            fee = car.get_fee(num_days)
            
            return render_template(
                'booking_form.html',
                confirmation=True,
                form=request.form,
                car=car,
                fee=fee
            ) 

        elif 'confirm' in request.form:
            location = Location(request.form['start'], request.form['end'])    
                   
            try:    
                booking  = system.make_booking(current_user, num_days, car, location, start_date, end_date, start_loc, end_loc)
            except BookingError as error:                 
                return render_template('booking_form.html', error = error.message)
            else:
                return render_template('booking_confirm.html', booking = booking)
            
    return render_template('booking_form.html', car=car)
示例#13
0
文件: routes.py 项目: A-Dajon/lab09
def car_bookings(rego):
    """
    Task 3: This should render a new template that shows a list of all
    the bookings associated with the car represented by 'rego'
    """
    
    car = system.get_car(rego)
    bookings = car.bookings
    
    '''
    list = []    
    for booking in bookings:
            list.append(booking) 
    return list
    '''
    print(bookings) 
    
    return render_template('bookings.html', bookings = bookings)
示例#14
0
文件: routes.py 项目: z5117018/lab08
def book(rego):
    car = system.get_car(rego)
    if car is None:
        abort(404)
    if request.method == 'POST':
        # date_format = "%Y-%m-%d"
        # start_date = datetime.strptime(request.form['start_date'], date_format)
        start_date = request.form['start_date']
        end_date = request.form['end_date']
        pickup = request.form['start']
        dropoff = request.form['end']
        print("start date is ", start_date)
        if (pickup == ''):
            pickup = None
        if (dropoff == ''):
            dropoff = None
        if (start_date == ''):
            start_date = None
        if (end_date == ''):
            end_date = None
        # location = Location(start, end)
        try:
            booking = system.make_booking(current_user, start_date, end_date,
                                          car, pickup, dropoff)
        except BookingException as errmsg:
            return render_template('booking_form.html',
                                   car=car,
                                   msg=errmsg.args[1])

        print("booking is ", booking)
        # end_date = datetime.strptime(request.form['end_date'], date_format)
        diff = booking.get_period()
        if 'check' in request.form:
            fee = car.get_fee(diff.days)
            return render_template('booking_form.html',
                                   confirmation=True,
                                   form=request.form,
                                   car=car,
                                   fee=fee)
        elif 'confirm' in request.form:
            # location = Location(request.form['start'], request.form['end'])
            # booking = system.make_booking(current_user, diff, car, location)
            return render_template('booking_confirm.html', booking=booking)
    return render_template('booking_form.html', car=car, msg=None)
示例#15
0
def book(rego):
    car = system.get_car(rego)

    if not car:
        abort(404)

    if request.method == 'POST':
        if "make" not in request.form and "check" not in request.form:
            abort(404)

        form = BookingForm(request.form)
        print(request.form)

        # 1. If form is not valid, then display appropriate error messages
        if not form.is_valid:
            return render_template('booking_form.html',
                                   errors=form.errors,
                                   form=request.form)

        # 2. If the user has pressed the 'check' button, then display the fee
        if "check" in request.form:
            checkData = dict(
                fee=system.check_fee(car, form.start_date, form.end_date))

            return render_template('booking_form.html',
                                   car=car,
                                   data=checkData,
                                   errors=False,
                                   form=request.form)

        # 3. Otherwise, if the user has pressed the 'confirm' button, then
        #   make the booking and display the confirmation page

        customer = Customer(form.customer_name, form.customer_licence)
        booking = system.make_booking(customer, car, form.start_date,
                                      form.end_date, form.start_location,
                                      form.end_location)
        bookingData = dict(booking=booking)
        return render_template('booking_confirm.html',
                               car=car,
                               data=bookingData)

    return render_template('booking_form.html', car=car, form={})
示例#16
0
def book(rego):
    car = system.get_car(rego)
    if car is None:
        abort(404)
    if request.method == 'POST':
        date_format = "%Y-%m-%d"
        """
        try:
            if not request.form.get('start_date', ''):
                raise BookingError("start date", "Specify a valid start date")
            if not request.form.get('end_date', ''):
                raise BookingError("end date", "Specify a valid end date")
        except BookingError as errmsg:
            msg = "Error with " + errmsg.name + ": " + errmsg.msg
            return render_template('booking_form.html', car=car, err=msg)
        else:
        """

        start_date = datetime.strptime(request.form['start_date'], date_format)
        end_date = datetime.strptime(request.form['end_date'], date_format)
        diff = end_date - start_date
        if 'check' in request.form:
            fee = car.get_fee(diff.days)
            return render_template('booking_form.html',
                                   confirmation=True,
                                   form=request.form,
                                   car=car,
                                   fee=fee)
        elif 'confirm' in request.form:
            location = Location(request.form['start'], request.form['end'])
            booking = system.make_booking(current_user, diff, car, location)
            if isinstance(booking, str):
                return render_template('booking_form.html',
                                       car=car,
                                       err=booking)
            return render_template('booking_confirm.html', booking=booking)
    return render_template('booking_form.html', car=car)
示例#17
0
def book(rego):
    car = system.get_car(rego)
    error = {}
    error['name'] = ''
    error['licence'] = ''
    error['date1'] = ''
    error['date2'] = ''
    error['loc1'] = ''
    error['loc2'] = ''
    error['period'] = ''

    values = {}
    values['name'] = ''
    values['licence'] = ''
    values['date1'] = ''
    values['date2'] = ''
    values['loc1'] = ''
    values['loc2'] = ''
    values['fee'] = ''

    if not car:
        abort(404)

    if request.method == 'POST':

        form = BookingForm(request.form)
        form._parse(request.form)
        values['name'] = form.customer_name
        values['licence'] = form.customer_licence
        values['loc1'] = form.start_location
        values['loc2'] = form.end_location
        values['date1'] = request.form["start_date"]
        values['date2'] = request.form["end_date"]

        if form.is_valid == False:
            error['name'] = form.get_error('customer_name')
            error['licence'] = form.get_error('customer_licence')
            error['date1'] = form.get_error('start_date')
            error['date2'] = form.get_error('end_date')
            error['loc1'] = form.get_error('start_location')
            error['loc2'] = form.get_error('end_location')
            error['period'] = form.get_error('period')

            return render_template('booking_form.html',
                                   car=car,
                                   error=error,
                                   values=values)

        if 'check' in request.form:
            values['fee'] = system.check_fee(car, form.start_date,
                                             form.end_date)
            return render_template('booking_form.html',
                                   car=car,
                                   error=error,
                                   values=values)

        elif 'confirm' in request.form:
            name = form.customer_name
            license = form.customer_licence
            customer = Customer(name, license)

            date1 = form.start_date
            date2 = form.end_date

            loc1 = form.start_location
            loc2 = form.end_location
            nbooking = system.make_booking(customer, car, date1, date2, loc1,
                                           loc2)

            return render_template('booking_confirm.html', booking=nbooking)
        '''
        IMPLEMENT THIS SECTION
        '''

        # 1. If form is not valid, then display appropriate error messages

        # 2. If the user has pressed the 'check' button, then display the fee

        # 3. Otherwise, if the user has pressed the 'confirm' button, then
        #   make the booking and display the confirmation page

    return render_template('booking_form.html',
                           car=car,
                           error=error,
                           values=values)