From 6b7b20d2792d5d936711117c5b09e18aa791f19a Mon Sep 17 00:00:00 2001 From: Med Date: Thu, 6 Jul 2017 17:41:10 +0200 Subject: [PATCH] Menage --- users/forms.py | 88 ++++++++++++++++++++++++++++++++++++++++++++++++- users/models.py | 86 ----------------------------------------------- users/views.py | 5 +-- 3 files changed, 90 insertions(+), 89 deletions(-) diff --git a/users/forms.py b/users/forms.py index dd4ad03..fc393ed 100644 --- a/users/forms.py +++ b/users/forms.py @@ -24,11 +24,12 @@ from django import forms +from django.forms import ModelForm, Form from django.contrib.auth.forms import ReadOnlyPasswordHashField from django.core.validators import MinLengthValidator from django.utils import timezone -from .models import User +from .models import Adhesion, Clef, ListRight, Right, Request, User class PassForm(forms.Form): passwd1 = forms.CharField(label=u'Nouveau mot de passe', max_length=255, validators=[MinLengthValidator(8)], widget=forms.PasswordInput) @@ -98,3 +99,88 @@ class ResetPasswordForm(forms.Form): pseudo = forms.CharField(label=u'Pseudo', max_length=255) email = forms.EmailField(max_length=255) +class BaseInfoForm(ModelForm): + def __init__(self, *args, **kwargs): + super(BaseInfoForm, self).__init__(*args, **kwargs) + self.fields['name'].label = 'Prénom' + self.fields['surname'].label = 'Nom' + #self.fields['comment'].label = 'Commentaire' + + class Meta: + model = User + fields = [ + 'name', + 'pseudo', + 'surname', + 'email', + 'telephone', + 'adresse', + ] + +class InfoForm(BaseInfoForm): + class Meta(BaseInfoForm.Meta): + fields = [ + 'name', + 'pseudo', + 'surname', + 'email', + 'telephone', + 'adresse', + 'maxemprunt', + ] + + +class PasswordForm(ModelForm): + class Meta: + model = User + fields = ['password'] + +class StateForm(ModelForm): + class Meta: + model = User + fields = ['state'] + +class ClefForm(ModelForm): + class Meta: + model = Clef + fields = '__all__' + +class AdhesionForm(ModelForm): + adherent = forms.ModelMultipleChoiceField(User.objects.all(), widget=forms.CheckboxSelectMultiple, required=False) + + class Meta: + model = Adhesion + fields = '__all__' + +class RightForm(ModelForm): + def __init__(self, *args, **kwargs): + super(RightForm, self).__init__(*args, **kwargs) + self.fields['right'].label = 'Droit' + self.fields['right'].empty_label = "Choisir un nouveau droit" + + class Meta: + model = Right + fields = ['right'] + + +class DelRightForm(Form): + rights = forms.ModelMultipleChoiceField(queryset=Right.objects.all(), label="Droits actuels", widget=forms.CheckboxSelectMultiple) + + +class ListRightForm(ModelForm): + class Meta: + model = ListRight + fields = ['listright', 'details'] + + def __init__(self, *args, **kwargs): + super(ListRightForm, self).__init__(*args, **kwargs) + self.fields['listright'].label = 'Nom du droit/groupe' + +class NewListRightForm(ListRightForm): + class Meta(ListRightForm.Meta): + fields = '__all__' + +class DelListRightForm(Form): + listrights = forms.ModelMultipleChoiceField(queryset=ListRight.objects.all(), label="Droits actuels", widget=forms.CheckboxSelectMultiple) + + diff --git a/users/models.py b/users/models.py index c28bae9..0baa68f 100644 --- a/users/models.py +++ b/users/models.py @@ -22,8 +22,6 @@ from django.db import models from django.db.models import Q -from django.forms import ModelForm, Form -from django import forms from django.db.models.signals import post_save, post_delete from django.dispatch import receiver from django.utils.functional import cached_property @@ -222,88 +220,4 @@ class Adhesion(models.Model): annee_fin = models.IntegerField(unique=True) adherent = models.ManyToManyField('User', blank=True) -class BaseInfoForm(ModelForm): - def __init__(self, *args, **kwargs): - super(BaseInfoForm, self).__init__(*args, **kwargs) - self.fields['name'].label = 'Prénom' - self.fields['surname'].label = 'Nom' - #self.fields['comment'].label = 'Commentaire' - - class Meta: - model = User - fields = [ - 'name', - 'pseudo', - 'surname', - 'email', - 'telephone', - 'adresse', - ] - -class InfoForm(BaseInfoForm): - class Meta(BaseInfoForm.Meta): - fields = [ - 'name', - 'pseudo', - 'surname', - 'email', - 'telephone', - 'adresse', - 'maxemprunt', - ] - - -class PasswordForm(ModelForm): - class Meta: - model = User - fields = ['password'] - -class StateForm(ModelForm): - class Meta: - model = User - fields = ['state'] - -class ClefForm(ModelForm): - class Meta: - model = Clef - fields = '__all__' - -class AdhesionForm(ModelForm): - adherent = forms.ModelMultipleChoiceField(User.objects.all(), widget=forms.CheckboxSelectMultiple, required=False) - - class Meta: - model = Adhesion - fields = '__all__' - -class RightForm(ModelForm): - def __init__(self, *args, **kwargs): - super(RightForm, self).__init__(*args, **kwargs) - self.fields['right'].label = 'Droit' - self.fields['right'].empty_label = "Choisir un nouveau droit" - - class Meta: - model = Right - fields = ['right'] - - -class DelRightForm(Form): - rights = forms.ModelMultipleChoiceField(queryset=Right.objects.all(), label="Droits actuels", widget=forms.CheckboxSelectMultiple) - - -class ListRightForm(ModelForm): - class Meta: - model = ListRight - fields = ['listright', 'details'] - - def __init__(self, *args, **kwargs): - super(ListRightForm, self).__init__(*args, **kwargs) - self.fields['listright'].label = 'Nom du droit/groupe' - -class NewListRightForm(ListRightForm): - class Meta(ListRightForm.Meta): - fields = '__all__' - -class DelListRightForm(Form): - listrights = forms.ModelMultipleChoiceField(queryset=ListRight.objects.all(), label="Droits actuels", widget=forms.CheckboxSelectMultiple) - diff --git a/users/views.py b/users/views.py index ff7094a..f4de0b5 100644 --- a/users/views.py +++ b/users/views.py @@ -39,8 +39,9 @@ from django.db import transaction from reversion.models import Version from reversion import revisions as reversion -from users.models import User, Request, ListRight, Right, DelListRightForm, NewListRightForm, ListRightForm, RightForm, DelRightForm -from users.models import InfoForm, BaseInfoForm, StateForm, Clef, ClefForm, Adhesion, AdhesionForm +from users.forms import DelListRightForm, NewListRightForm, ListRightForm, RightForm, DelRightForm +from users.forms import InfoForm, BaseInfoForm, StateForm, ClefForm, AdhesionForm +from users.models import User, Request, ListRight, Right, Clef, Adhesion from users.forms import PassForm, ResetPasswordForm from media.models import Emprunt