Premier jet des clubs
On peut inscrire les utilisateurs aux différents clubs du COF. Le formulaire d'inscription est inclus dans la page “inscription d'un nouveau membre”. À réfléchir comment ajouter des infos supplémentaires : chèque des caution, commentaires, etc.
This commit is contained in:
parent
5d685a04d7
commit
c07cf654fb
5 changed files with 91 additions and 12 deletions
|
@ -13,7 +13,7 @@ from django.db.models import Max
|
|||
from django.core.validators import MinLengthValidator
|
||||
|
||||
from gestioncof.models import CofProfile, EventCommentValue, \
|
||||
CalendarSubscription
|
||||
CalendarSubscription, Club
|
||||
from gestioncof.widgets import TriStateCheckbox
|
||||
from gestioncof.shared import lock_table, unlock_table
|
||||
|
||||
|
@ -389,3 +389,14 @@ class CalendarForm(forms.ModelForm):
|
|||
model = CalendarSubscription
|
||||
fields = ['subscribe_to_events', 'subscribe_to_my_shows',
|
||||
'other_shows']
|
||||
|
||||
|
||||
class ClubsForm(forms.Form):
|
||||
"""
|
||||
Formulaire d'inscription d'un membre à plusieurs clubs du COF.
|
||||
"""
|
||||
clubs = forms.ModelMultipleChoiceField(
|
||||
label="Inscriptions aux clubs du COF",
|
||||
queryset=Club.objects.all(),
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
required=False)
|
||||
|
|
47
gestioncof/migrations/0007_alter_club.py
Normal file
47
gestioncof/migrations/0007_alter_club.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('gestioncof', '0006_add_calendar'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='club',
|
||||
name='name',
|
||||
field=models.CharField(unique=True, max_length=200,
|
||||
verbose_name='Nom')
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='club',
|
||||
name='description',
|
||||
field=models.TextField(verbose_name='Description', blank=True)
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='club',
|
||||
name='membres',
|
||||
field=models.ManyToManyField(related_name='clubs',
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
blank=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='club',
|
||||
name='respos',
|
||||
field=models.ManyToManyField(related_name='clubs_geres',
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
blank=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='event',
|
||||
name='start_date',
|
||||
field=models.DateTimeField(null=True,
|
||||
verbose_name='Date de d\xe9but',
|
||||
blank=True),
|
||||
),
|
||||
]
|
|
@ -86,10 +86,11 @@ post_save.connect(create_user_profile, sender=User)
|
|||
|
||||
@python_2_unicode_compatible
|
||||
class Club(models.Model):
|
||||
name = models.CharField("Nom", max_length=200)
|
||||
description = models.TextField("Description")
|
||||
respos = models.ManyToManyField(User, related_name="clubs_geres")
|
||||
membres = models.ManyToManyField(User, related_name="clubs")
|
||||
name = models.CharField("Nom", max_length=200, unique=True)
|
||||
description = models.TextField("Description", blank=True)
|
||||
respos = models.ManyToManyField(User, related_name="clubs_geres",
|
||||
blank=True)
|
||||
membres = models.ManyToManyField(User, related_name="clubs", blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
{{ user_form | bootstrap }}
|
||||
{{ profile_form | bootstrap }}
|
||||
</table>
|
||||
<hr />
|
||||
<table>
|
||||
{{ clubs_form | bootstrap }}
|
||||
</table>
|
||||
{{ event_formset.management_form }}
|
||||
{% for event_form in event_formset %}
|
||||
<hr />
|
||||
|
|
|
@ -29,7 +29,7 @@ from gestioncof.decorators import buro_required, cof_required
|
|||
from gestioncof.forms import UserProfileForm, EventStatusFilterForm, \
|
||||
SurveyForm, SurveyStatusFilterForm, RegistrationUserForm, \
|
||||
RegistrationProfileForm, EventForm, CalendarForm, EventFormset, \
|
||||
RegistrationPassUserForm
|
||||
RegistrationPassUserForm, ClubsForm
|
||||
|
||||
from bda.models import Tirage, Spectacle
|
||||
|
||||
|
@ -341,8 +341,9 @@ def registration_form2(request, login_clipper=None, username=None):
|
|||
profile_form = RegistrationProfileForm(initial={
|
||||
'login_clipper': login_clipper})
|
||||
registration_set_ro_fields(user_form, profile_form)
|
||||
# events
|
||||
# events & clubs
|
||||
event_formset = EventFormset(events=events, prefix='events')
|
||||
clubs_form = ClubsForm(initial={'clubs': member.clubs.all()})
|
||||
if username:
|
||||
member = get_object_or_404(User, username=username)
|
||||
(profile, _) = CofProfile.objects.get_or_create(user=member)
|
||||
|
@ -361,15 +362,20 @@ def registration_form2(request, login_clipper=None, username=None):
|
|||
event_formset = EventFormset(
|
||||
events=events, prefix='events',
|
||||
current_registrations=current_registrations)
|
||||
# Clubs
|
||||
clubs_form = ClubsForm(initial={'clubs': member.clubs.all()})
|
||||
elif not login_clipper:
|
||||
# new user
|
||||
user_form = RegistrationPassUserForm()
|
||||
profile_form = RegistrationProfileForm()
|
||||
event_formset = EventFormset(events=events, prefix='events')
|
||||
clubs_form = ClubsForm()
|
||||
return render(request, "registration_form.html",
|
||||
{"user_form": user_form, "profile_form": profile_form,
|
||||
"member": member, "login_clipper": login_clipper,
|
||||
"event_formset": event_formset})
|
||||
{"member": member, "login_clipper": login_clipper,
|
||||
"user_form": user_form,
|
||||
"profile_form": profile_form,
|
||||
"event_formset": event_formset,
|
||||
"clubs_form": clubs_form})
|
||||
|
||||
|
||||
@buro_required
|
||||
|
@ -392,6 +398,7 @@ def registration(request):
|
|||
else:
|
||||
user_form = RegistrationUserForm
|
||||
profile_form = RegistrationProfileForm(request_dict)
|
||||
clubs_form = ClubsForm(request_dict)
|
||||
events = Event.objects.filter(old=False).all()
|
||||
event_formset = EventFormset(events=events, data=request_dict,
|
||||
prefix='events')
|
||||
|
@ -419,10 +426,13 @@ def registration(request):
|
|||
# Maintenant on remplit le formulaire de profil
|
||||
profile_form = RegistrationProfileForm(request_dict,
|
||||
instance=profile)
|
||||
if profile_form.is_valid() and event_formset.is_valid():
|
||||
if (profile_form.is_valid() and event_formset.is_valid()
|
||||
and clubs_form.is_valid()):
|
||||
# Enregistrement du profil
|
||||
profile = profile_form.save()
|
||||
if profile.is_cof and not was_cof:
|
||||
send_custom_mail(member, "bienvenue")
|
||||
# Enregistrement des inscriptions aux événements
|
||||
for form in event_formset:
|
||||
if 'status' not in form.cleaned_data:
|
||||
form.cleaned_data['status'] = 'no'
|
||||
|
@ -455,6 +465,11 @@ def registration(request):
|
|||
comments = field.default
|
||||
send_custom_mail(member, "mega",
|
||||
{"remarques": comments})
|
||||
# Enregistrement des inscriptions aux clubs
|
||||
member.clubs.clear()
|
||||
for club in clubs_form.cleaned_data['clubs']:
|
||||
club.membres.add(member)
|
||||
club.save()
|
||||
success = True
|
||||
return render(request, "registration_post.html",
|
||||
{"success": success,
|
||||
|
@ -462,7 +477,8 @@ def registration(request):
|
|||
"profile_form": profile_form,
|
||||
"member": member,
|
||||
"login_clipper": login_clipper,
|
||||
"event_formset": event_formset})
|
||||
"event_formset": event_formset,
|
||||
"clubs_form": clubs_form})
|
||||
else:
|
||||
return render(request, "registration.html")
|
||||
|
||||
|
|
Loading…
Reference in a new issue