|
@@ -2,13 +2,15 @@
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
+import datetime
|
|
|
+
|
|
|
from django.shortcuts import render, redirect
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
from django.contrib import messages
|
|
|
from django.http import HttpResponseForbidden
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
|
|
-
|
|
|
+from .forms import LoanTransferForm
|
|
|
from .models import Item, Loan
|
|
|
|
|
|
|
|
@@ -34,6 +36,39 @@ def loan_return(request, pk):
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
+def loan_transfer(request, pk):
|
|
|
+ """ Transfer something loaned to another member
|
|
|
+ """
|
|
|
+ old_loan = get_object_or_404(Loan, pk=pk)
|
|
|
+
|
|
|
+ if not old_loan.user_can_close(request.user):
|
|
|
+ return HttpResponseForbidden()
|
|
|
+
|
|
|
+ if request.method == 'POST':
|
|
|
+ form = LoanTransferForm(request.POST)
|
|
|
+ if form.is_valid():
|
|
|
+ old_loan.item.give_back()
|
|
|
+ Loan.objects.create(
|
|
|
+ user=form.cleaned_data['target_user'],
|
|
|
+ loan_date=datetime.date.today(),
|
|
|
+ item=old_loan.item)
|
|
|
+ messages.success(
|
|
|
+ request,
|
|
|
+ "Le matériel {} a été transféré à l'adhérent \"{}\"".format(
|
|
|
+ old_loan.item,
|
|
|
+ form.data['target_user']))
|
|
|
+ return redirect(reverse('hardware_provisioning:loan-list'))
|
|
|
+
|
|
|
+ else:
|
|
|
+ form = LoanTransferForm()
|
|
|
+
|
|
|
+ return render(request, 'hardware_provisioning/transfer.html', {
|
|
|
+ 'form': form,
|
|
|
+ 'loan': old_loan,
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+@login_required
|
|
|
def loan_list(request):
|
|
|
view = 'old' if 'old' in request.GET else ''
|
|
|
|