mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 12:53:11 +00:00
A partir de django 1.9 les filter__in ne sont plus implicites
This commit is contained in:
parent
90df520620
commit
19d984f85e
5 changed files with 22 additions and 19 deletions
|
@ -17,14 +17,14 @@ class Facture(models.Model):
|
||||||
control = models.BooleanField(default=False)
|
control = models.BooleanField(default=False)
|
||||||
|
|
||||||
def prix(self):
|
def prix(self):
|
||||||
prix = Vente.objects.all().filter(facture=self).aggregate(models.Sum('prix'))['prix__sum']
|
prix = Vente.objects.filter(facture=self).aggregate(models.Sum('prix'))['prix__sum']
|
||||||
return prix
|
return prix
|
||||||
|
|
||||||
def prix_total(self):
|
def prix_total(self):
|
||||||
return Vente.objects.all().filter(facture=self).aggregate(total=models.Sum(models.F('prix')*models.F('number'), output_field=models.FloatField()))['total']
|
return Vente.objects.filter(facture=self).aggregate(total=models.Sum(models.F('prix')*models.F('number'), output_field=models.FloatField()))['total']
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
name = ' - '.join(vente.name for vente in Vente.objects.all().filter(facture=self))
|
name = ' - '.join(vente.name for vente in Vente.objects.filter(facture=self))
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -34,7 +34,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"""
|
""" 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)
|
cotisation=Cotisation(vente=vente)
|
||||||
if date_start:
|
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(Max('date_end'))['date_end__max']
|
end_adhesion = Cotisation.objects.filter(vente__in=Vente.objects.filter(facture__in=Facture.objects.filter(user=user).exclude(valid=False))).filter(date_start__lt=date_start).aggregate(Max('date_end'))['date_end__max']
|
||||||
else:
|
else:
|
||||||
end_adhesion = user.end_adhesion()
|
end_adhesion = user.end_adhesion()
|
||||||
date_start = date_start or timezone.now()
|
date_start = date_start or timezone.now()
|
||||||
|
@ -330,7 +330,10 @@ def control(request):
|
||||||
page_query = Facture.objects.order_by('date').reverse().filter(id__in=[facture.id for facture in facture_list])
|
page_query = Facture.objects.order_by('date').reverse().filter(id__in=[facture.id for facture in facture_list])
|
||||||
controlform = controlform_set(request.POST or None, queryset=page_query)
|
controlform = controlform_set(request.POST or None, queryset=page_query)
|
||||||
if controlform.is_valid():
|
if controlform.is_valid():
|
||||||
|
with transaction.atomic(), reversion.create_revision():
|
||||||
controlform.save()
|
controlform.save()
|
||||||
|
reversion.set_user(request.user)
|
||||||
|
reversion.set_comment("Controle trésorier")
|
||||||
return redirect("/cotisations/control/")
|
return redirect("/cotisations/control/")
|
||||||
return render(request, 'cotisations/control.html', {'facture_list': facture_list, 'controlform': controlform})
|
return render(request, 'cotisations/control.html', {'facture_list': facture_list, 'controlform': controlform})
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,8 @@ class AddInterfaceForm(EditInterfaceForm):
|
||||||
super(AddInterfaceForm, self).__init__(*args, **kwargs)
|
super(AddInterfaceForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
|
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
|
||||||
if not infra:
|
if not infra:
|
||||||
self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False))
|
self.fields['type'].queryset = MachineType.objects.filter(ip_type__in=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)
|
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type__in=IpType.objects.filter(need_infra=False)).filter(need_infra=False)
|
||||||
else:
|
else:
|
||||||
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True)
|
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True)
|
||||||
|
|
||||||
|
@ -59,8 +59,8 @@ class BaseEditInterfaceForm(EditInterfaceForm):
|
||||||
super(BaseEditInterfaceForm, self).__init__(*args, **kwargs)
|
super(BaseEditInterfaceForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
|
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
|
||||||
if not infra:
|
if not infra:
|
||||||
self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False))
|
self.fields['type'].queryset = MachineType.objects.filter(ip_type__in=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)
|
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type__in=IpType.objects.filter(need_infra=False)).filter(need_infra=False)
|
||||||
else:
|
else:
|
||||||
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True)
|
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True)
|
||||||
|
|
||||||
|
|
|
@ -42,14 +42,14 @@ def full_domain_validator(request, interface):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def unassign_ips(user):
|
def unassign_ips(user):
|
||||||
machines = Interface.objects.filter(machine=Machine.objects.filter(user=user))
|
machines = user.user_interfaces()
|
||||||
for machine in machines:
|
for machine in machines:
|
||||||
unassign_ipv4(machine)
|
unassign_ipv4(machine)
|
||||||
return
|
return
|
||||||
|
|
||||||
def assign_ips(user):
|
def assign_ips(user):
|
||||||
""" Assign une ipv4 aux machines d'un user """
|
""" Assign une ipv4 aux machines d'un user """
|
||||||
machines = Interface.objects.filter(machine=Machine.objects.filter(user=user))
|
machines = user.user_interfaces()
|
||||||
for machine in machines:
|
for machine in machines:
|
||||||
if not machine.ipv4:
|
if not machine.ipv4:
|
||||||
interface = assign_ipv4(machine)
|
interface = assign_ipv4(machine)
|
||||||
|
@ -475,7 +475,7 @@ def add_alias(request, interfaceid):
|
||||||
if interface.machine.user != request.user:
|
if interface.machine.user != request.user:
|
||||||
messages.error(request, "Vous ne pouvez pas ajouter un alias à une machine d'un autre user que vous sans droit")
|
messages.error(request, "Vous ne pouvez pas ajouter un alias à une machine d'un autre user que vous sans droit")
|
||||||
return redirect("/users/profil/" + str(request.user.id))
|
return redirect("/users/profil/" + str(request.user.id))
|
||||||
if Alias.objects.filter(interface_parent=interface.machine.user.user_interfaces()).count() >= MAX_ALIAS:
|
if Alias.objects.filter(interface_parent__in=interface.machine.user.user_interfaces()).count() >= MAX_ALIAS:
|
||||||
messages.error(request, "Vous avez atteint le maximum d'alias autorisées que vous pouvez créer vous même (%s) " % MAX_ALIAS)
|
messages.error(request, "Vous avez atteint le maximum d'alias autorisées que vous pouvez créer vous même (%s) " % MAX_ALIAS)
|
||||||
return redirect("/users/profil/" + str(request.user.id))
|
return redirect("/users/profil/" + str(request.user.id))
|
||||||
alias = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',)))
|
alias = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',)))
|
||||||
|
@ -683,7 +683,7 @@ def interface_list(request):
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('serveur')
|
@permission_required('serveur')
|
||||||
def alias(request):
|
def alias(request):
|
||||||
alias = Alias.objects.filter(interface_parent=Interface.objects.exclude(ipv4=None))
|
alias = Alias.objects.filter(interface_parent__in=Interface.objects.exclude(ipv4=None))
|
||||||
seria = AliasSerializer(alias, many=True)
|
seria = AliasSerializer(alias, many=True)
|
||||||
return JSONResponse(seria.data)
|
return JSONResponse(seria.data)
|
||||||
|
|
||||||
|
@ -707,7 +707,7 @@ def mx(request):
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('serveur')
|
@permission_required('serveur')
|
||||||
def ns(request):
|
def ns(request):
|
||||||
ns = Ns.objects.filter(interface=Interface.objects.exclude(ipv4=None))
|
ns = Ns.objects.filter(interface__in=Interface.objects.exclude(ipv4=None))
|
||||||
seria = NsSerializer(ns, many=True)
|
seria = NsSerializer(ns, many=True)
|
||||||
return JSONResponse(seria.data)
|
return JSONResponse(seria.data)
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ class User(AbstractBaseUser):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def end_adhesion(self):
|
def end_adhesion(self):
|
||||||
date_max = Cotisation.objects.all().filter(vente=Vente.objects.all().filter(facture=Facture.objects.all().filter(user=self).exclude(valid=False))).aggregate(models.Max('date_end'))['date_end__max']
|
date_max = Cotisation.objects.filter(vente__in=Vente.objects.filter(facture__in=Facture.objects.filter(user=self).exclude(valid=False))).aggregate(models.Max('date_end'))['date_end__max']
|
||||||
return date_max
|
return date_max
|
||||||
|
|
||||||
def is_adherent(self):
|
def is_adherent(self):
|
||||||
|
@ -194,12 +194,12 @@ class User(AbstractBaseUser):
|
||||||
|
|
||||||
def end_ban(self):
|
def end_ban(self):
|
||||||
""" Renvoie la date de fin de ban d'un user, False sinon """
|
""" Renvoie la date de fin de ban d'un user, False sinon """
|
||||||
date_max = Ban.objects.all().filter(user=self).aggregate(models.Max('date_end'))['date_end__max']
|
date_max = Ban.objects.filter(user=self).aggregate(models.Max('date_end'))['date_end__max']
|
||||||
return date_max
|
return date_max
|
||||||
|
|
||||||
def end_whitelist(self):
|
def end_whitelist(self):
|
||||||
""" Renvoie la date de fin de ban d'un user, False sinon """
|
""" Renvoie la date de fin de ban d'un user, False sinon """
|
||||||
date_max = Whitelist.objects.all().filter(user=self).aggregate(models.Max('date_end'))['date_end__max']
|
date_max = Whitelist.objects.filter(user=self).aggregate(models.Max('date_end'))['date_end__max']
|
||||||
return date_max
|
return date_max
|
||||||
|
|
||||||
def is_ban(self):
|
def is_ban(self):
|
||||||
|
@ -228,7 +228,7 @@ class User(AbstractBaseUser):
|
||||||
and not self.is_ban() and (self.is_adherent() or self.is_whitelisted())
|
and not self.is_ban() and (self.is_adherent() or self.is_whitelisted())
|
||||||
|
|
||||||
def user_interfaces(self):
|
def user_interfaces(self):
|
||||||
return Interface.objects.filter(machine=Machine.objects.filter(user=self))
|
return Interface.objects.filter(machine__in=Machine.objects.filter(user=self))
|
||||||
|
|
||||||
def has_module_perms(self, app_label):
|
def has_module_perms(self, app_label):
|
||||||
# Simplest version again
|
# Simplest version again
|
||||||
|
@ -267,7 +267,7 @@ class User(AbstractBaseUser):
|
||||||
if access_refresh:
|
if access_refresh:
|
||||||
user_ldap.dialupAccess = str(self.has_access())
|
user_ldap.dialupAccess = str(self.has_access())
|
||||||
if mac_refresh:
|
if mac_refresh:
|
||||||
user_ldap.macs = [inter.mac_bare() for inter in Interface.objects.filter(machine=Machine.objects.filter(user=self))]
|
user_ldap.macs = [inter.mac_bare() for inter in Interface.objects.filter(machine__in=Machine.objects.filter(user=self))]
|
||||||
user_ldap.save()
|
user_ldap.save()
|
||||||
|
|
||||||
def ldap_del(self):
|
def ldap_del(self):
|
||||||
|
|
Loading…
Reference in a new issue