From bbc00fdb0bda13d26bca15fa4527f7312aa0cf4c Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 11 Sep 2017 01:29:24 +0200 Subject: [PATCH] =?UTF-8?q?Ajoute=20unicode=20literals=20+=20attribue=20le?= =?UTF-8?q?s=20ip=20=C3=A0=20l'enregistrement=20auto=20en=20fonction=20du?= =?UTF-8?q?=20nas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cotisations/admin.py | 2 ++ cotisations/forms.py | 2 ++ cotisations/models.py | 2 ++ cotisations/urls.py | 2 ++ cotisations/views.py | 2 ++ freeradius_utils/auth.py | 7 +++++-- logs/admin.py | 2 ++ logs/models.py | 2 ++ logs/urls.py | 2 ++ logs/views.py | 3 +++ machines/admin.py | 2 ++ machines/forms.py | 2 ++ machines/models.py | 2 ++ machines/urls.py | 2 ++ machines/views.py | 3 +++ preferences/admin.py | 2 ++ preferences/forms.py | 2 ++ preferences/models.py | 1 + preferences/urls.py | 2 ++ preferences/views.py | 1 + re2o/context_processors.py | 2 ++ re2o/settings.py | 2 ++ re2o/settings_local.example.py | 2 ++ re2o/urls.py | 2 ++ re2o/views.py | 2 ++ re2o/wsgi.py | 2 ++ search/admin.py | 2 ++ search/forms.py | 2 ++ search/models.py | 2 ++ search/urls.py | 2 ++ search/views.py | 3 +++ topologie/admin.py | 1 + topologie/forms.py | 2 ++ topologie/models.py | 2 ++ topologie/urls.py | 2 ++ topologie/views.py | 2 ++ users/admin.py | 2 ++ users/forms.py | 1 + users/models.py | 16 +++++++++++----- users/urls.py | 2 ++ users/views.py | 3 +++ 41 files changed, 94 insertions(+), 7 deletions(-) diff --git a/cotisations/admin.py b/cotisations/admin.py index f5954561..29e3285d 100644 --- a/cotisations/admin.py +++ b/cotisations/admin.py @@ -21,6 +21,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.contrib import admin from reversion.admin import VersionAdmin diff --git a/cotisations/forms.py b/cotisations/forms.py index f8b8afba..90c9e826 100644 --- a/cotisations/forms.py +++ b/cotisations/forms.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django import forms from django.forms import ModelForm, Form from django import forms diff --git a/cotisations/models.py b/cotisations/models.py index 9778a2d1..bcb0c744 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -21,6 +21,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.db import models from django.db.models.signals import post_save, post_delete diff --git a/cotisations/urls.py b/cotisations/urls.py index 5717b34f..2cf86888 100644 --- a/cotisations/urls.py +++ b/cotisations/urls.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.conf.urls import url from . import views diff --git a/cotisations/views.py b/cotisations/views.py index 07dd6f68..1e64e9e7 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -23,6 +23,8 @@ # App de gestion des users pour re2o # Goulven Kermarec, Gabriel Détraz # Gplv2 +from __future__ import unicode_literals + from django.shortcuts import render, redirect from django.shortcuts import get_object_or_404 from django.template.context_processors import csrf diff --git a/freeradius_utils/auth.py b/freeradius_utils/auth.py index 90eae257..a9443e95 100644 --- a/freeradius_utils/auth.py +++ b/freeradius_utils/auth.py @@ -32,6 +32,8 @@ Inspirés d'autres exemples trouvés ici : https://github.com/FreeRADIUS/freeradius-server/blob/master/src/modules/rlm_python/ """ +from __future__ import unicode_literals + import logging import netaddr import radiusd # Module magique freeradius (radiusd.py is dummy) @@ -238,8 +240,9 @@ def detach(_=None): def decide_vlan_and_register_macauth(switch_id, port_number, mac_address): # Get port from switch and port number - switch = Switch.objects.filter(switch_interface=Interface.objects.filter(Q(ipv4=IpList.objects.filter(ipv4=switch_id)) | Q(domain=Domain.objects.filter(name=switch_id)))) - if not switch: + ipv4 = IpList.objects.filter(ipv4=switch_id) + switch = Switch.objects.filter(switch_interface=Interface.objects.filter(Q(ipv4=ipv4) | Q(domain=Domain.objects.filter(name=switch_id)))) + if not switch or not ipv4: return ('?', 'Switch inconnu', VLAN_OK) sw_name = str(switch.first().switch_interface) diff --git a/logs/admin.py b/logs/admin.py index 5b3e9c9d..bcdc4f1d 100644 --- a/logs/admin.py +++ b/logs/admin.py @@ -21,6 +21,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.contrib import admin # Register your models here. diff --git a/logs/models.py b/logs/models.py index c545ba5e..934704ba 100644 --- a/logs/models.py +++ b/logs/models.py @@ -21,6 +21,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.db import models # Create your models here. diff --git a/logs/urls.py b/logs/urls.py index 832288e0..348765d8 100644 --- a/logs/urls.py +++ b/logs/urls.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.conf.urls import url from . import views diff --git a/logs/views.py b/logs/views.py index b20f1b5f..d9bcf9b5 100644 --- a/logs/views.py +++ b/logs/views.py @@ -23,6 +23,9 @@ # App de gestion des statistiques pour re2o # Gabriel Détraz # Gplv2 + +from __future__ import unicode_literals + from django.http import HttpResponse from django.shortcuts import render, redirect from django.shortcuts import get_object_or_404 diff --git a/machines/admin.py b/machines/admin.py index 10d1b520..5fe4c49b 100644 --- a/machines/admin.py +++ b/machines/admin.py @@ -21,6 +21,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.contrib import admin from reversion.admin import VersionAdmin diff --git a/machines/forms.py b/machines/forms.py index f0091c59..c72026fe 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.forms import ModelForm, Form, ValidationError from django import forms from .models import Domain, Machine, Interface, IpList, MachineType, Extension, Mx, Text, Ns, Service, Vlan, Nas, IpType diff --git a/machines/models.py b/machines/models.py index 833c231f..769cd237 100644 --- a/machines/models.py +++ b/machines/models.py @@ -21,6 +21,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.db import models from django.db.models.signals import post_save, pre_delete, post_delete from django.dispatch import receiver diff --git a/machines/urls.py b/machines/urls.py index 3801b449..cdf3d5fb 100644 --- a/machines/urls.py +++ b/machines/urls.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.conf.urls import url from . import views diff --git a/machines/views.py b/machines/views.py index d70523da..4268519b 100644 --- a/machines/views.py +++ b/machines/views.py @@ -23,6 +23,9 @@ # App de gestion des machines pour re2o # Gabriel Détraz, Augustin Lemesle # Gplv2 + +from __future__ import unicode_literals + from django.http import HttpResponse from django.shortcuts import render, redirect from django.shortcuts import get_object_or_404 diff --git a/preferences/admin.py b/preferences/admin.py index f3c8bf6a..a8ce9335 100644 --- a/preferences/admin.py +++ b/preferences/admin.py @@ -21,6 +21,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.contrib import admin from reversion.admin import VersionAdmin diff --git a/preferences/forms.py b/preferences/forms.py index ca2df893..20c7ca95 100644 --- a/preferences/forms.py +++ b/preferences/forms.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.forms import ModelForm, Form, ValidationError from django import forms from .models import OptionalUser, OptionalMachine, OptionalTopologie, GeneralOption, AssoOption, MailMessageOption, Service diff --git a/preferences/models.py b/preferences/models.py index b2843310..2c6be69e 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -21,6 +21,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals from django.db import models from cotisations.models import Paiement diff --git a/preferences/urls.py b/preferences/urls.py index 624971d8..624d2e75 100644 --- a/preferences/urls.py +++ b/preferences/urls.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.conf.urls import url from . import views diff --git a/preferences/views.py b/preferences/views.py index 66ecd101..5fe1cff5 100644 --- a/preferences/views.py +++ b/preferences/views.py @@ -24,6 +24,7 @@ # Gabriel Détraz, Augustin Lemesle # Gplv2 +from __future__ import unicode_literals from django.shortcuts import render from django.shortcuts import get_object_or_404, render, redirect diff --git a/re2o/context_processors.py b/re2o/context_processors.py index 0fb8b22b..dd39b04b 100644 --- a/re2o/context_processors.py +++ b/re2o/context_processors.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from machines.models import Interface, Machine from preferences.models import GeneralOption diff --git a/re2o/settings.py b/re2o/settings.py index 1502b0ef..c3560eac 100644 --- a/re2o/settings.py +++ b/re2o/settings.py @@ -33,6 +33,8 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.8/ref/settings/ """ +from __future__ import unicode_literals + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os from .settings_local import * diff --git a/re2o/settings_local.example.py b/re2o/settings_local.example.py index 6c2ea863..ef1797cf 100644 --- a/re2o/settings_local.example.py +++ b/re2o/settings_local.example.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + SECRET_KEY = 'SUPER_SECRET_KEY' DB_PASSWORD = 'SUPER_SECRET_DB' diff --git a/re2o/urls.py b/re2o/urls.py index 74e3640c..5fd45f85 100644 --- a/re2o/urls.py +++ b/re2o/urls.py @@ -34,6 +34,8 @@ Class-based views Including another URLconf 1. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ +from __future__ import unicode_literals + from django.conf.urls import include, url from django.contrib import admin from django.contrib.auth import views as auth_views diff --git a/re2o/views.py b/re2o/views.py index df975634..bd8077e1 100644 --- a/re2o/views.py +++ b/re2o/views.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.shortcuts import render from django.shortcuts import get_object_or_404 from django.template.context_processors import csrf diff --git a/re2o/wsgi.py b/re2o/wsgi.py index 2e9d3ab4..70108566 100644 --- a/re2o/wsgi.py +++ b/re2o/wsgi.py @@ -29,6 +29,8 @@ For more information on this file, see https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ """ +from __future__ import unicode_literals + import os from django.core.wsgi import get_wsgi_application from os.path import dirname diff --git a/search/admin.py b/search/admin.py index 5b3e9c9d..bcdc4f1d 100644 --- a/search/admin.py +++ b/search/admin.py @@ -21,6 +21,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.contrib import admin # Register your models here. diff --git a/search/forms.py b/search/forms.py index 3f53f707..fa43be55 100644 --- a/search/forms.py +++ b/search/forms.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.db.models import Q from simple_search import BaseSearchForm diff --git a/search/models.py b/search/models.py index 23f3607a..8d1fa0e4 100644 --- a/search/models.py +++ b/search/models.py @@ -21,6 +21,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.db import models from django import forms from django.forms import Form diff --git a/search/urls.py b/search/urls.py index bee07853..3b16fcd1 100644 --- a/search/urls.py +++ b/search/urls.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.conf.urls import url from . import views diff --git a/search/views.py b/search/views.py index 5610dbcd..fa9a43e8 100644 --- a/search/views.py +++ b/search/views.py @@ -23,6 +23,9 @@ # App de recherche pour re2o # Augustin lemesle, Gabriel Détraz, Goulven Kermarec # Gplv2 + +from __future__ import unicode_literals + from django.shortcuts import render from django.shortcuts import get_object_or_404 from django.template.context_processors import csrf diff --git a/topologie/admin.py b/topologie/admin.py index a0ef25b8..d1657330 100644 --- a/topologie/admin.py +++ b/topologie/admin.py @@ -21,6 +21,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals from django.contrib import admin from reversion.admin import VersionAdmin diff --git a/topologie/forms.py b/topologie/forms.py index c2227e5d..1f826809 100644 --- a/topologie/forms.py +++ b/topologie/forms.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from .models import Port, Switch, Room, Stack from django.forms import ModelForm, Form from machines.models import Interface diff --git a/topologie/models.py b/topologie/models.py index e2dc0b33..0aafa24e 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -21,6 +21,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.db import models from django.db.models.signals import post_delete from django.dispatch import receiver diff --git a/topologie/urls.py b/topologie/urls.py index 3c3ed49a..f4537ac5 100644 --- a/topologie/urls.py +++ b/topologie/urls.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.conf.urls import url from . import views diff --git a/topologie/views.py b/topologie/views.py index 37188df0..4e453d7c 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.shortcuts import render, redirect from django.contrib import messages from django.contrib.auth.decorators import login_required, permission_required diff --git a/users/admin.py b/users/admin.py index a5e423a3..6a1e0e74 100644 --- a/users/admin.py +++ b/users/admin.py @@ -21,6 +21,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.contrib import admin from django.contrib.auth.models import Group from django.contrib.auth.admin import UserAdmin as BaseUserAdmin diff --git a/users/forms.py b/users/forms.py index 62bbf475..3fd38560 100644 --- a/users/forms.py +++ b/users/forms.py @@ -23,6 +23,7 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals from django import forms from django.forms import ModelForm, Form diff --git a/users/models.py b/users/models.py index 4677b8cd..bf9f579e 100644 --- a/users/models.py +++ b/users/models.py @@ -21,6 +21,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.db import models from django.db.models import Q from django import forms @@ -47,7 +49,7 @@ from django.contrib.auth.models import AbstractBaseUser, BaseUserManager from django.core.validators import MinLengthValidator from topologie.models import Room from cotisations.models import Cotisation, Facture, Paiement, Vente -from machines.models import Domain, Interface, MachineType, Machine, regen +from machines.models import Domain, Interface, MachineType, Machine, Nas, MachineType, regen from preferences.models import GeneralOption, AssoOption, OptionalUser, OptionalMachine, MailMessageOption now = timezone.now() @@ -453,17 +455,21 @@ class User(AbstractBaseUser): general_options.email_from, [req.user.email], fail_silently=False) return - def autoregister_machine(self, mac_address): + def autoregister_machine(self, mac_address, nas_ip): all_machines = self.all_machines() options, created = OptionalMachine.objects.get_or_create() - if all_macines.count() > options.max_lambdauser_interfaces: + if all_machines.count() > options.max_lambdauser_interfaces: return False, "Maximum de machines enregistrees atteinte" + nas_object = Nas.objects.filter(nas_type__in=MachineType.objects.filter(ip_type=nas_ip.ip_type)) + if not nas_object: + return False, "Re2o ne sait pas à quel machinetype affecter cette machine" + machine_type_cible = nas_object.first().machine_type try: machine_parent = Machine() machine_parent.user = self interface_cible = Interface() interface_cible.mac_address = mac_address - interface_cible.type = MachineType.objects.all().first() + interface_cible.type = machine_type_cible interface_cible.clean() machine_parent.clean() domain = Domain() @@ -481,7 +487,7 @@ class User(AbstractBaseUser): return True, "Ok" def all_machines(self): - return Interfaces.objects.filter(machine__in=Machine.objects.filter(user=self)) + return Interface.objects.filter(machine__in=Machine.objects.filter(user=self)) def __str__(self): return self.pseudo diff --git a/users/urls.py b/users/urls.py index c869e226..397ce263 100644 --- a/users/urls.py +++ b/users/urls.py @@ -20,6 +20,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import unicode_literals + from django.conf.urls import url from . import views diff --git a/users/views.py b/users/views.py index bd16ed00..5315c9bc 100644 --- a/users/views.py +++ b/users/views.py @@ -23,6 +23,9 @@ # App de gestion des users pour re2o # Goulven Kermarec, Gabriel Détraz, Lemesle Augustin # Gplv2 + +from __future__ import unicode_literals + from django.shortcuts import get_object_or_404, render, redirect from django.template.context_processors import csrf from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger