mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Nettoyage du code (modelform et update) phase1
This commit is contained in:
parent
2b373cdcf0
commit
420e884e9b
5 changed files with 21 additions and 56 deletions
|
@ -102,13 +102,9 @@ class ArticleForm(ModelForm):
|
|||
super(ArticleForm, self).__init__(*args, **kwargs)
|
||||
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)
|
||||
|
||||
class Meta:
|
||||
fields = ['articles']
|
||||
model = Article
|
||||
|
||||
class PaiementForm(ModelForm):
|
||||
class Meta:
|
||||
model = Paiement
|
||||
|
@ -119,13 +115,9 @@ class PaiementForm(ModelForm):
|
|||
self.fields['moyen'].label = 'Moyen 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)
|
||||
|
||||
class Meta:
|
||||
exclude = ['moyen']
|
||||
model = Paiement
|
||||
|
||||
class BanqueForm(ModelForm):
|
||||
class Meta:
|
||||
model = Banque
|
||||
|
@ -135,9 +127,5 @@ class BanqueForm(ModelForm):
|
|||
super(BanqueForm, self).__init__(*args, **kwargs)
|
||||
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)
|
||||
|
||||
class Meta:
|
||||
exclude = ['name']
|
||||
model = Banque
|
||||
|
|
|
@ -119,7 +119,7 @@ class DomainForm(AliasForm):
|
|||
kwargs['initial'] = initial
|
||||
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)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -127,10 +127,6 @@ class DelAliasForm(ModelForm):
|
|||
super(DelAliasForm, self).__init__(*args, **kwargs)
|
||||
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 Meta:
|
||||
model = MachineType
|
||||
|
@ -170,13 +166,9 @@ class ExtensionForm(ModelForm):
|
|||
self.fields['name'].label = 'Extension à ajouter'
|
||||
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)
|
||||
|
||||
class Meta:
|
||||
exclude = ['name', 'need_infra', 'origin']
|
||||
model = Extension
|
||||
|
||||
class MxForm(ModelForm):
|
||||
class Meta:
|
||||
model = Mx
|
||||
|
|
|
@ -281,17 +281,15 @@ class Service(models.Model):
|
|||
|
||||
def ask_regen(self):
|
||||
""" 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):
|
||||
serv.asked_regen = True
|
||||
serv.save()
|
||||
Service_link.objects.filter(service=self).exclude(asked_regen=True).update(asked_regen=True)
|
||||
return
|
||||
|
||||
def process_link(self, servers):
|
||||
""" 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)):
|
||||
link = Service_link(service=self, server=serv)
|
||||
link.save()
|
||||
for serv in Service_link.objects.filter(service=self).exclude(server__in=servers):
|
||||
serv.delete()
|
||||
Service_link.objects.filter(service=self).exclude(server__in=servers).delete()
|
||||
return
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
|
|
@ -257,21 +257,12 @@ class NewListRightForm(ListRightForm):
|
|||
super(NewListRightForm, self).__init__(*args, **kwargs)
|
||||
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)
|
||||
|
||||
class Meta:
|
||||
exclude = ['listright','gid','details']
|
||||
model = ListRight
|
||||
|
||||
class DelSchoolForm(ModelForm):
|
||||
class DelSchoolForm(Form):
|
||||
schools = forms.ModelMultipleChoiceField(queryset=School.objects.all(), label="Etablissements actuels", widget=forms.CheckboxSelectMultiple)
|
||||
|
||||
class Meta:
|
||||
exclude = ['name']
|
||||
model = School
|
||||
|
||||
|
||||
class RightForm(ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RightForm, self).__init__(*args, **kwargs)
|
||||
|
@ -283,19 +274,13 @@ class RightForm(ModelForm):
|
|||
fields = ['right']
|
||||
|
||||
|
||||
class DelRightForm(ModelForm):
|
||||
class DelRightForm(Form):
|
||||
rights = forms.ModelMultipleChoiceField(queryset=Right.objects.all(), widget=forms.CheckboxSelectMultiple)
|
||||
|
||||
def __init__(self, right, *args, **kwargs):
|
||||
super(DelRightForm, self).__init__(*args, **kwargs)
|
||||
self.fields['rights'].queryset = Right.objects.filter(right=right)
|
||||
|
||||
|
||||
class Meta:
|
||||
model = Right
|
||||
exclude = ['user', 'right']
|
||||
|
||||
|
||||
class BanForm(ModelForm):
|
||||
def __init__(self, *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 preferences.models import OptionalUser
|
||||
|
||||
now = timezone.now()
|
||||
|
||||
def remove_user_room(room):
|
||||
""" Déménage de force l'ancien locataire de la chambre """
|
||||
try:
|
||||
|
@ -93,17 +95,17 @@ def get_admin_right():
|
|||
admin_right.save()
|
||||
return admin_right
|
||||
|
||||
def all_adherent():
|
||||
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()
|
||||
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=search_time)))).distinct()
|
||||
|
||||
def all_baned():
|
||||
return User.objects.filter(ban__in=Ban.objects.filter(date_end__gt=timezone.now())).distinct()
|
||||
def all_baned(search_time=now):
|
||||
return User.objects.filter(ban__in=Ban.objects.filter(date_end__gt=search_time)).distinct()
|
||||
|
||||
def all_whitelisted():
|
||||
return User.objects.filter(whitelist__in=Whitelist.objects.filter(date_end__gt=timezone.now())).distinct()
|
||||
def all_whitelisted(search_time=now):
|
||||
return User.objects.filter(whitelist__in=Whitelist.objects.filter(date_end__gt=search_time)).distinct()
|
||||
|
||||
def all_has_access():
|
||||
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()
|
||||
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=search_time)))))).distinct()
|
||||
|
||||
class UserManager(BaseUserManager):
|
||||
def _create_user(self, pseudo, name, surname, email, password=None, su=False):
|
||||
|
|
Loading…
Reference in a new issue