From 297e300abe8839307516c76de8722cc33f19358a Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 26 Mar 2018 00:08:24 +0200 Subject: [PATCH] Rename Borne en AccessPoint --- re2o/templatetags/acl.py | 1 + re2o/utils.py | 6 +- re2o/views.py | 2 +- topologie/admin.py | 6 +- topologie/forms.py | 10 +-- .../migrations/0044_auto_20180326_0002.py | 28 +++++++ topologie/models.py | 18 ++-- topologie/templates/topologie/aff_ap.html | 74 +++++++++++++++++ topologie/templates/topologie/aff_borne.html | 74 ----------------- .../{index_borne.html => index_ap.html} | 6 +- topologie/templates/topologie/sidebar.html | 2 +- topologie/urls.py | 10 +-- topologie/views.py | 82 +++++++++---------- 13 files changed, 174 insertions(+), 145 deletions(-) create mode 100644 topologie/migrations/0044_auto_20180326_0002.py create mode 100644 topologie/templates/topologie/aff_ap.html delete mode 100644 topologie/templates/topologie/aff_borne.html rename topologie/templates/topologie/{index_borne.html => index_ap.html} (88%) diff --git a/re2o/templatetags/acl.py b/re2o/templatetags/acl.py index c2d3ba24..d749b299 100644 --- a/re2o/templatetags/acl.py +++ b/re2o/templatetags/acl.py @@ -122,6 +122,7 @@ MODEL_NAME = { # topologie 'Stack' : topologie.models.Stack, 'Switch' : topologie.models.Switch, + 'AccessPoint' : topologie.models.AccessPoint, 'ModelSwitch' : topologie.models.ModelSwitch, 'ConstructorSwitch' : topologie.models.ConstructorSwitch, 'Port' : topologie.models.Port, diff --git a/re2o/utils.py b/re2o/utils.py index d577ba70..a3c1dcb8 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -234,9 +234,9 @@ class SortTable: 'default': ['name'] } TOPOLOGIE_INDEX_BORNE = { - 'borne_name': ['domain__name'], - 'borne_ip': ['ipv4__ipv4'], - 'borne_mac': ['mac_address'], + 'ap_name': ['domain__name'], + 'ap_ip': ['ipv4__ipv4'], + 'ap_mac': ['mac_address'], 'default': ['domain__name'] } TOPOLOGIE_INDEX_STACK = { diff --git a/re2o/views.py b/re2o/views.py index c0fbb8ef..9a987e5a 100644 --- a/re2o/views.py +++ b/re2o/views.py @@ -83,7 +83,7 @@ HISTORY_BIND = { 'stack' : topologie.models.Stack, 'model_switch' : topologie.models.ModelSwitch, 'constructor_switch' : topologie.models.ConstructorSwitch, - 'borne' : topologie.models.Borne, + 'ap' : topologie.models.AccessPoint, }, 'machines' : { 'machine' : machines.models.Machine, diff --git a/topologie/admin.py b/topologie/admin.py index f7021148..6c64aec7 100644 --- a/topologie/admin.py +++ b/topologie/admin.py @@ -36,7 +36,7 @@ from .models import ( Stack, ModelSwitch, ConstructorSwitch, - Borne + AccessPoint ) @@ -55,7 +55,7 @@ class PortAdmin(VersionAdmin): pass -class BorneAdmin(VersionAdmin): +class AccessPointAdmin(VersionAdmin): """Administration d'une borne""" pass @@ -76,7 +76,7 @@ class ConstructorSwitchAdmin(VersionAdmin): admin.site.register(Port, PortAdmin) -admin.site.register(Borne, BorneAdmin) +admin.site.register(AccessPoint, AccessPointAdmin) admin.site.register(Room, RoomAdmin) admin.site.register(Switch, SwitchAdmin) admin.site.register(Stack, StackAdmin) diff --git a/topologie/forms.py b/topologie/forms.py index 6e37bb0c..568ddd74 100644 --- a/topologie/forms.py +++ b/topologie/forms.py @@ -43,7 +43,7 @@ from .models import ( Stack, ModelSwitch, ConstructorSwitch, - Borne + AccessPoint ) @@ -111,18 +111,18 @@ class StackForm(ModelForm): super(StackForm, self).__init__(*args, prefix=prefix, **kwargs) -class AddBorneForm(EditInterfaceForm): +class AddAccessPointForm(EditInterfaceForm): """Formulaire pour la création d'une borne Relié directement au modèle borne""" class Meta: - model = Borne + model = AccessPoint fields = ['mac_address', 'type', 'ipv4', 'details', 'location'] -class EditBorneForm(EditInterfaceForm): +class EditAccessPointForm(EditInterfaceForm): """Edition d'une interface. Edition complète""" class Meta: - model = Borne + model = AccessPoint fields = ['machine', 'type', 'ipv4', 'mac_address', 'details', 'location'] diff --git a/topologie/migrations/0044_auto_20180326_0002.py b/topologie/migrations/0044_auto_20180326_0002.py new file mode 100644 index 00000000..f18b4ed9 --- /dev/null +++ b/topologie/migrations/0044_auto_20180326_0002.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-03-25 22:02 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0043_renamenewswitch'), + ] + + operations = [ + migrations.RenameModel( + old_name='Borne', + new_name='AccessPoint', + ), + migrations.AlterModelOptions( + name='accesspoint', + options={'permissions': (('view_ap', 'Peut voir une borne'),)}, + ), + migrations.AlterModelOptions( + name='switch', + options={'permissions': (('view_switch', 'Peut voir un objet switch'),)}, + ), + ] diff --git a/topologie/models.py b/topologie/models.py index e0891f18..d94c5704 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -109,7 +109,7 @@ class Stack(models.Model): inférieure à l'id minimale"}) -class Borne(Interface): +class AccessPoint(Interface): """Define a wireless AP. Inherit from machines.interfaces Definition pour une borne wifi , hérite de machines.interfaces @@ -125,33 +125,33 @@ class Borne(Interface): class Meta: permissions = ( - ("view_borne", "Peut voir une borne"), + ("view_ap", "Peut voir une borne"), ) - def get_instance(borne_id, *args, **kwargs): - return Borne.objects.get(pk=borne_id) + def get_instance(ap_id, *args, **kwargs): + return AccessPoint.objects.get(pk=ap_id) def can_create(user_request, *args, **kwargs): - return user_request.has_perm('topologie.add_borne') , u"Vous n'avez pas le droit\ + return user_request.has_perm('topologie.add_ap') , u"Vous n'avez pas le droit\ de créer une borne" def can_edit(self, user_request, *args, **kwargs): - if not user_request.has_perm('topologie.change_borne'): + if not user_request.has_perm('topologie.change_ap'): return False, u"Vous n'avez pas le droit d'éditer des bornes" return True, None def can_delete(self, user_request, *args, **kwargs): - if not user_request.has_perm('topologie.delete_borne'): + if not user_request.has_perm('topologie.delete_ap'): return False, u"Vous n'avez pas le droit de supprimer une borne" return True, None def can_view_all(user_request, *args, **kwargs): - if not user_request.has_perm('topologie.view_borne'): + if not user_request.has_perm('topologie.view_ap'): return False, u"Vous n'avez pas le droit de voir les bornes" return True, None def can_view(self, user_request, *args, **kwargs): - if not user_request.has_perm('topologie.view_borne'): + if not user_request.has_perm('topologie.view_ap'): return False, u"Vous n'avez pas le droit de voir les bornes" return True, None diff --git a/topologie/templates/topologie/aff_ap.html b/topologie/templates/topologie/aff_ap.html new file mode 100644 index 00000000..b9130a0d --- /dev/null +++ b/topologie/templates/topologie/aff_ap.html @@ -0,0 +1,74 @@ +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load acl %} + +
+ {% if ap_list.paginator %} + {% include "pagination.html" with list=ap_list %} + {% endif %} + + + + + + + + + + + + + + {% for ap in ap_list %} + + + + + + + + + {% endfor %} +
{% include "buttons/sort.html" with prefix='ap' col='name' text='Borne' %}{% include "buttons/sort.html" with prefix='ap' col='mac' text='Addresse mac' %}{% include "buttons/sort.html" with prefix='ap' col='ip' text='Ipv4' %}CommentaireLocalisation
{{ap}}{{ap.mac_address}}{{ap.ipv4}}{{ap.details}}{{ap.location}} + + + + {% can_edit ap %} + + + + {% acl_end %} + {% can_delete ap %} + + + + {% acl_end %} +
+ + + {% if ap_list.paginator %} +{% include "pagination.html" with list=ap_list %} +{% endif %} +
diff --git a/topologie/templates/topologie/aff_borne.html b/topologie/templates/topologie/aff_borne.html deleted file mode 100644 index 8080aaaf..00000000 --- a/topologie/templates/topologie/aff_borne.html +++ /dev/null @@ -1,74 +0,0 @@ -{% comment %} -Re2o est un logiciel d'administration développé initiallement au rezometz. Il -se veut agnostique au réseau considéré, de manière à être installable en -quelques clics. - -Copyright © 2017 Gabriel Détraz -Copyright © 2017 Goulven Kermarec -Copyright © 2017 Augustin Lemesle - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -{% endcomment %} - -{% load acl %} - -
-{% if borne_list.paginator %} -{% include "pagination.html" with list=borne_list %} -{% endif %} - - - - - - - - - - - - - - {% for borne in borne_list %} - - - - - - - - - {% endfor %} -
{% include "buttons/sort.html" with prefix='borne' col='name' text='Borne' %}{% include "buttons/sort.html" with prefix='borne' col='mac' text='Addresse mac' %}{% include "buttons/sort.html" with prefix='borne' col='ip' text='Ipv4' %}CommentaireLocalisation
{{borne}}{{borne.mac_address}}{{borne.ipv4}}{{borne.details}}{{borne.location}} - - - - {% can_edit borne %} - - - - {% acl_end %} - {% can_delete borne %} - - - - {% acl_end %} -
- - -{% if borne_list.paginator %} -{% include "pagination.html" with list=borne_list %} -{% endif %} -
diff --git a/topologie/templates/topologie/index_borne.html b/topologie/templates/topologie/index_ap.html similarity index 88% rename from topologie/templates/topologie/index_borne.html rename to topologie/templates/topologie/index_ap.html index e6d20dfb..19499998 100644 --- a/topologie/templates/topologie/index_borne.html +++ b/topologie/templates/topologie/index_ap.html @@ -30,11 +30,11 @@ with this program; if not, write to the Free Software Foundation, Inc., {% block content %}

Points d'accès WiFi

-{% can_create Room %} - Ajouter une borne +{% can_create AccessPoint %} + Ajouter une borne
{% acl_end %} - {% include "topologie/aff_borne.html" with borne_list=borne_list %} + {% include "topologie/aff_ap.html" with ap_list=ap_list %}


diff --git a/topologie/templates/topologie/sidebar.html b/topologie/templates/topologie/sidebar.html index 6351ffd0..bdbcf7fc 100644 --- a/topologie/templates/topologie/sidebar.html +++ b/topologie/templates/topologie/sidebar.html @@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., Switchs - + Bornes WiFi diff --git a/topologie/urls.py b/topologie/urls.py index 19b87947..1f2968b7 100644 --- a/topologie/urls.py +++ b/topologie/urls.py @@ -35,11 +35,11 @@ from . import views urlpatterns = [ url(r'^$', views.index, name='index'), - url(r'^index_borne/$', views.index_borne, name='index-borne'), - url(r'^new_borne/$', views.new_borne, name='new-borne'), - url(r'^edit_borne/(?P[0-9]+)$', - views.edit_borne, - name='edit-borne'), + url(r'^index_ap/$', views.index_ap, name='index-ap'), + url(r'^new_ap/$', views.new_ap, name='new-ap'), + url(r'^edit_ap/(?P[0-9]+)$', + views.edit_ap, + name='edit-ap'), url(r'^create_ports/(?P[0-9]+)$', views.create_ports, name='create-ports'), diff --git a/topologie/views.py b/topologie/views.py index 97091a83..6102bb66 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -54,7 +54,7 @@ from topologie.models import ( Stack, ModelSwitch, ConstructorSwitch, - Borne + AccessPoint ) from topologie.forms import EditPortForm, NewSwitchForm, EditSwitchForm from topologie.forms import ( @@ -64,8 +64,8 @@ from topologie.forms import ( EditModelSwitchForm, EditConstructorSwitchForm, CreatePortsForm, - AddBorneForm, - EditBorneForm + AddAccessPointForm, + EditAccessPointForm ) from users.views import form from re2o.utils import SortTable @@ -172,29 +172,29 @@ def index_room(request): @login_required -@can_view_all(Borne) -def index_borne(request): +@can_view_all(AccessPoint) +def index_ap(request): """ Affichage de l'ensemble des bornes""" - borne_list = Borne.objects - borne_list = SortTable.sort( - borne_list, + ap_list = AccessPoint.objects + ap_list = SortTable.sort( + ap_list, request.GET.get('col'), request.GET.get('order'), SortTable.TOPOLOGIE_INDEX_BORNE ) pagination_number = GeneralOption.get_cached_value('pagination_number') - paginator = Paginator(borne_list, pagination_number) + paginator = Paginator(ap_list, pagination_number) page = request.GET.get('page') try: - borne_list = paginator.page(page) + ap_list = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. - borne_list = paginator.page(1) + ap_list = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. - borne_list = paginator.page(paginator.num_pages) - return render(request, 'topologie/index_borne.html', { - 'borne_list': borne_list + ap_list = paginator.page(paginator.num_pages) + return render(request, 'topologie/index_ap.html', { + 'ap_list': ap_list }) @@ -526,12 +526,12 @@ def edit_switch(request, switch, switch_id): @login_required -@can_create(Borne) -def new_borne(request): - """ Creation d'une borne. Cree en meme temps l'interface et la machine +@can_create(AccessPoint) +def new_ap(request): + """ Creation d'une ap. Cree en meme temps l'interface et la machine associée. Vue complexe. Appelle successivement les 3 models forms adaptés : machine, interface, domain et switch""" - borne = AddBorneForm( + ap = AddAccessPointForm( request.POST or None, user=request.user ) @@ -542,7 +542,7 @@ def new_borne(request): domain = DomainForm( request.POST or None, ) - if borne.is_valid() and machine.is_valid(): + if ap.is_valid() and machine.is_valid(): user = AssoOption.get_cached_value('utilisateur_asso') if not user: messages.error(request, "L'user association n'existe pas encore,\ @@ -550,29 +550,29 @@ def new_borne(request): return redirect(reverse('topologie:index')) new_machine = machine.save(commit=False) new_machine.user = user - new_borne = borne.save(commit=False) - domain.instance.interface_parent = new_borne + new_ap = ap.save(commit=False) + domain.instance.interface_parent = new_ap if domain.is_valid(): new_domain_instance = domain.save(commit=False) with transaction.atomic(), reversion.create_revision(): new_machine.save() reversion.set_user(request.user) reversion.set_comment("Création") - new_borne.machine = new_machine + new_ap.machine = new_machine with transaction.atomic(), reversion.create_revision(): - new_borne.save() + new_ap.save() reversion.set_user(request.user) reversion.set_comment("Création") - new_domain_instance.interface_parent = new_borne + new_domain_instance.interface_parent = new_ap with transaction.atomic(), reversion.create_revision(): new_domain_instance.save() reversion.set_user(request.user) reversion.set_comment("Création") messages.success(request, "La borne a été créé") - return redirect(reverse('topologie:index-borne')) - i_mbf_param = generate_ipv4_mbf_param(borne, False) + return redirect(reverse('topologie:index-ap')) + i_mbf_param = generate_ipv4_mbf_param(ap, False) return form({ - 'topoform': borne, + 'topoform': ap, 'machineform': machine, 'domainform': domain, 'i_mbf_param': i_mbf_param, @@ -581,32 +581,32 @@ def new_borne(request): @login_required -@can_edit(Borne) -def edit_borne(request, borne, borne_id): +@can_edit(AccessPoint) +def edit_ap(request, ap, ap_id): """ Edition d'un switch. Permet de chambre nombre de ports, place dans le stack, interface et machine associée""" - borne_form = EditBorneForm( + ap_form = EditAccessPointForm( request.POST or None, user=request.user, - instance=borne + instance=ap ) machine_form = NewMachineForm( request.POST or None, user=request.user, - instance=borne.machine + instance=ap.machine ) domain_form = DomainForm( request.POST or None, - instance=borne.domain + instance=ap.domain ) - if borne_form.is_valid() and machine_form.is_valid(): + if ap_form.is_valid() and machine_form.is_valid(): user = AssoOption.get_cached_value('utilisateur_asso') if not user: messages.error(request, "L'user association n'existe pas encore,\ veuillez le créer ou le linker dans preferences") - return redirect(reverse('topologie:index-borne')) + return redirect(reverse('topologie:index-ap')) new_machine = machine_form.save(commit=False) - new_borne = borne_form.save(commit=False) + new_ap = ap_form.save(commit=False) new_domain = domain_form.save(commit=False) with transaction.atomic(), reversion.create_revision(): new_machine.save() @@ -616,10 +616,10 @@ def edit_borne(request, borne, borne_id): field for field in machine_form.changed_data) ) with transaction.atomic(), reversion.create_revision(): - new_borne.save() + new_ap.save() reversion.set_user(request.user) reversion.set_comment("Champs modifié(s) : %s" % ', '.join( - field for field in borne_form.changed_data) + field for field in ap_form.changed_data) ) reversion.set_comment("Création") with transaction.atomic(), reversion.create_revision(): @@ -629,10 +629,10 @@ def edit_borne(request, borne, borne_id): field for field in domain_form.changed_data) ) messages.success(request, "La borne a été modifiée") - return redirect(reverse('topologie:index-borne')) - i_mbf_param = generate_ipv4_mbf_param(borne_form, False ) + return redirect(reverse('topologie:index-ap')) + i_mbf_param = generate_ipv4_mbf_param(ap_form, False ) return form({ - 'topoform': borne_form, + 'topoform': ap_form, 'machineform': machine_form, 'domainform': domain_form, 'i_mbf_param': i_mbf_param,