예제 #1
0
def bookings_create():
    form = BookingFormCreate(request.form)

    if not form.validate():
        return render_template("bookings/new.html", form=form)

    start_dt = dt.combine(form.start_date.data, form.start_time.data)
    end_dt = dt.combine(form.end_date.data, form.end_time.data)

    if start_dt < dt.utcnow() and ADMIN not in current_user.roles():
        form.start_date.errors.append(msg_past)
        form.start_time.errors.append(msg_past)
        return render_template("bookings/new.html", form=form)

    if start_dt >= end_dt:
        form.start_date.errors.append(msg_start)
        form.start_time.errors.append(msg_start)
        form.end_date.errors.append(msg_end)
        form.end_time.errors.append(msg_end)
        return render_template("bookings/new.html", form=form)

    b = Booking(form.account.data.id, form.resource.data.id, start_dt, end_dt)

    if not Booking.is_free_time_slot(b):
        for field in [
                form.resource, form.start_date, form.start_time, form.end_date,
                form.end_time
        ]:
            field.errors.extend(
                [msg_free_rts_1(form.resource.data), msg_free_rts_2])
        return render_template("bookings/new.html", form=form)

    db.session().add(b)
    db.session().commit()
    return redirect(url_for("bookings_single", booking_id=b.id))
예제 #2
0
def client_my():
    return render_template("auth/my.html",
                           client=current_user,
                           approved_bookings=Booking.approved_bookings(
                               current_user.id, True),
                           not_approved_bookings=Booking.approved_bookings(
                               current_user.id, False))
예제 #3
0
def bookings_update(booking_id):
    b = Booking.query.get(booking_id)

    if not b:
        return render_template("404.html", res_type="booking"), 404

    if ((b.start_dt <= dt.utcnow() and ADMIN not in current_user.roles())
            or b.id not in [b.id for b in Booking.get_allowed_by_account()]):
        return login_manager.unauthorized()

    old_b = copy.deepcopy(b)
    form = BookingFormUpdate(request.form)

    if not form.validate():
        return render_template("bookings/update.html", booking=b, form=form)

    for field in [form.account, form.resource]:
        if field.data:
            setattr(b, field.name, field.data)

    b.start_dt = dt.combine(form.start_date.data, form.start_time.data)
    b.end_dt = dt.combine(form.end_date.data, form.end_time.data)

    if b.start_dt < dt.utcnow() and ADMIN not in current_user.roles():
        form.start_date.errors.append(msg_past)
        form.start_time.errors.append(msg_past)
        return render_template("bookings/update.html",
                               booking=old_b,
                               form=form)

    if b.start_dt >= b.end_dt:
        for field in [form.start_date, form.start_time]:
            if field:
                field.errors.append(msg_start)
        for field in [form.end_date, form.end_time]:
            if field:
                field.errors.append(msg_end)
        return render_template("bookings/update.html",
                               booking=old_b,
                               form=form)

    if not Booking.is_free_time_slot(b):
        for field in [
                form.resource, form.start_date, form.start_time, form.end_date,
                form.end_time
        ]:
            field.errors.extend(
                [msg_free_rts_1(form.resource.data), msg_free_rts_2])
        return render_template("bookings/update.html",
                               booking=old_b,
                               form=form)

    b.calculate_price()
    db.session().commit()
    return redirect(url_for("bookings_single", booking_id=b.id))
예제 #4
0
def bookings_single(booking_id):
    b = Booking.query.get(booking_id)

    if not b:
        return render_template("404.html", res_type="booking"), 404

    if b.id not in [b.id for b in Booking.get_allowed_by_account()]:
        return login_manager.unauthorized()

    return render_template("bookings/single.html", booking=b)
예제 #5
0
def bookings_delete_ask(booking_id):
    b = Booking.query.get(booking_id)

    if not b:
        return render_template("404.html", res_type="booking"), 404

    if ((b.start_dt <= dt.utcnow() and ADMIN not in current_user.roles())
            or b.id not in [b.id for b in Booking.get_allowed_by_account()]):
        return login_manager.unauthorized()

    return render_template("bookings/delete.html", booking=b)
예제 #6
0
def bookings_delete(booking_id):
    b = Booking.query.get(booking_id)

    if not b:
        return render_template("404.html", res_type="booking"), 404

    if ((b.start_dt <= dt.utcnow() and ADMIN not in current_user.roles())
            or b.id not in [b.id for b in Booking.get_allowed_by_account()]):
        return login_manager.unauthorized()

    db.session.delete(b)
    db.session.commit()
    return redirect(url_for("bookings_list"))
예제 #7
0
파일: views.py 프로젝트: nigoshh/hoax
def invoices_form_update(invoice_id):
    i = Invoice.query.get(invoice_id)

    if not i:
        return render_template("404.html", res_type="invoice"), 404

    if i.id not in [i.id for i in Invoice.get_allowed()]:
        return login_manager.unauthorized()

    form = InvoiceFormUpdate()
    form.bookings.query = Booking.get_allowed_by_account(invoice_id)
    form.bookings.data = i.bookings
    form.paid.data = i.paid
    return render_template("invoices/update.html", invoice=i, form=form)
예제 #8
0
def bookings_form_update(booking_id):
    b = Booking.query.get(booking_id)

    if not b:
        return render_template("404.html", res_type="booking"), 404

    if ((b.start_dt <= dt.utcnow() and ADMIN not in current_user.roles())
            or b.id not in [b.id for b in Booking.get_allowed_by_account()]):
        return login_manager.unauthorized()

    form = BookingFormUpdate()
    form.account.data = b.account
    form.resource.data = b.resource
    form.start_date.data = b.start_dt.date()
    form.start_time.data = b.start_dt.time()
    form.end_date.data = b.end_dt.date()
    form.end_time.data = b.end_dt.time()
    return render_template("bookings/update.html", booking=b, form=form)
예제 #9
0
파일: views.py 프로젝트: nigoshh/hoax
def invoices_update(invoice_id):
    i = Invoice.query.get(invoice_id)

    if not i:
        return render_template("404.html", res_type="invoice"), 404

    if i.id not in [i.id for i in Invoice.get_allowed()]:
        return login_manager.unauthorized()

    old_i = copy.deepcopy(i)
    form = InvoiceFormUpdate(request.form)
    form.bookings.query = Booking.get_allowed_by_account(invoice_id)

    if not form.validate():
        return render_template("invoices/update.html", invoice=i, form=form)

    # checking that all bookings belong to the same account
    if len(set([b.account.username for b in form.bookings.data])) > 1:
        form.bookings.errors.append(msg_same_account)
        return render_template("invoices/update.html",
                               invoice=old_i,
                               form=form)

    if i.paid and form.paid.data:
        form.bookings.errors.append(msg_paid)
        return render_template("invoices/update.html",
                               invoice=old_i,
                               form=form)

    for field in form:
        setattr(i, field.name, field.data)
    i.calculate_price()

    try:
        db.session().commit()
    except exc.SQLAlchemyError as e:
        db.session().rollback()
        form.bookings.errors.append(msg_unique)
        return render_template("invoices/update.html",
                               invoice=old_i,
                               form=form)

    return redirect(url_for("invoices_single", invoice_id=i.id))
예제 #10
0
def bookings_list():
    form = BookingFormFilter(request.args)
    form.validate()

    from_dt = None
    if (form.from_date.data or form.from_time.data):
        if (form.from_date.data and form.from_time.data):
            from_dt = dt.combine(form.from_date.data, form.from_time.data)
        elif form.from_date.data:
            form.from_date.errors.append(msg_both_from_date)
            form.from_time.errors.append(msg_both_from_date)
        else:
            form.from_date.errors.append(msg_both_from_time)
            form.from_time.errors.append(msg_both_from_time)
    to_dt = None
    if (form.to_date.data or form.to_time.data):
        if (form.to_date.data and form.to_time.data):
            to_dt = dt.combine(form.to_date.data, form.to_time.data)
        elif form.to_date.data:
            form.to_date.errors.append(msg_both_to_date)
            form.to_time.errors.append(msg_both_to_date)
        else:
            form.to_date.errors.append(msg_both_to_time)
            form.to_time.errors.append(msg_both_to_time)

    if from_dt and to_dt and from_dt >= to_dt:
        from_dt = None
        to_dt = None
        form.from_date.errors.append(msg_from)
        form.from_time.errors.append(msg_from)
        form.to_date.errors.append(msg_to)
        form.to_time.errors.append(msg_to)

    resource_ids = [r.id for r in form.resources.data]

    return render_template("bookings/list.html",
                           form=form,
                           bookings=Booking.get_allowed_by_resource(
                               from_dt, to_dt, resource_ids,
                               form.filter_not_in_invoice.data))
예제 #11
0
def bookings_create(destination_id, accomodation_id, roomtype_id):
    form = BookingForm(request.form)

    d = Destination.query.get(destination_id)
    a = Accomodation.query.get(accomodation_id)
    r = RoomType.query.get(roomtype_id)
    price = a.pricelevel * r.price

    if not form.validate():
        return render_template("bookings/new.html", destination = d, accomodation = a, roomtype = r, price = price, form = form)

    if not (form.email_notification.data or form.phone_notification.data):
        return render_template("bookings/new.html", destination = d, accomodation = a, roomtype = r, price = price, form = form, error = "Choose at least one of the two notification options.")

    x = random.choice(range(1000000, 9999999))
    
    bookings = Booking.booking_number_exists(x)
    while not bookings:
        x = random.choice(range(1000000, 9999999))
        bookings = Booking.booking_number_exists(x)

    r = RoomType.query.get(roomtype_id)
    a = Accomodation.query.get(accomodation_id)
    nights = form.nights.data
    price = a.pricelevel * r.price * nights

    b = Booking(x, price, nights, roomtype_id, accomodation_id)
    b.email_notification = form.email_notification.data
    b.phone_notification = form.phone_notification.data
    b.client_id = current_user.id
    
    db.session().add(b)
    try:
        db.session().commit()
    except:
        db.session().rollback()
        raise
    
    return redirect(url_for("client_my"))
예제 #12
0
def bookings_delete(booking_id):

    Booking.query.filter_by(id=booking_id).delete()
    try:
        db.session().commit()
    except:
        db.session().rollback()
        raise

    return render_template("auth/my.html", client = current_user, approved_bookings = Booking.approved_bookings(current_user.id, True), not_approved_bookings = Booking.approved_bookings(current_user.id, False))
예제 #13
0
def bookings_index():
    return render_template("bookings/list.html", how_many_bookings = Client.how_many_bookings(), all_bookings = Booking.all_bookings(), destinations = Destination.how_many_bookings_all(), accomodations = Accomodation.how_many_bookings_all(), roomtypes = RoomType.how_many_bookings_all())