예제 #1
0
def BookingSubmit(request, location_slug):
    if not request.method == "POST":
        return HttpResponseRedirect("/404")

    location = get_object_or_404(Location, slug=location_slug)

    form = BookingUseForm(location, request.POST)
    if form.is_valid():
        comments = request.POST.get('comments')
        use = form.save(commit=False)
        use.location = location
        booking = Booking(use=use, comments=comments)
        # reset_rate also generates the bill.
        if request.user.is_authenticated():
            use.user = request.user
            if use.suggest_drft():
                use.accounted_by = Use.DRFT
            use.save()
            # we already set the value of 'use' when creating the Booking,
            # but it wasn't saved at that point, and Django complains about
            # a missing primary key here otherwise, so re-setting.
            booking.use = use
            booking.save()
            booking.reset_rate()
            new_booking_notify(booking)
            messages.add_message(
                request, messages.INFO,
                'Thanks! Your booking was submitted. You will receive an email when it has been reviewed. You may wish to <a href="/people/%s/edit/">update your profile</a> if your projects or ideas have changed since your last visit.'
                % booking.use.user.username)
            return HttpResponseRedirect(
                reverse('booking_detail', args=(location_slug, booking.id)))
        else:
            booking_data = booking.serialize()
            request.session['booking'] = booking_data
            messages.add_message(
                request, messages.INFO,
                'Thank you! Please make a profile to complete your booking request.'
            )
            return HttpResponseRedirect(reverse('registration_register'))
    else:
        logger.debug('form was not valid')
        logger.debug(request.POST)
        logger.debug(form.errors)
        raise Exception(str(form.errors.as_data()))
예제 #2
0
def BookingSubmit(request, location_slug):
    if not request.method == "POST":
        return HttpResponseRedirect("/404")

    location = get_object_or_404(Location, slug=location_slug)

    form = BookingUseForm(location, request.POST)
    if form.is_valid():
        comments = request.POST.get('comments')
        use = form.save(commit=False)
        use.location = location
        booking = Booking(use=use, comments=comments)
        # reset_rate also generates the bill.
        if request.user.is_authenticated():
            use.user = request.user
            if use.suggest_drft():
                use.accounted_by = Use.DRFT
            use.save()
            # we already set the value of 'use' when creating the Booking,
            # but it wasn't saved at that point, and Django complains about
            # a missing primary key here otherwise, so re-setting.
            booking.use = use
            booking.save()
            booking.reset_rate()
            new_booking_notify(booking)
            messages.add_message(
                request,
                messages.INFO,
                'Thanks! Your booking was submitted. You will receive an email when it has been reviewed. You may wish to <a href="/people/%s/edit/">update your profile</a> if your projects or ideas have changed since your last visit.' % booking.use.user.username
            )
            return HttpResponseRedirect(reverse('booking_detail', args=(location_slug, booking.id)))
        else:
            booking_data = booking.serialize()
            request.session['booking'] = booking_data
            messages.add_message(request, messages.INFO, 'Thank you! Please make a profile to complete your booking request.')
            return HttpResponseRedirect(reverse('registration_register'))
    else:
        print 'form was not valid'
        logger.debug(request.POST)
        logger.debug(form.errors)
        raise Exception(str(form.errors.as_data()))
예제 #3
0
def BookingEdit(request, booking_id, location_slug):
    logger.debug("Entering BookingEdit")

    location = get_object_or_404(Location, slug=location_slug)
    booking = Booking.objects.get(id=booking_id)
    # need to pull these dates out before we pass the instance into
    # the BookingUseForm, since it (apparently) updates the instance
    # immediately (which is weird, since it hasn't validated the form
    # yet!)
    original_arrive = booking.use.arrive
    original_depart = booking.use.depart
    original_room = booking.use.resource
    if request.user.is_authenticated() and request.user == booking.use.user:
        logger.debug("BookingEdit: Authenticated and same user")
        if request.user in booking.use.location.house_admins.all():
            is_house_admin = True
        else:
            is_house_admin = False

        if request.method == "POST":
            logger.debug("BookingEdit: POST")
            form = BookingUseForm(location, request.POST, instance=booking.use)
            if form.is_valid():
                logger.debug("BookingEdit: Valid Form")
                comments = request.POST.get('comments')
                print 'comments?'
                print comments
                booking.comments = comments
                booking.generate_bill()
                booking.save()
                form.save()
                if (
                    not booking.is_pending() and
                    (
                        booking.use.arrive != original_arrive or
                        booking.use.depart != original_depart or
                        booking.use.resource != original_room
                    )
                ):
                    logger.debug("booking room or date was changed. updating status.")
                    booking.pending()
                    # notify house_admins by email
                    try:
                        updated_booking_notify(booking)
                    except:
                        logger.debug("Booking %d was updated but admin notification failed to send" % booking.id)
                    client_msg = 'The booking was updated and the new information will be reviewed for availability.'
                else:
                    client_msg = 'The booking was updated.'
                # save the instance *after* the status has been updated as needed.
                messages.add_message(request, messages.INFO, client_msg)
                return HttpResponseRedirect(reverse("booking_detail", args=(location.slug, booking_id)))
        else:
            # form = get_booking_form_for_perms(request, post=False, instance=booking)
            form = BookingUseForm(location, instance=booking.use)

        return render(
            request,
            'booking_edit.html',
            {
                'form': form,
                'booking_id': booking_id,
                'arrive': booking.use.arrive,
                'depart': booking.use.depart,
                'is_house_admin': is_house_admin,
                'max_days': location.max_booking_days,
                'location': location
            }
        )
    else:
        return HttpResponseRedirect("/")
예제 #4
0
def BookingEdit(request, booking_id, location_slug):
    logger.debug("Entering BookingEdit")

    location = get_object_or_404(Location, slug=location_slug)
    booking = Booking.objects.get(id=booking_id)
    # need to pull these dates out before we pass the instance into
    # the BookingUseForm, since it (apparently) updates the instance
    # immediately (which is weird, since it hasn't validated the form
    # yet!)
    original_arrive = booking.use.arrive
    original_depart = booking.use.depart
    original_room = booking.use.resource
    if request.user.is_authenticated() and request.user == booking.use.user:
        logger.debug("BookingEdit: Authenticated and same user")
        if request.user in booking.use.location.house_admins.all():
            is_house_admin = True
        else:
            is_house_admin = False

        if request.method == "POST":
            logger.debug("BookingEdit: POST")
            form = BookingUseForm(location, request.POST, instance=booking.use)
            if form.is_valid():
                logger.debug("BookingEdit: Valid Form")
                comments = request.POST.get('comments')
                logger.debug('comments?')
                logger.debug(comments)
                booking.comments = comments
                booking.generate_bill()
                booking.save()
                form.save()
                if (not booking.is_pending()
                        and (booking.use.arrive != original_arrive
                             or booking.use.depart != original_depart
                             or booking.use.resource != original_room)):
                    logger.debug(
                        "booking room or date was changed. updating status.")
                    booking.pending()
                    # notify house_admins by email
                    try:
                        updated_booking_notify(booking)
                    except:
                        logger.debug(
                            "Booking %d was updated but admin notification failed to send"
                            % booking.id)
                    client_msg = 'The booking was updated and the new information will be reviewed for availability.'
                else:
                    client_msg = 'The booking was updated.'
                # save the instance *after* the status has been updated as needed.
                messages.add_message(request, messages.INFO, client_msg)
                return HttpResponseRedirect(
                    reverse("booking_detail",
                            args=(location.slug, booking_id)))
        else:
            # form = get_booking_form_for_perms(request, post=False, instance=booking)
            form = BookingUseForm(location, instance=booking.use)

        return render(
            request, 'booking_edit.html', {
                'form': form,
                'booking_id': booking_id,
                'arrive': booking.use.arrive,
                'depart': booking.use.depart,
                'is_house_admin': is_house_admin,
                'max_days': location.max_booking_days,
                'location': location
            })
    else:
        return HttpResponseRedirect("/")