|
@@ -10,29 +10,33 @@ from django.contrib import messages
|
|
from django.http import HttpResponseForbidden
|
|
from django.http import HttpResponseForbidden
|
|
from django.core.urlresolvers import reverse
|
|
from django.core.urlresolvers import reverse
|
|
|
|
|
|
-from .forms import LoanTransferForm
|
|
|
|
|
|
+from .forms import LoanTransferForm, LoanReturnForm
|
|
from .models import Item, Loan
|
|
from .models import Item, Loan
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
@login_required
|
|
def loan_return(request, pk):
|
|
def loan_return(request, pk):
|
|
- loan = Loan.objects.get(pk=pk)
|
|
|
|
|
|
+ loan = get_object_or_404(Loan, pk=pk)
|
|
|
|
|
|
if not loan.user_can_close(request.user):
|
|
if not loan.user_can_close(request.user):
|
|
return HttpResponseForbidden('Non autorisé')
|
|
return HttpResponseForbidden('Non autorisé')
|
|
|
|
|
|
if request.method == 'POST':
|
|
if request.method == 'POST':
|
|
- messages.success(
|
|
|
|
- request,
|
|
|
|
- 'Le matériel {} a été marqué comme rendu'.format(
|
|
|
|
- loan.item))
|
|
|
|
- loan.item.give_back()
|
|
|
|
- return redirect(reverse('hardware_provisioning:loan-list'))
|
|
|
|
-
|
|
|
|
|
|
+ form = LoanReturnForm(request.POST)
|
|
|
|
+ if form.is_valid():
|
|
|
|
+ messages.success(
|
|
|
|
+ request,
|
|
|
|
+ 'Le matériel {} a été marqué comme rendu'.format(
|
|
|
|
+ loan.item))
|
|
|
|
+ loan.item.give_back(form.cleaned_data['storage'])
|
|
|
|
+ return redirect(reverse('hardware_provisioning:loan-list'))
|
|
else:
|
|
else:
|
|
- return render(request, 'hardware_provisioning/return.html', {
|
|
|
|
- 'loan': loan,
|
|
|
|
- })
|
|
|
|
|
|
+ form = LoanReturnForm()
|
|
|
|
+
|
|
|
|
+ return render(request, 'hardware_provisioning/return.html', {
|
|
|
|
+ 'loan': loan,
|
|
|
|
+ 'form': form,
|
|
|
|
+ })
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
@login_required
|