From 8f0b04df9e4af093dde0eb3a6d43f7dc8e20ca41 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 9 Jul 2016 14:59:05 +0200 Subject: [PATCH] =?UTF-8?q?Controle=20is=5Fadmin=20pour=20g=C3=A9rer=20les?= =?UTF-8?q?=20machines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/templates/machines/aff_extension.html | 2 +- machines/templates/machines/aff_machinetype.html | 2 +- machines/templates/machines/index_extension.html | 2 ++ machines/templates/machines/index_machinetype.html | 2 ++ machines/views.py | 14 +++++++++++--- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/machines/templates/machines/aff_extension.html b/machines/templates/machines/aff_extension.html index b00972a3..5a96efb5 100644 --- a/machines/templates/machines/aff_extension.html +++ b/machines/templates/machines/aff_extension.html @@ -8,7 +8,7 @@ {% for extension in extension_list %} {{ extension.name }} - Editer + {% if is_admin %} Editer{% endif %} {% endfor %} diff --git a/machines/templates/machines/aff_machinetype.html b/machines/templates/machines/aff_machinetype.html index d951b329..9103a970 100644 --- a/machines/templates/machines/aff_machinetype.html +++ b/machines/templates/machines/aff_machinetype.html @@ -10,7 +10,7 @@ {{ type.type }} {{ type.extension }} - Editer + {% if is_admin %} Editer{% endif %} {% endfor %} diff --git a/machines/templates/machines/index_extension.html b/machines/templates/machines/index_extension.html index 1c867e26..646fb7b8 100644 --- a/machines/templates/machines/index_extension.html +++ b/machines/templates/machines/index_extension.html @@ -5,8 +5,10 @@ {% block content %}

Liste des extensions

+ {% if is_admin %} Ajouter une extension Supprimer une ou plusieurs extensions + {% endif %} {% include "machines/aff_extension.html" with extension_list=extension_list %}

diff --git a/machines/templates/machines/index_machinetype.html b/machines/templates/machines/index_machinetype.html index 22e8824a..0b0c4554 100644 --- a/machines/templates/machines/index_machinetype.html +++ b/machines/templates/machines/index_machinetype.html @@ -5,8 +5,10 @@ {% block content %}

Liste des types de machines

+ {% if is_admin %} Ajouter un type de machine Supprimer un ou plusieurs types de machines + {% endif %} {% include "machines/aff_machinetype.html" with machinetype_list=machinetype_list %}

diff --git a/machines/views.py b/machines/views.py index dbfc217b..5d7c3e6c 100644 --- a/machines/views.py +++ b/machines/views.py @@ -6,7 +6,7 @@ from django.shortcuts import render_to_response, get_object_or_404 from django.core.context_processors import csrf from django.template import Context, RequestContext, loader from django.contrib import messages -from django.contrib.auth.decorators import login_required +from django.contrib.auth.decorators import login_required, permission_required from django.db.models import ProtectedError from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, NewInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm @@ -111,6 +111,7 @@ def new_interface(request, machineid): return form({'machineform': machine_form, 'interfaceform': interface_form}, 'machines/machine.html', request) @login_required +@permission_required('admin') def add_machinetype(request): machinetype = MachineTypeForm(request.POST or None) if machinetype.is_valid(): @@ -120,6 +121,7 @@ def add_machinetype(request): return form({'machineform': machinetype, 'interfaceform': None}, 'machines/machine.html', request) @login_required +@permission_required('admin') def edit_machinetype(request, machinetypeid): try: machinetype_instance = MachineType.objects.get(pk=machinetypeid) @@ -134,6 +136,7 @@ def edit_machinetype(request, machinetypeid): return form({'machineform': machinetype}, 'machines/machine.html', request) @login_required +@permission_required('admin') def del_machinetype(request): machinetype = DelMachineTypeForm(request.POST or None) if machinetype.is_valid(): @@ -148,6 +151,7 @@ def del_machinetype(request): return form({'machineform': machinetype, 'interfaceform': None}, 'machines/machine.html', request) @login_required +@permission_required('admin') def add_extension(request): extension = ExtensionForm(request.POST or None) if extension.is_valid(): @@ -157,6 +161,7 @@ def add_extension(request): return form({'machineform': extension, 'interfaceform': None}, 'machines/machine.html', request) @login_required +@permission_required('admin') def edit_extension(request, extensionid): try: extension_instance = Extension.objects.get(pk=extensionid) @@ -171,6 +176,7 @@ def edit_extension(request, extensionid): return form({'machineform': extension}, 'machines/machine.html', request) @login_required +@permission_required('admin') def del_extension(request): extension = DelExtensionForm(request.POST or None) if extension.is_valid(): @@ -191,10 +197,12 @@ def index(request): @login_required def index_machinetype(request): + is_admin = request.user.has_perms(('admin',)) machinetype_list = MachineType.objects.order_by('type') - return render(request, 'machines/index_machinetype.html', {'machinetype_list':machinetype_list}) + return render(request, 'machines/index_machinetype.html', {'machinetype_list':machinetype_list, 'is_admin':is_admin}) @login_required def index_extension(request): + is_admin = request.user.has_perms(('admin',)) extension_list = Extension.objects.order_by('name') - return render(request, 'machines/index_extension.html', {'extension_list':extension_list}) + return render(request, 'machines/index_extension.html', {'extension_list':extension_list, 'is_admin':is_admin})