8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 19:33:11 +00:00

Controle is_admin pour gérer les machines

This commit is contained in:
chirac 2016-07-09 14:59:05 +02:00
parent ee324af6fa
commit d6150c7e68
5 changed files with 17 additions and 5 deletions

View file

@ -8,7 +8,7 @@
{% for extension in extension_list %} {% for extension in extension_list %}
<tr> <tr>
<td>{{ extension.name }}</td> <td>{{ extension.name }}</td>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:edit-extension' extension.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a></td> <td>{% if is_admin %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:edit-extension' extension.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>{% endif %}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View file

@ -10,7 +10,7 @@
<tr> <tr>
<td>{{ type.type }}</td> <td>{{ type.type }}</td>
<td>{{ type.extension }}</td> <td>{{ type.extension }}</td>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:edit-machinetype' type.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a></td> <td>{% if is_admin %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:edit-machinetype' type.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>{% endif %}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View file

@ -5,8 +5,10 @@
{% block content %} {% block content %}
<h2>Liste des extensions</h2> <h2>Liste des extensions</h2>
{% if is_admin %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-extension' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter une extension</a> <a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-extension' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter une extension</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:del-extension' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer une ou plusieurs extensions</a> <a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:del-extension' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer une ou plusieurs extensions</a>
{% endif %}
{% include "machines/aff_extension.html" with extension_list=extension_list %} {% include "machines/aff_extension.html" with extension_list=extension_list %}
<br /> <br />
<br /> <br />

View file

@ -5,8 +5,10 @@
{% block content %} {% block content %}
<h2>Liste des types de machines</h2> <h2>Liste des types de machines</h2>
{% if is_admin %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-machinetype' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un type de machine</a> <a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-machinetype' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un type de machine</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:del-machinetype' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types de machines</a> <a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:del-machinetype' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types de machines</a>
{% endif %}
{% include "machines/aff_machinetype.html" with machinetype_list=machinetype_list %} {% include "machines/aff_machinetype.html" with machinetype_list=machinetype_list %}
<br /> <br />
<br /> <br />

View file

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