Fix the registration forms
- The former `RegistrationUserProfileForm` is splitted in two. - There is a new form: `RegistrationCofProfileForm`
This commit is contained in:
parent
58d708b791
commit
b639c04549
4 changed files with 60 additions and 42 deletions
50
cof/forms.py
50
cof/forms.py
|
@ -17,6 +17,8 @@ from .models import CofProfile, EventCommentValue, \
|
||||||
from .widgets import TriStateCheckbox
|
from .widgets import TriStateCheckbox
|
||||||
from .shared import lock_table, unlock_table
|
from .shared import lock_table, unlock_table
|
||||||
|
|
||||||
|
from gestion.models import Profile
|
||||||
|
|
||||||
from bda.models import Spectacle
|
from bda.models import Spectacle
|
||||||
|
|
||||||
|
|
||||||
|
@ -216,30 +218,21 @@ class RegistrationPassUserForm(RegistrationUserForm):
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
class RegistrationProfileForm(forms.ModelForm):
|
class RegistrationCofProfileForm(forms.ModelForm):
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kwargs):
|
||||||
super(RegistrationProfileForm, self).__init__(*args, **kw)
|
super(RegistrationCofProfileForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['mailing_cof'].initial = True
|
|
||||||
self.fields['mailing_bda'].initial = True
|
|
||||||
self.fields['mailing_bda_revente'].initial = True
|
|
||||||
self.fields['num'].widget.attrs['readonly'] = True
|
self.fields['num'].widget.attrs['readonly'] = True
|
||||||
|
|
||||||
self.fields.keyOrder = [
|
class Meta:
|
||||||
'login_clipper',
|
model = CofProfile
|
||||||
'phone',
|
fields = [
|
||||||
'occupation',
|
"num", "type_cotiz", "is_cof", "is_buro",
|
||||||
'departement',
|
"mailing", "mailing_bda", "mailing_bda_revente",
|
||||||
'is_cof',
|
"petits_cours_accept", "petits_cours_remarques"
|
||||||
'num',
|
]
|
||||||
'type_cotiz',
|
|
||||||
'mailing_cof',
|
|
||||||
'mailing_bda',
|
|
||||||
'mailing_bda_revente',
|
|
||||||
'comments'
|
|
||||||
]
|
|
||||||
|
|
||||||
def save(self, *args, **kw):
|
def save(self, *args, **kw):
|
||||||
instance = super(RegistrationProfileForm, self).save(*args, **kw)
|
instance = super(RegistrationCofProfileForm, self).save(*args, **kw)
|
||||||
if instance.is_cof and not instance.num:
|
if instance.is_cof and not instance.num:
|
||||||
# Generate new number
|
# Generate new number
|
||||||
try:
|
try:
|
||||||
|
@ -253,11 +246,20 @@ class RegistrationProfileForm(forms.ModelForm):
|
||||||
unlock_table(CofProfile)
|
unlock_table(CofProfile)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
class RegistrationProfileForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CofProfile
|
model = Profile
|
||||||
fields = ("login_clipper", "num", "phone", "occupation",
|
fields = [
|
||||||
"departement", "is_cof", "type_cotiz", "mailing_cof",
|
"login_clipper", "phone", "occupation", "departement", "comments"
|
||||||
"mailing_bda", "mailing_bda_revente", "comments")
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class RegistrationUserForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = ["first_name", "last_name"]
|
||||||
|
|
||||||
|
|
||||||
STATUS_CHOICES = (('no', 'Non'),
|
STATUS_CHOICES = (('no', 'Non'),
|
||||||
('wait', 'Oui mais attente paiement'),
|
('wait', 'Oui mais attente paiement'),
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
</table>
|
</table>
|
||||||
<hr />
|
<hr />
|
||||||
<table>
|
<table>
|
||||||
|
{{ cofprofile_form | bootstrap }}
|
||||||
{{ clubs_form | bootstrap }}
|
{{ clubs_form | bootstrap }}
|
||||||
</table>
|
</table>
|
||||||
{{ event_formset.management_form }}
|
{{ event_formset.management_form }}
|
||||||
|
|
46
cof/views.py
46
cof/views.py
|
@ -27,13 +27,16 @@ from .models import EventCommentField, EventCommentValue, \
|
||||||
from .shared import send_custom_mail
|
from .shared import send_custom_mail
|
||||||
from .models import CofProfile, Clipper, Club
|
from .models import CofProfile, Clipper, Club
|
||||||
from .decorators import buro_required, cof_required
|
from .decorators import buro_required, cof_required
|
||||||
from .forms import UserProfileForm, EventStatusFilterForm, \
|
from .forms import (
|
||||||
SurveyForm, SurveyStatusFilterForm, RegistrationUserForm, \
|
EventStatusFilterForm, SurveyForm, SurveyStatusFilterForm,
|
||||||
RegistrationProfileForm, EventForm, CalendarForm, EventFormset, \
|
RegistrationUserForm, RegistrationProfileForm, RegistrationCofProfileForm,
|
||||||
RegistrationPassUserForm, ClubsForm
|
EventForm, CalendarForm, EventFormset, RegistrationPassUserForm, ClubsForm
|
||||||
|
)
|
||||||
|
|
||||||
from bda.models import Tirage, Spectacle
|
from bda.models import Tirage, Spectacle
|
||||||
|
|
||||||
|
from gestion.models import Profile
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def home(request):
|
def home(request):
|
||||||
|
@ -331,16 +334,20 @@ def registration_form2(request, login_clipper=None, username=None):
|
||||||
# profile
|
# profile
|
||||||
profile_form = RegistrationProfileForm(initial={
|
profile_form = RegistrationProfileForm(initial={
|
||||||
'login_clipper': login_clipper})
|
'login_clipper': login_clipper})
|
||||||
|
# COF - profile
|
||||||
|
cofprofile_form = RegistrationCofProfileForm()
|
||||||
registration_set_ro_fields(user_form, profile_form)
|
registration_set_ro_fields(user_form, profile_form)
|
||||||
# events & clubs
|
# events & clubs
|
||||||
event_formset = EventFormset(events=events, prefix='events')
|
event_formset = EventFormset(events=events, prefix='events')
|
||||||
clubs_form = ClubsForm()
|
clubs_form = ClubsForm()
|
||||||
if username:
|
if username:
|
||||||
member = get_object_or_404(User, username=username)
|
member = get_object_or_404(User, username=username)
|
||||||
(profile, _) = CofProfile.objects.get_or_create(user=member)
|
(profile, _) = Profile.objects.get_or_create(user=member)
|
||||||
|
(cofprofile, _) = CofProfile.objects.get_or_create(profile=profile)
|
||||||
# already existing, prefill
|
# already existing, prefill
|
||||||
user_form = RegistrationUserForm(instance=member)
|
user_form = RegistrationUserForm(instance=member)
|
||||||
profile_form = RegistrationProfileForm(instance=profile)
|
profile_form = RegistrationProfileForm(instance=profile)
|
||||||
|
cofprofile_form = RegistrationCofProfileForm(instance=cofprofile)
|
||||||
registration_set_ro_fields(user_form, profile_form)
|
registration_set_ro_fields(user_form, profile_form)
|
||||||
# events
|
# events
|
||||||
current_registrations = []
|
current_registrations = []
|
||||||
|
@ -360,12 +367,14 @@ def registration_form2(request, login_clipper=None, username=None):
|
||||||
user_form = RegistrationPassUserForm()
|
user_form = RegistrationPassUserForm()
|
||||||
user_form.force_long_username()
|
user_form.force_long_username()
|
||||||
profile_form = RegistrationProfileForm()
|
profile_form = RegistrationProfileForm()
|
||||||
|
cofprofile_form = RegistrationCofProfileForm()
|
||||||
event_formset = EventFormset(events=events, prefix='events')
|
event_formset = EventFormset(events=events, prefix='events')
|
||||||
clubs_form = ClubsForm()
|
clubs_form = ClubsForm()
|
||||||
return render(request, "registration_form.html",
|
return render(request, "registration_form.html",
|
||||||
{"member": member, "login_clipper": login_clipper,
|
{"member": member, "login_clipper": login_clipper,
|
||||||
"user_form": user_form,
|
"user_form": user_form,
|
||||||
"profile_form": profile_form,
|
"profile_form": profile_form,
|
||||||
|
"cofprofile_form": cofprofile_form,
|
||||||
"event_formset": event_formset,
|
"event_formset": event_formset,
|
||||||
"clubs_form": clubs_form})
|
"clubs_form": clubs_form})
|
||||||
|
|
||||||
|
@ -414,17 +423,25 @@ def registration(request):
|
||||||
|
|
||||||
if user_form.is_valid():
|
if user_form.is_valid():
|
||||||
member = user_form.save()
|
member = user_form.save()
|
||||||
profile, _ = CofProfile.objects.get_or_create(user=member)
|
cofprofile, _ = CofProfile.objects.get_or_create(user=member)
|
||||||
was_cof = profile.is_cof
|
was_cof = cofprofile.is_cof
|
||||||
request_dict["num"] = profile.num
|
request_dict["num"] = cofprofile.num
|
||||||
# Maintenant on remplit le formulaire de profil
|
# Maintenant on remplit le formulaire de profil
|
||||||
profile_form = RegistrationProfileForm(request_dict,
|
cofprofile_form = RegistrationCofProfileForm(
|
||||||
instance=profile)
|
request_dict,
|
||||||
if (profile_form.is_valid() and event_formset.is_valid()
|
instance=cofprofile
|
||||||
and clubs_form.is_valid()):
|
)
|
||||||
|
forms_are_valid = all(
|
||||||
|
profile_form.is_valid(),
|
||||||
|
cofprofile_form.is_valid(),
|
||||||
|
event_formset.is_valid(),
|
||||||
|
clubs_form.is_valid()
|
||||||
|
)
|
||||||
|
if forms_are_valid:
|
||||||
# Enregistrement du profil
|
# Enregistrement du profil
|
||||||
profile = profile_form.save()
|
profile_form.save()
|
||||||
if profile.is_cof and not was_cof:
|
cofprofile = cofprofile_form.save()
|
||||||
|
if cofprofile.is_cof and not was_cof:
|
||||||
send_custom_mail(member, "bienvenue")
|
send_custom_mail(member, "bienvenue")
|
||||||
# Enregistrement des inscriptions aux événements
|
# Enregistrement des inscriptions aux événements
|
||||||
for form in event_formset:
|
for form in event_formset:
|
||||||
|
@ -469,6 +486,7 @@ def registration(request):
|
||||||
{"success": success,
|
{"success": success,
|
||||||
"user_form": user_form,
|
"user_form": user_form,
|
||||||
"profile_form": profile_form,
|
"profile_form": profile_form,
|
||||||
|
"cofprofile_form": cofprofile_form,
|
||||||
"member": member,
|
"member": member,
|
||||||
"login_clipper": login_clipper,
|
"login_clipper": login_clipper,
|
||||||
"event_formset": event_formset,
|
"event_formset": event_formset,
|
||||||
|
|
|
@ -10,10 +10,7 @@ class UserForm(forms.ModelForm):
|
||||||
fields = ["first_name", "last_name"]
|
fields = ["first_name", "last_name"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ProfileForm(forms.ModelForm):
|
class ProfileForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CofProfile
|
model = Profile
|
||||||
fields = ["phone", "departement"]
|
fields = ["phone", "departement"]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue