From 9ee42c0743c0ee4b316f446cdcda86e12d76139a Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 25 Nov 2016 22:50:53 +0100 Subject: [PATCH 1/5] Permet le changement de chambre force --- users/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/users/views.py b/users/views.py index fe52ec20..ff505326 100644 --- a/users/views.py +++ b/users/views.py @@ -125,7 +125,7 @@ def edit_info(request, userid): if not request.user.has_perms(('cableur',)): user = BaseInfoForm(request.POST or None, instance=user) else: - user = EditInfoForm(request.POST or None, instance=user) + user = InfoForm(request.POST or None, instance=user) if user.is_valid(): with transaction.atomic(), reversion.create_revision(): user.save() From 50b8420dd4824952e1d8d0387a9620e24b1771bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Br=C3=A9livet?= Date: Tue, 29 Nov 2016 23:53:02 +0100 Subject: [PATCH 2/5] Modification de create_cotis --- cotisations/views.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cotisations/views.py b/cotisations/views.py index aa9834c6..abd6e893 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -32,11 +32,14 @@ def form(ctx, template, request): def create_cotis(vente, user, duration, date_start=False): """ Update et crée l'objet cotisation associé à une facture, prend en argument l'user, la facture pour la quantitéi, et l'article pour la durée""" cotisation=Cotisation(vente=vente) + if date_start: + end_adhesion = Cotisation.objects.filter(vente=Vente.objects.filter(facture=Facture.objects.filter(user=user).exclude(valid=False))).filter(date_start__lt=date_start).aggregate(models.Max('date_end'))['date_end__max'] + else: + end_adhesion = user.end_adhesion() date_start = date_start or timezone.now() - date_max = user.end_adhesion() or date_start - if date_max < date_start: - date_max = date_start - cotisation.date_start=date_max + end_adhesion = end_adhesion or date_start + date_max = max(end_adhesion, date_start) + cotisation.date_start = date_max cotisation.date_end = cotisation.date_start + relativedelta(months=duration) cotisation.save() return From d5c5134d4709b33b79c74bd73b4734f04b7256d3 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 30 Nov 2016 00:59:04 +0100 Subject: [PATCH 3/5] Fix models import --- cotisations/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cotisations/views.py b/cotisations/views.py index abd6e893..ba3533d6 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -33,7 +33,7 @@ def create_cotis(vente, user, duration, date_start=False): """ Update et crée l'objet cotisation associé à une facture, prend en argument l'user, la facture pour la quantitéi, et l'article pour la durée""" cotisation=Cotisation(vente=vente) if date_start: - end_adhesion = Cotisation.objects.filter(vente=Vente.objects.filter(facture=Facture.objects.filter(user=user).exclude(valid=False))).filter(date_start__lt=date_start).aggregate(models.Max('date_end'))['date_end__max'] + end_adhesion = Cotisation.objects.filter(vente=Vente.objects.filter(facture=Facture.objects.filter(user=user).exclude(valid=False))).filter(date_start__lt=date_start).aggregate(Max('date_end'))['date_end__max'] else: end_adhesion = user.end_adhesion() date_start = date_start or timezone.now() From 32217118e17b15360789baa7ff5f60a9e4a805ef Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 30 Nov 2016 04:48:47 +0100 Subject: [PATCH 4/5] Bricoles, affiche les ip dispo --- machines/forms.py | 9 +++++++-- machines/views.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/machines/forms.py b/machines/forms.py index 6a8d8d27..05f3a1f6 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -1,6 +1,7 @@ from django.forms import ModelForm, Form, ValidationError from django import forms from .models import Alias, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, IpType +from django.db.models import Q class EditMachineForm(ModelForm): class Meta: @@ -41,7 +42,9 @@ class AddInterfaceForm(EditInterfaceForm): self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4" if not infra: self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False)) - self.fields['ipv4'].queryset = IpList.objects.filter(ip_type=IpType.objects.filter(need_infra=False)) + self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type=IpType.objects.filter(need_infra=False)) + else: + self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True) class NewInterfaceForm(EditInterfaceForm): class Meta(EditInterfaceForm.Meta): @@ -57,7 +60,9 @@ class BaseEditInterfaceForm(EditInterfaceForm): self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4" if not infra: self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False)) - self.fields['ipv4'].queryset = IpList.objects.filter(ip_type=IpType.objects.filter(need_infra=False)) + self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type=IpType.objects.filter(need_infra=False)) + else: + self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True) class AliasForm(ModelForm): class Meta: diff --git a/machines/views.py b/machines/views.py index fd8e5a93..522b6730 100644 --- a/machines/views.py +++ b/machines/views.py @@ -197,7 +197,7 @@ def new_interface(request, machineid): reversion.set_user(request.user) reversion.set_comment("Création") messages.success(request, "L'interface a été ajoutée") - return redirect("/users/profil/" + str(request.user.id)) + return redirect("/users/profil/" + str(machine.user.id)) return form({'interfaceform': interface_form}, 'machines/machine.html', request) @login_required From ea20cede0c22f6f9b1c8194cdcd029a346a0c118 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Thu, 1 Dec 2016 03:00:55 +0100 Subject: [PATCH 5/5] Rajoute une acl need_infra sur l'object ip --- machines/forms.py | 4 ++-- machines/migrations/0034_iplist_need_infra.py | 19 +++++++++++++++++++ machines/models.py | 1 + machines/views.py | 7 ++++++- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 machines/migrations/0034_iplist_need_infra.py diff --git a/machines/forms.py b/machines/forms.py index 05f3a1f6..14ebd884 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -42,7 +42,7 @@ class AddInterfaceForm(EditInterfaceForm): self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4" if not infra: self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False)) - self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type=IpType.objects.filter(need_infra=False)) + self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type=IpType.objects.filter(need_infra=False)).filter(need_infra=False) else: self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True) @@ -60,7 +60,7 @@ class BaseEditInterfaceForm(EditInterfaceForm): self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4" if not infra: self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False)) - self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type=IpType.objects.filter(need_infra=False)) + self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type=IpType.objects.filter(need_infra=False)).filter(need_infra=False) else: self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True) diff --git a/machines/migrations/0034_iplist_need_infra.py b/machines/migrations/0034_iplist_need_infra.py new file mode 100644 index 00000000..801a40fb --- /dev/null +++ b/machines/migrations/0034_iplist_need_infra.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0033_extension_need_infra'), + ] + + operations = [ + migrations.AddField( + model_name='iplist', + name='need_infra', + field=models.BooleanField(default=False), + ), + ] diff --git a/machines/models.py b/machines/models.py index f7ef3681..0bd879d7 100644 --- a/machines/models.py +++ b/machines/models.py @@ -124,6 +124,7 @@ class IpList(models.Model): ipv4 = models.GenericIPAddressField(protocol='IPv4', unique=True) ip_type = models.ForeignKey('IpType', on_delete=models.PROTECT) + need_infra = models.BooleanField(default=False) def __str__(self): return self.ipv4 diff --git a/machines/views.py b/machines/views.py index 522b6730..eea7fdd3 100644 --- a/machines/views.py +++ b/machines/views.py @@ -60,7 +60,10 @@ def assign_ips(user): def free_ip(type): """ Renvoie la liste des ip disponibles """ - return IpList.objects.filter(interface__isnull=True).filter(ip_type=type) + if not type.need_infra: + return IpList.objects.filter(interface__isnull=True).filter(ip_type=type).filter(need_infra=False) + else: + return IpList.objects.filter(interface__isnull=True).filter(ip_type=type) def assign_ipv4(interface): """ Assigne une ip à l'interface """ @@ -142,6 +145,8 @@ def edit_interface(request, interfaceid): new_machine.save() reversion.set_user(request.user) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in machine_form.changed_data)) + if free_ip(new_interface.type.ip_type) and not new_interface.ipv4: + new_interface = assign_ipv4(new_interface) with transaction.atomic(), reversion.create_revision(): new_interface.save() reversion.set_user(request.user)