|
@@ -1,12 +1,39 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
-from django.shortcuts import render
|
|
|
+
|
|
|
+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 .models import Item, Loan
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
+def loan_return(request, pk):
|
|
|
+ loan = Loan.objects.get(pk=pk)
|
|
|
+
|
|
|
+ if not loan.user_can_close(request.user):
|
|
|
+ return HttpResponseForbidden('Non autorisé')
|
|
|
+
|
|
|
+ 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'))
|
|
|
+
|
|
|
+ else:
|
|
|
+ return render(request, 'hardware_provisioning/return.html', {
|
|
|
+ 'loan': loan,
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+@login_required
|
|
|
def loan_list(request):
|
|
|
view = 'old' if 'old' in request.GET else ''
|
|
|
|