Commit 3bdd17a0 authored by chirac's avatar chirac

Reassigne des ips au désarchivage

parent 36f95c88
......@@ -11,14 +11,19 @@ from .models import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInter
from .models import Machine, Interface, IpList
from users.models import User
def unassign_ip(machine):
machine.ipv4 = None
machine.save()
def unassign_ips(user):
machines = Interface.objects.filter(machine=Machine.objects.filter(user=user))
for machine in machines:
unassign_ip(machine)
unassign_ipv4(machine)
return
def assign_ips(user):
""" Assign une ipv4 aux machines d'un user """
machines = Interface.objects.filter(machine=Machine.objects.filter(user=user))
for machine in machines:
if not machine.ipv4:
interface = assign_ipv4(machine)
interface.save()
return
def free_ip():
......@@ -32,6 +37,10 @@ def assign_ipv4(interface):
interface.ipv4 = free_ips[0]
return interface
def unassign_ipv4(interface):
interface.ipv4 = None
interface.save()
def form(ctx, template, request):
c = ctx
c.update(csrf(request))
......
......@@ -15,7 +15,7 @@ from machines.models import Machine, Interface
from users.forms import PassForm
from search.models import SearchForm
from cotisations.views import is_adherent, end_adhesion
from machines.views import unassign_ips
from machines.views import unassign_ips, assign_ips
from re2o.login import makeSecret, hashNT
......@@ -24,6 +24,11 @@ def archive(user):
unassign_ips(user)
return
def unarchive(user):
""" Triger actions au desarchivage d'un user """
assign_ips(user)
return
def end_ban(user):
""" Renvoie la date de fin de ban d'un user, False sinon """
date_max = Ban.objects.all().filter(user=user).aggregate(Max('date_end'))['date_end__max']
......@@ -83,6 +88,8 @@ def state(request, userid):
if state.has_changed():
if state.cleaned_data['state'] == User.STATE_ARCHIVED:
archive(user)
else:
unarchive(user)
state.save()
messages.success(request, "Etat changé avec succès")
return redirect("/users/")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment