def reservation_edit(request, schedule_id, id): """ Display the details related to a reservation and also process edits. """ schedule = get_object_or_404(Schedule, pk=schedule_id) reservation = get_object_or_404(Reservation, pk=id) if request.method == 'POST': form = ReservationForm( request.POST, instance=reservation, ) if form.is_valid(): form.save() request.user.message_set.create( message="Your reservation was updated.") return HttpResponseRedirect( reverse('resources_reservation_edit', args=[schedule.id, reservation.id])) else: form = ReservationForm(instance=reservation) return render_to_response('resources/reservation_edit.html', { 'reservation': reservation, 'form': form, 'schedule': schedule, }, context_instance=RequestContext(request))
def reservation_edit(request, schedule_id, id): """ Display the details related to a reservation and also process edits. """ schedule = get_object_or_404(Schedule, pk=schedule_id) reservation = get_object_or_404(Reservation, pk=id) if request.method == 'POST': form = ReservationForm(request.POST, instance=reservation,) if form.is_valid(): form.save() request.user.message_set.create( message="Your reservation was updated.") return HttpResponseRedirect( reverse('resources_reservation_edit', args=[schedule.id, reservation.id] )) else: form = ReservationForm( instance=reservation ) return render_to_response( 'resources/reservation_edit.html', { 'reservation': reservation, 'form': form, 'schedule': schedule,}, context_instance=RequestContext(request))
def reservation_add(request, schedule_id, resource_id): """ Take a resource id and create a reservation object. """ resource = get_object_or_404(Resource, pk=resource_id) schedule = get_object_or_404(Schedule, pk=schedule_id) start_date = request.GET.get('start_date', None) end_date = request.GET.get('start_date', None) profile = request.user.get_profile() if not resource.is_available(): raise Http403, "Sorry, this resource is currently not available for checkout." if request.method == 'POST': form = ReservationForm(request.POST) if form.is_valid(): reservation = form.save(commit=False) reservation.start_when = form.cleaned_data['start_when'] reservation.end_when = form.cleaned_data['end_when'] reservation.profile = profile reservation.resource = resource reservation.save() request.user.message_set.create( message="Your reservation was saved.") # redirect to the schedule detail on the right start date return HttpResponseRedirect( reverse('resources_reservation_edit', args=[schedule.id, reservation.id])) else: # Process GET request form = ReservationForm( initial={ 'start_date': start_date, 'end_date': end_date, 'schedule': schedule.id, 'resource': resource.id, }) return render_to_response('resources/reservation_add.html', locals(), context_instance=RequestContext(request))
def reservation_add(request, schedule_id, resource_id): """ Take a resource id and create a reservation object. """ resource = get_object_or_404(Resource, pk=resource_id) schedule = get_object_or_404(Schedule, pk=schedule_id) start_date = request.GET.get('start_date', None) end_date = request.GET.get('start_date', None) profile = request.user.get_profile() if not resource.is_available(): raise Http403, "Sorry, this resource is currently not available for checkout." if request.method == 'POST': form = ReservationForm(request.POST) if form.is_valid(): reservation = form.save(commit=False) reservation.start_when = form.cleaned_data['start_when'] reservation.end_when = form.cleaned_data['end_when'] reservation.profile = profile reservation.resource = resource reservation.save() request.user.message_set.create(message="Your reservation was saved.") # redirect to the schedule detail on the right start date return HttpResponseRedirect( reverse('resources_reservation_edit', args=[schedule.id, reservation.id] )) else: # Process GET request form = ReservationForm( initial={'start_date':start_date, 'end_date':end_date, 'schedule':schedule.id, 'resource':resource.id, }) return render_to_response( 'resources/reservation_add.html', locals(), context_instance=RequestContext(request))