From 88f519ba8e69b5bca855045deeb4f530484b1aa9 Mon Sep 17 00:00:00 2001 From: Tipunchetrhum Date: Thu, 29 Mar 2018 23:43:43 +0200 Subject: [PATCH 1/6] modification panel profil --- users/templates/users/profil.html | 207 +++++++++++------------------- 1 file changed, 77 insertions(+), 130 deletions(-) diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html index 731ba560..ba45c0bd 100644 --- a/users/templates/users/profil.html +++ b/users/templates/users/profil.html @@ -49,50 +49,36 @@ non adhérent{% endif %} et votre connexion est {% if users.has_access %}

Informations détaillées

-
-
+
+ + + Editer + + + + Changer le mot de passe + + {% can_change User state %} + + + Changer le statut + + {% acl_end %} + {% can_change User groups %} + + + Gérer les groupes + + {% acl_end %} + + + Historique + + +
+
@@ -194,23 +180,16 @@ non adhérent{% endif %} et votre connexion est {% if users.has_access %}

Gérer le club

-
-

Administrateurs du club

+ + + Gérer admin et membres + +
+
+

Administrateurs du club

@@ -259,21 +238,14 @@ non adhérent{% endif %} et votre connexion est {% if users.has_access %} Machines {{machines_list.count}} - - +
+
{% if machines_list %} {% include "machines/aff_machines.html" with machines_list=machines_list %} @@ -289,37 +261,26 @@ non adhérent{% endif %} et votre connexion est {% if users.has_access %} Cotisations -
+
+ {% can_create Facture %} + + + Ajouter une cotisation + + {% if user_solde %} + + + Modifier le solde + + {% endif%}{% acl_else %} + {% if user_solde %} + + + Ajouter une cotisation par solde{% endif %}{% acl_end %} + +
{% if facture_list %} {% include "cotisations/aff_cotisations.html" with facture_list=facture_list %} @@ -335,23 +296,16 @@ non adhérent{% endif %} et votre connexion est {% if users.has_access %} Bannissements - -
+
+
+ {% can_create Ban %} + + + Ajouter un bannissement + + {% acl_end %} +
{% if ban_list %} {% include "users/aff_bans.html" with ban_list=ban_list %} @@ -367,23 +321,16 @@ non adhérent{% endif %} et votre connexion est {% if users.has_access %} Accès à titre gracieux -
+
+ {% can_create Whitelist %} + + + Accorder un accès à titre gracieux + + {% acl_end %} +
{% if white_list %} {% include "users/aff_whitelists.html" with white_list=white_list %} From e7be7e1a2c21a5b7a6d6b12b2642e828e1bf5ac9 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sun, 1 Apr 2018 20:44:23 +0200 Subject: [PATCH 2/6] Fix service users + stack --- topologie/views.py | 2 +- users/urls.py | 4 ++-- users/views.py | 22 +++++++++++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/topologie/views.py b/topologie/views.py index 97b01ebb..b57a5255 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -211,7 +211,7 @@ def index_ap(request): def index_stack(request): """Affichage de la liste des stacks (affiche l'ensemble des switches)""" stack_list = Stack.objects\ - .prefetch_related('switch_set__domain__extension') + .prefetch_related('switch_set__interface_set__domain__extension') stack_list = SortTable.sort( stack_list, request.GET.get('col'), diff --git a/users/urls.py b/users/urls.py index fac55e44..b8f428b0 100644 --- a/users/urls.py +++ b/users/urls.py @@ -45,12 +45,12 @@ urlpatterns = [ url(r'^del_group/(?P[0-9]+)/(?P[0-9]+)$', views.del_group, name='del-group'), url(r'^new_serviceuser/$', views.new_serviceuser, name='new-serviceuser'), url( - r'^edit_serviceuser/(?P[0-9]+)$', + r'^edit_serviceuser/(?P[0-9]+)$', views.edit_serviceuser, name='edit-serviceuser' ), url( - r'^del_serviceuser/(?P[0-9]+)$', + r'^del_serviceuser/(?P[0-9]+)$', views.del_serviceuser, name='del-serviceuser' ), diff --git a/users/views.py b/users/views.py index 73332e8b..8eb23bbf 100644 --- a/users/views.py +++ b/users/views.py @@ -305,36 +305,36 @@ def new_serviceuser(request): @login_required @can_edit(ServiceUser) -def edit_serviceuser(request, user, userid): +def edit_serviceuser(request, serviceuser, serviceuserid): """ Edit a ServiceUser """ - user = EditServiceUserForm(request.POST or None, instance=user) - if user.is_valid(): - user_object = user.save(commit=False) + serviceuser = EditServiceUserForm(request.POST or None, instance=serviceuser) + if serviceuser.is_valid(): + user_object = serviceuser.save(commit=False) with transaction.atomic(), reversion.create_revision(): - if user.cleaned_data['password']: - user_object.set_password(user.cleaned_data['password']) + if serviceuser.cleaned_data['password']: + user_object.set_password(serviceuser.cleaned_data['password']) user_object.save() reversion.set_user(request.user) reversion.set_comment("Champs modifié(s) : %s" % ', '.join( - field for field in user.changed_data + field for field in serviceuser.changed_data )) messages.success(request, "L'user a bien été modifié") return redirect(reverse('users:index-serviceusers')) - return form({'userform': user, 'action_name':'Editer un serviceuser'}, 'users/user.html', request) + return form({'userform': serviceuser, 'action_name':'Editer un serviceuser'}, 'users/user.html', request) @login_required @can_delete(ServiceUser) -def del_serviceuser(request, user, userid): +def del_serviceuser(request, serviceuser, serviceuserid): """Suppression d'un ou plusieurs serviceusers""" if request.method == "POST": with transaction.atomic(), reversion.create_revision(): - user.delete() + serviceuser.delete() reversion.set_user(request.user) messages.success(request, "L'user a été détruite") return redirect(reverse('users:index-serviceusers')) return form( - {'objet': user, 'objet_name': 'serviceuser'}, + {'objet': serviceuser, 'objet_name': 'serviceuser'}, 'users/delete.html', request ) From ec076fb4bf19ba62878a5f7d014057e039469166 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Tue, 3 Apr 2018 04:58:00 +0200 Subject: [PATCH 3/6] xReactivation du sendmail --- users/models.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/users/models.py b/users/models.py index 8b4b11c9..efd46a75 100644 --- a/users/models.py +++ b/users/models.py @@ -548,15 +548,15 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, PermissionsMix 'welcome_mail_en': mailmessageoptions.welcome_mail_en, 'pseudo': self.pseudo, }) - #send_mail( - # 'Bienvenue au %(name)s / Welcome to %(name)s' % { - # 'name': AssoOption.get_cached_value('name') - # }, - # '', - # GeneralOption.get_cached_value('email_from'), - # [self.email], - # html_message=template.render(context) - #) + send_mail( + 'Bienvenue au %(name)s / Welcome to %(name)s' % { + 'name': AssoOption.get_cached_value('name') + }, + '', + GeneralOption.get_cached_value('email_from'), + [self.email], + html_message=template.render(context) + ) return def reset_passwd_mail(self, request): @@ -576,14 +576,14 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, PermissionsMix reverse('users:process', kwargs={'token': req.token})), 'expire_in': str(GeneralOption.get_cached_value('req_expire_hrs')) + ' heures', } - #send_mail( - # 'Changement de mot de passe du %(name)s / Password\ - # renewal for %(name)s' % {'name': AssoOption.get_cached_value('name')}, - # template.render(context), - # GeneralOption.get_cached_value('email_from'), - # [req.user.email], - # fail_silently=False - #) + send_mail( + 'Changement de mot de passe du %(name)s / Password\ + renewal for %(name)s' % {'name': AssoOption.get_cached_value('name')}, + template.render(context), + GeneralOption.get_cached_value('email_from'), + [req.user.email], + fail_silently=False + ) return def autoregister_machine(self, mac_address, nas_type): @@ -1127,13 +1127,13 @@ class Ban(RevMixin, AclMixin, models.Model): 'date_end': self.date_end, 'asso_name': AssoOption.get_cached_value('name'), }) - #send_mail( - # 'Deconnexion disciplinaire', - # template.render(context), - # GeneralOption.get_cached_value('email_from'), - # [self.user.email], - # fail_silently=False - #) + send_mail( + 'Deconnexion disciplinaire', + template.render(context), + GeneralOption.get_cached_value('email_from'), + [self.user.email], + fail_silently=False + ) return def is_active(self): From 3affe08d29ece99bd815c126dc4d89b5f1c88ffa Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Tue, 3 Apr 2018 05:00:06 +0200 Subject: [PATCH 4/6] Factorisation de paginator + pagination des machines dans profil --- cotisations/views.py | 23 +++-------------- logs/views.py | 25 +++---------------- machines/views.py | 13 ++-------- preferences/views.py | 1 - re2o/utils.py | 17 +++++++++++++ re2o/views.py | 13 ++-------- topologie/views.py | 36 +++------------------------ users/views.py | 59 ++++++-------------------------------------- 8 files changed, 39 insertions(+), 148 deletions(-) diff --git a/cotisations/views.py b/cotisations/views.py index 9db33d1d..545f9ebe 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -28,7 +28,6 @@ import os from django.urls import reverse from django.shortcuts import render, redirect -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.validators import MaxValueValidator from django.contrib.auth.decorators import login_required, permission_required from django.contrib import messages @@ -45,7 +44,7 @@ from users.models import User from re2o.settings import LOGO_PATH from re2o import settings from re2o.views import form -from re2o.utils import SortTable +from re2o.utils import SortTable, re2o_paginator from re2o.acl import ( can_create, can_edit, @@ -455,14 +454,7 @@ def control(request): fields=('control', 'valid'), extra=0 ) - paginator = Paginator(facture_list, pagination_number) - page = request.GET.get('page') - try: - facture_list = paginator.page(page) - except PageNotAnInteger: - facture_list = paginator.page(1) - except EmptyPage: - facture_list = paginator.page(paginator.num.pages) + facture_list = re2o_paginator(request, facture_list, pagination_number) controlform = controlform_set(request.POST or None, queryset=facture_list.object_list) if controlform.is_valid(): controlform.save() @@ -517,16 +509,7 @@ def index(request): request.GET.get('order'), SortTable.COTISATIONS_INDEX ) - paginator = Paginator(facture_list, pagination_number) - page = request.GET.get('page') - try: - facture_list = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - facture_list = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - facture_list = paginator.page(paginator.num_pages) + facture_list = re2o_paginator(request, facture_list, pagination_number) return render(request, 'cotisations/index.html', { 'facture_list': facture_list }) diff --git a/logs/views.py b/logs/views.py index 5dd87eaa..84ff8180 100644 --- a/logs/views.py +++ b/logs/views.py @@ -39,7 +39,6 @@ from __future__ import unicode_literals from django.urls import reverse from django.shortcuts import render, redirect -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.contrib import messages from django.contrib.auth.decorators import login_required from django.db.models import Count, Max @@ -100,6 +99,7 @@ from re2o.utils import ( all_baned, all_has_access, all_adherent, + re2o_paginator, ) from re2o.acl import ( can_view_all, @@ -139,17 +139,7 @@ def index(request): request.GET.get('order'), SortTable.LOGS_INDEX ) - paginator = Paginator(versions, pagination_number) - page = request.GET.get('page') - try: - versions = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - versions = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - versions = paginator.page(paginator.num_pages) - + versions = re2o_paginator(request, versions, pagination_number) # Force to have a list instead of QuerySet versions.count(0) # Items to remove later because invalid @@ -191,16 +181,7 @@ def stats_logs(request): request.GET.get('order'), SortTable.LOGS_STATS_LOGS ) - paginator = Paginator(revisions, pagination_number) - page = request.GET.get('page') - try: - revisions = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - revisions = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - revisions = paginator.page(paginator.num_pages) + revisions = re2o_paginator(request, revisions, pagination_number) return render(request, 'logs/stats_logs.html', { 'revisions_list': revisions }) diff --git a/machines/views.py b/machines/views.py index a3cfe209..ee23504d 100644 --- a/machines/views.py +++ b/machines/views.py @@ -33,7 +33,6 @@ from django.http import HttpResponse from django.shortcuts import render, redirect from django.shortcuts import get_object_or_404 from django.template.context_processors import csrf -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.template import Context, RequestContext, loader from django.contrib import messages from django.contrib.auth.decorators import login_required, permission_required @@ -123,6 +122,7 @@ from re2o.utils import ( all_has_access, filter_active_interfaces, SortTable, + re2o_paginator, ) from re2o.acl import ( can_create, @@ -863,16 +863,7 @@ def index(request): request.GET.get('order'), SortTable.MACHINES_INDEX ) - paginator = Paginator(machines_list, pagination_large_number) - page = request.GET.get('page') - try: - machines_list = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - machines_list = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - machines_list = paginator.page(paginator.num_pages) + machines_list = re2o_paginator(request, machines_list, pagination_large_number) return render(request, 'machines/index.html', {'machines_list': machines_list}) @login_required diff --git a/preferences/views.py b/preferences/views.py index 43befc72..22341c28 100644 --- a/preferences/views.py +++ b/preferences/views.py @@ -32,7 +32,6 @@ from __future__ import unicode_literals from django.urls import reverse from django.shortcuts import render, redirect -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.contrib import messages from django.contrib.auth.decorators import login_required, permission_required from django.db.models import ProtectedError diff --git a/re2o/utils.py b/re2o/utils.py index aaefca8d..8336aab5 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -42,6 +42,7 @@ from django.db.models import Q from django.contrib import messages from django.shortcuts import redirect from django.urls import reverse +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from cotisations.models import Cotisation, Facture, Paiement, Vente from machines.models import Domain, Interface, Machine @@ -280,6 +281,22 @@ class SortTable: else: return request +def re2o_paginator(request, query_set, pagination_number): + """Paginator script for list display in re2o. + :request: + :query_set: Query_set to paginate + :pagination_number: Number of entries to display""" + paginator = Paginator(query_set, pagination_number) + page = request.GET.get('page') + try: + results = paginator.page(page) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + results = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g. 9999), deliver last page of results. + results = paginator.page(paginator.num_pages) + return results def remove_user_room(room): """ Déménage de force l'ancien locataire de la chambre """ diff --git a/re2o/views.py b/re2o/views.py index 83cd7630..991b8702 100644 --- a/re2o/views.py +++ b/re2o/views.py @@ -31,7 +31,6 @@ from django.urls import reverse from django.shortcuts import render, redirect from django.template.context_processors import csrf from django.contrib.auth.decorators import login_required, permission_required -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from reversion.models import Version from django.contrib import messages from preferences.models import Service @@ -42,6 +41,7 @@ import os import time from itertools import chain import users, preferences, cotisations, topologie, machines +from .utils import re2o_paginator def form(ctx, template, request): """Form générique, raccourci importé par les fonctions views du site""" @@ -150,16 +150,7 @@ def history(request, application, object_name, object_id): if hasattr(instance, 'linked_objects'): for related_object in chain(instance.linked_objects()): reversions = reversions | Version.objects.get_for_object(related_object) - paginator = Paginator(reversions, pagination_number) - page = request.GET.get('page') - try: - reversions = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - reversions = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of result - reversions = paginator.page(paginator.num_pages) + reversions = re2o_paginator(request, reversions, pagination_number) return render( request, 're2o/history.html', diff --git a/topologie/views.py b/topologie/views.py index f87213fa..0d73d3ea 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -43,7 +43,6 @@ from django.db import IntegrityError from django.db import transaction from django.db.models import ProtectedError, Prefetch from django.core.exceptions import ValidationError -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from topologie.models import ( Switch, @@ -66,7 +65,7 @@ from topologie.forms import ( EditAccessPointForm ) from users.views import form -from re2o.utils import SortTable +from re2o.utils import re2o_paginator, SortTable from re2o.acl import ( can_create, can_edit, @@ -103,16 +102,7 @@ def index(request): SortTable.TOPOLOGIE_INDEX ) pagination_number = GeneralOption.get_cached_value('pagination_number') - paginator = Paginator(switch_list, pagination_number) - page = request.GET.get('page') - try: - switch_list = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - switch_list = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - switch_list = paginator.page(paginator.num_pages) + switch_list = re2o_paginator(request, switch_list, pagination_number) return render(request, 'topologie/index.html', { 'switch_list': switch_list }) @@ -158,16 +148,7 @@ def index_room(request): SortTable.TOPOLOGIE_INDEX_ROOM ) pagination_number = GeneralOption.get_cached_value('pagination_number') - paginator = Paginator(room_list, pagination_number) - page = request.GET.get('page') - try: - room_list = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - room_list = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - room_list = paginator.page(paginator.num_pages) + room_list = re2o_paginator(request, room_list, pagination_number) return render(request, 'topologie/index_room.html', { 'room_list': room_list }) @@ -189,16 +170,7 @@ def index_ap(request): SortTable.TOPOLOGIE_INDEX_BORNE ) pagination_number = GeneralOption.get_cached_value('pagination_number') - paginator = Paginator(ap_list, pagination_number) - page = request.GET.get('page') - try: - ap_list = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - ap_list = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - ap_list = paginator.page(paginator.num_pages) + ap_list = re2o_paginator(request, ap_list, pagination_number) return render(request, 'topologie/index_ap.html', { 'ap_list': ap_list }) diff --git a/users/views.py b/users/views.py index be87dd06..80680e40 100644 --- a/users/views.py +++ b/users/views.py @@ -37,7 +37,6 @@ from __future__ import unicode_literals from django.urls import reverse from django.shortcuts import get_object_or_404, render, redirect -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.contrib import messages from django.contrib.auth.decorators import login_required, permission_required from django.db.models import ProtectedError, Q @@ -95,6 +94,7 @@ from re2o.views import form from re2o.utils import ( all_has_access, SortTable, + re2o_paginator ) from re2o.acl import ( can_create, @@ -572,16 +572,7 @@ def index(request): request.GET.get('order'), SortTable.USERS_INDEX ) - paginator = Paginator(users_list, pagination_number) - page = request.GET.get('page') - try: - users_list = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - users_list = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - users_list = paginator.page(paginator.num_pages) + users_list = re2o_paginator(request, users_list, pagination_number) return render(request, 'users/index.html', {'users_list': users_list}) @@ -597,16 +588,7 @@ def index_clubs(request): request.GET.get('order'), SortTable.USERS_INDEX ) - paginator = Paginator(clubs_list, pagination_number) - page = request.GET.get('page') - try: - clubs_list = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - clubs_list = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - clubs_list = paginator.page(paginator.num_pages) + clubs_list = re2o_paginator(request, clubs_list, pagination_number) return render(request, 'users/index_clubs.html', {'clubs_list': clubs_list}) @@ -622,16 +604,7 @@ def index_ban(request): request.GET.get('order'), SortTable.USERS_INDEX_BAN ) - paginator = Paginator(ban_list, pagination_number) - page = request.GET.get('page') - try: - ban_list = paginator.page(page) - except PageNotAnInteger: - # If page isn't an integer, deliver first page - ban_list = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - ban_list = paginator.page(paginator.num_pages) + ban_list = re2o_paginator(request, ban_list, pagination_number) return render(request, 'users/index_ban.html', {'ban_list': ban_list}) @@ -647,16 +620,7 @@ def index_white(request): request.GET.get('order'), SortTable.USERS_INDEX_BAN ) - paginator = Paginator(white_list, pagination_number) - page = request.GET.get('page') - try: - white_list = paginator.page(page) - except PageNotAnInteger: - # If page isn't an integer, deliver first page - white_list = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - white_list = paginator.page(paginator.num_pages) + white_list = re2o_paginator(request, white_list, pagination_number) return render( request, 'users/index_whitelist.html', @@ -676,16 +640,7 @@ def index_school(request): request.GET.get('order'), SortTable.USERS_INDEX_SCHOOL ) - paginator = Paginator(school_list, pagination_number) - page = request.GET.get('page') - try: - school_list = paginator.page(page) - except PageNotAnInteger: - # If page isn't an integer, deliver first page - school_list = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - school_list = paginator.page(paginator.num_pages) + school_list = re2o_paginator(request, school_list, pagination_number) return render( request, 'users/index_schools.html', @@ -754,6 +709,8 @@ def profil(request, users, userid): request.GET.get('order'), SortTable.MACHINES_INDEX ) + pagination_large_number = GeneralOption.get_cached_value('pagination_large_number') + machines = re2o_paginator(request, machines, pagination_large_number) factures = Facture.objects.filter(user=users) factures = SortTable.sort( factures, From cdc012bc47799a8af76d59daa3d38c902d3be001 Mon Sep 17 00:00:00 2001 From: chirac Date: Tue, 3 Apr 2018 20:11:19 +0200 Subject: [PATCH 5/6] Update auth.py --- freeradius_utils/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freeradius_utils/auth.py b/freeradius_utils/auth.py index c20764e9..5d3195da 100644 --- a/freeradius_utils/auth.py +++ b/freeradius_utils/auth.py @@ -237,7 +237,7 @@ def detach(_=None): return radiusd.RLM_MODULE_OK def find_nas_from_request(nas_id): - nas = Interface.objects.filter(Q(domain=Domain.objects.filter(name=nas_id)) | Q(ipv4=IpList.objects.filter(ipv4=nas_id))).select_related('type').select_related('switch__stack') + nas = Interface.objects.filter(Q(domain=Domain.objects.filter(name=nas_id)) | Q(ipv4=IpList.objects.filter(ipv4=nas_id))).select_related('type').select_related('machine__switch__stack') return nas.first() def check_user_machine_and_register(nas_type, username, mac_address): From bb6b19f5742f47cac7f5ad923e62bb203b3b8cb5 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 7 Apr 2018 22:13:41 +0200 Subject: [PATCH 6/6] Fix le changement d'etat de l'user --- users/views.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/users/views.py b/users/views.py index 12e6740e..26b1e0e7 100644 --- a/users/views.py +++ b/users/views.py @@ -198,14 +198,12 @@ def state(request, user, userid): need droit bureau """ state = StateForm(request.POST or None, instance=user) if state.is_valid(): - if state.cleaned_data['state'] == User.STATE_ARCHIVE: - user.archive() - elif state.cleaned_data['state'] == User.STATE_ACTIVE: - user.unarchive() - elif state.cleaned_data['state'] == User.STATE_DISABLED: - user.state = User.STATE_DISABLED - if user.changed_data: - user.save() + if state.changed_data: + if state.cleaned_data['state'] == User.STATE_ARCHIVE: + user.archive() + elif state.cleaned_data['state'] == User.STATE_ACTIVE: + user.unarchive() + state.save() messages.success(request, "Etat changé avec succès") return redirect(reverse( 'users:profil',