mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Nettoyage du code (modelform et update) phase1
This commit is contained in:
parent
7f5e4afd64
commit
e29dcbd5e3
5 changed files with 21 additions and 56 deletions
|
@ -102,13 +102,9 @@ class ArticleForm(ModelForm):
|
||||||
super(ArticleForm, self).__init__(*args, **kwargs)
|
super(ArticleForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['name'].label = "Désignation de l'article"
|
self.fields['name'].label = "Désignation de l'article"
|
||||||
|
|
||||||
class DelArticleForm(ModelForm):
|
class DelArticleForm(Form):
|
||||||
articles = forms.ModelMultipleChoiceField(queryset=Article.objects.all(), label="Articles actuels", widget=forms.CheckboxSelectMultiple)
|
articles = forms.ModelMultipleChoiceField(queryset=Article.objects.all(), label="Articles actuels", widget=forms.CheckboxSelectMultiple)
|
||||||
|
|
||||||
class Meta:
|
|
||||||
fields = ['articles']
|
|
||||||
model = Article
|
|
||||||
|
|
||||||
class PaiementForm(ModelForm):
|
class PaiementForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Paiement
|
model = Paiement
|
||||||
|
@ -119,13 +115,9 @@ class PaiementForm(ModelForm):
|
||||||
self.fields['moyen'].label = 'Moyen de paiement à ajouter'
|
self.fields['moyen'].label = 'Moyen de paiement à ajouter'
|
||||||
self.fields['type_paiement'].label = 'Type de paiement à ajouter'
|
self.fields['type_paiement'].label = 'Type de paiement à ajouter'
|
||||||
|
|
||||||
class DelPaiementForm(ModelForm):
|
class DelPaiementForm(Form):
|
||||||
paiements = forms.ModelMultipleChoiceField(queryset=Paiement.objects.all(), label="Moyens de paiement actuels", widget=forms.CheckboxSelectMultiple)
|
paiements = forms.ModelMultipleChoiceField(queryset=Paiement.objects.all(), label="Moyens de paiement actuels", widget=forms.CheckboxSelectMultiple)
|
||||||
|
|
||||||
class Meta:
|
|
||||||
exclude = ['moyen']
|
|
||||||
model = Paiement
|
|
||||||
|
|
||||||
class BanqueForm(ModelForm):
|
class BanqueForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Banque
|
model = Banque
|
||||||
|
@ -135,9 +127,5 @@ class BanqueForm(ModelForm):
|
||||||
super(BanqueForm, self).__init__(*args, **kwargs)
|
super(BanqueForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['name'].label = 'Banque à ajouter'
|
self.fields['name'].label = 'Banque à ajouter'
|
||||||
|
|
||||||
class DelBanqueForm(ModelForm):
|
class DelBanqueForm(Form):
|
||||||
banques = forms.ModelMultipleChoiceField(queryset=Banque.objects.all(), label="Banques actuelles", widget=forms.CheckboxSelectMultiple)
|
banques = forms.ModelMultipleChoiceField(queryset=Banque.objects.all(), label="Banques actuelles", widget=forms.CheckboxSelectMultiple)
|
||||||
|
|
||||||
class Meta:
|
|
||||||
exclude = ['name']
|
|
||||||
model = Banque
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ class DomainForm(AliasForm):
|
||||||
kwargs['initial'] = initial
|
kwargs['initial'] = initial
|
||||||
super(DomainForm, self).__init__(*args, **kwargs)
|
super(DomainForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
class DelAliasForm(ModelForm):
|
class DelAliasForm(Form):
|
||||||
alias = forms.ModelMultipleChoiceField(queryset=Domain.objects.all(), label="Alias actuels", widget=forms.CheckboxSelectMultiple)
|
alias = forms.ModelMultipleChoiceField(queryset=Domain.objects.all(), label="Alias actuels", widget=forms.CheckboxSelectMultiple)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -127,10 +127,6 @@ class DelAliasForm(ModelForm):
|
||||||
super(DelAliasForm, self).__init__(*args, **kwargs)
|
super(DelAliasForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['alias'].queryset = Domain.objects.filter(cname__in=Domain.objects.filter(interface_parent=interface))
|
self.fields['alias'].queryset = Domain.objects.filter(cname__in=Domain.objects.filter(interface_parent=interface))
|
||||||
|
|
||||||
class Meta:
|
|
||||||
exclude = ['interface_parent', 'name', 'extension', 'cname']
|
|
||||||
model = Domain
|
|
||||||
|
|
||||||
class MachineTypeForm(ModelForm):
|
class MachineTypeForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MachineType
|
model = MachineType
|
||||||
|
@ -170,13 +166,9 @@ class ExtensionForm(ModelForm):
|
||||||
self.fields['name'].label = 'Extension à ajouter'
|
self.fields['name'].label = 'Extension à ajouter'
|
||||||
self.fields['origin'].label = 'Enregistrement A origin'
|
self.fields['origin'].label = 'Enregistrement A origin'
|
||||||
|
|
||||||
class DelExtensionForm(ModelForm):
|
class DelExtensionForm(Form):
|
||||||
extensions = forms.ModelMultipleChoiceField(queryset=Extension.objects.all(), label="Extensions actuelles", widget=forms.CheckboxSelectMultiple)
|
extensions = forms.ModelMultipleChoiceField(queryset=Extension.objects.all(), label="Extensions actuelles", widget=forms.CheckboxSelectMultiple)
|
||||||
|
|
||||||
class Meta:
|
|
||||||
exclude = ['name', 'need_infra', 'origin']
|
|
||||||
model = Extension
|
|
||||||
|
|
||||||
class MxForm(ModelForm):
|
class MxForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Mx
|
model = Mx
|
||||||
|
|
|
@ -281,17 +281,15 @@ class Service(models.Model):
|
||||||
|
|
||||||
def ask_regen(self):
|
def ask_regen(self):
|
||||||
""" Marque à True la demande de régénération pour un service x """
|
""" Marque à True la demande de régénération pour un service x """
|
||||||
for serv in Service_link.objects.filter(service=self).exclude(asked_regen=True):
|
Service_link.objects.filter(service=self).exclude(asked_regen=True).update(asked_regen=True)
|
||||||
serv.asked_regen = True
|
return
|
||||||
serv.save()
|
|
||||||
|
|
||||||
def process_link(self, servers):
|
def process_link(self, servers):
|
||||||
""" Django ne peut créer lui meme les relations manytomany avec table intermediaire explicite"""
|
""" Django ne peut créer lui meme les relations manytomany avec table intermediaire explicite"""
|
||||||
for serv in servers.exclude(pk__in=Interface.objects.filter(service=self)):
|
for serv in servers.exclude(pk__in=Interface.objects.filter(service=self)):
|
||||||
link = Service_link(service=self, server=serv)
|
link = Service_link(service=self, server=serv)
|
||||||
link.save()
|
link.save()
|
||||||
for serv in Service_link.objects.filter(service=self).exclude(server__in=servers):
|
Service_link.objects.filter(service=self).exclude(server__in=servers).delete()
|
||||||
serv.delete()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
|
|
@ -257,21 +257,12 @@ class NewListRightForm(ListRightForm):
|
||||||
super(NewListRightForm, self).__init__(*args, **kwargs)
|
super(NewListRightForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['gid'].label = 'Gid, attention, cet attribut ne doit pas être modifié après création'
|
self.fields['gid'].label = 'Gid, attention, cet attribut ne doit pas être modifié après création'
|
||||||
|
|
||||||
class DelListRightForm(ModelForm):
|
class DelListRightForm(Form):
|
||||||
listrights = forms.ModelMultipleChoiceField(queryset=ListRight.objects.all(), label="Droits actuels", widget=forms.CheckboxSelectMultiple)
|
listrights = forms.ModelMultipleChoiceField(queryset=ListRight.objects.all(), label="Droits actuels", widget=forms.CheckboxSelectMultiple)
|
||||||
|
|
||||||
class Meta:
|
class DelSchoolForm(Form):
|
||||||
exclude = ['listright','gid','details']
|
|
||||||
model = ListRight
|
|
||||||
|
|
||||||
class DelSchoolForm(ModelForm):
|
|
||||||
schools = forms.ModelMultipleChoiceField(queryset=School.objects.all(), label="Etablissements actuels", widget=forms.CheckboxSelectMultiple)
|
schools = forms.ModelMultipleChoiceField(queryset=School.objects.all(), label="Etablissements actuels", widget=forms.CheckboxSelectMultiple)
|
||||||
|
|
||||||
class Meta:
|
|
||||||
exclude = ['name']
|
|
||||||
model = School
|
|
||||||
|
|
||||||
|
|
||||||
class RightForm(ModelForm):
|
class RightForm(ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(RightForm, self).__init__(*args, **kwargs)
|
super(RightForm, self).__init__(*args, **kwargs)
|
||||||
|
@ -283,19 +274,13 @@ class RightForm(ModelForm):
|
||||||
fields = ['right']
|
fields = ['right']
|
||||||
|
|
||||||
|
|
||||||
class DelRightForm(ModelForm):
|
class DelRightForm(Form):
|
||||||
rights = forms.ModelMultipleChoiceField(queryset=Right.objects.all(), widget=forms.CheckboxSelectMultiple)
|
rights = forms.ModelMultipleChoiceField(queryset=Right.objects.all(), widget=forms.CheckboxSelectMultiple)
|
||||||
|
|
||||||
def __init__(self, right, *args, **kwargs):
|
def __init__(self, right, *args, **kwargs):
|
||||||
super(DelRightForm, self).__init__(*args, **kwargs)
|
super(DelRightForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['rights'].queryset = Right.objects.filter(right=right)
|
self.fields['rights'].queryset = Right.objects.filter(right=right)
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Right
|
|
||||||
exclude = ['user', 'right']
|
|
||||||
|
|
||||||
|
|
||||||
class BanForm(ModelForm):
|
class BanForm(ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(BanForm, self).__init__(*args, **kwargs)
|
super(BanForm, self).__init__(*args, **kwargs)
|
||||||
|
|
|
@ -46,6 +46,8 @@ from cotisations.models import Cotisation, Facture, Paiement, Vente
|
||||||
from machines.models import Interface, Machine
|
from machines.models import Interface, Machine
|
||||||
from preferences.models import OptionalUser
|
from preferences.models import OptionalUser
|
||||||
|
|
||||||
|
now = timezone.now()
|
||||||
|
|
||||||
def remove_user_room(room):
|
def remove_user_room(room):
|
||||||
""" Déménage de force l'ancien locataire de la chambre """
|
""" Déménage de force l'ancien locataire de la chambre """
|
||||||
try:
|
try:
|
||||||
|
@ -93,17 +95,17 @@ def get_admin_right():
|
||||||
admin_right.save()
|
admin_right.save()
|
||||||
return admin_right
|
return admin_right
|
||||||
|
|
||||||
def all_adherent():
|
def all_adherent(search_time=now):
|
||||||
return User.objects.filter(facture__in=Facture.objects.filter(vente__in=Vente.objects.filter(cotisation__in=Cotisation.objects.filter(vente__in=Vente.objects.filter(facture__in=Facture.objects.all().exclude(valid=False))).filter(date_end__gt=timezone.now())))).distinct()
|
return User.objects.filter(facture__in=Facture.objects.filter(vente__in=Vente.objects.filter(cotisation__in=Cotisation.objects.filter(vente__in=Vente.objects.filter(facture__in=Facture.objects.all().exclude(valid=False))).filter(date_end__gt=search_time)))).distinct()
|
||||||
|
|
||||||
def all_baned():
|
def all_baned(search_time=now):
|
||||||
return User.objects.filter(ban__in=Ban.objects.filter(date_end__gt=timezone.now())).distinct()
|
return User.objects.filter(ban__in=Ban.objects.filter(date_end__gt=search_time)).distinct()
|
||||||
|
|
||||||
def all_whitelisted():
|
def all_whitelisted(search_time=now):
|
||||||
return User.objects.filter(whitelist__in=Whitelist.objects.filter(date_end__gt=timezone.now())).distinct()
|
return User.objects.filter(whitelist__in=Whitelist.objects.filter(date_end__gt=search_time)).distinct()
|
||||||
|
|
||||||
def all_has_access():
|
def all_has_access(search_time=now):
|
||||||
return User.objects.filter(Q(state=User.STATE_ACTIVE) & ~Q(ban__in=Ban.objects.filter(date_end__gt=timezone.now())) & (Q(whitelist__in=Whitelist.objects.filter(date_end__gt=timezone.now())) | Q(facture__in=Facture.objects.filter(vente__in=Vente.objects.filter(cotisation__in=Cotisation.objects.filter(vente__in=Vente.objects.filter(facture__in=Facture.objects.all().exclude(valid=False))).filter(date_end__gt=timezone.now())))))).distinct()
|
return User.objects.filter(Q(state=User.STATE_ACTIVE) & ~Q(ban__in=Ban.objects.filter(date_end__gt=timezone.now())) & (Q(whitelist__in=Whitelist.objects.filter(date_end__gt=timezone.now())) | Q(facture__in=Facture.objects.filter(vente__in=Vente.objects.filter(cotisation__in=Cotisation.objects.filter(vente__in=Vente.objects.filter(facture__in=Facture.objects.all().exclude(valid=False))).filter(date_end__gt=search_time)))))).distinct()
|
||||||
|
|
||||||
class UserManager(BaseUserManager):
|
class UserManager(BaseUserManager):
|
||||||
def _create_user(self, pseudo, name, surname, email, password=None, su=False):
|
def _create_user(self, pseudo, name, surname, email, password=None, su=False):
|
||||||
|
|
Loading…
Reference in a new issue