From 0de800ae61605acdc035bf6e47c069c685b7190a Mon Sep 17 00:00:00 2001 From: davy39 Date: Thu, 10 Feb 2022 11:49:49 +0100 Subject: [PATCH] Ajout troubles cognitifes --- inscription/forms.py | 32 +++++++++++++++---- inscription/models.py | 21 ++++++------ inscription/urls.py | 3 +- inscription/views.py | 11 ++++++- static/css/custom-dark.css | 9 ++++++ .../inscription/formulaire_inscription.html | 22 ++++++++++--- 6 files changed, 75 insertions(+), 23 deletions(-) diff --git a/inscription/forms.py b/inscription/forms.py index 918c0a7..a80dfd6 100644 --- a/inscription/forms.py +++ b/inscription/forms.py @@ -1,11 +1,9 @@ from django import forms from django.utils.translation import gettext_lazy as _ -from crispy_forms.bootstrap import FormActions, InlineField, InlineCheckboxes, FieldWithButtons, StrictButton +from crispy_forms.bootstrap import FormActions, InlineField, FieldWithButtons, StrictButton from crispy_forms.helper import FormHelper from crispy_forms.layout import Div, Fieldset, Layout, Submit, Field - -import inscription.models -from .models import BaseEleve, Allergie +from .models import BaseEleve, Allergie, TroubleCognitif, Spe from .utils import CaptchaWizardField # Pour l'autocomplétion de la commune en fonction du département choisi from dal import autocomplete @@ -229,8 +227,17 @@ class InscriptionForm3(forms.ModelForm): allergie = forms.ModelMultipleChoiceField( queryset=Allergie.objects.all(), widget=forms.CheckboxSelectMultiple, - required=False + required=False, + label="Allergies" + ) + dys = forms.ModelMultipleChoiceField( + queryset=TroubleCognitif.objects.all(), + widget=forms.CheckboxSelectMultiple, + required=False, + label="Troubles de l'apprentissage" ) + ajout_dys = forms.CharField(label="Ajouter un trouble", required=False) + nouvelle = forms.BooleanField(label="Première inscription au LXP", required=False) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -242,7 +249,12 @@ def __init__(self, *args, **kwargs): # Largeur des labels et des champs sur la grille self.helper.label_class = 'col-md-4' self.helper.field_class = 'col-md-8 d-flex flex-wrap justify-content-between' + self.helper.use_custom_control = True + self.helper.form_show_labels = True self.helper.layout = Layout( + Field('dys', id='dys'), + FieldWithButtons('ajout_dys', StrictButton('Enregistrer', id='dys-btn', css_class='btn-outline-success', + onclick="ajoutDys()")), Field('allergie', id='allergie'), FieldWithButtons('ajout_allergie', StrictButton('Enregistrer', id='allergie-btn', css_class='btn-outline-success', onclick="ajoutAllergie()")), @@ -250,6 +262,12 @@ def __init__(self, *args, **kwargs): ) + class Media: + js = ('js/hide_lxp_an_passe.js',) + css = { + 'screen': ('css/custom-dark.css',), + } + class Meta: # Définis le modèle utilisé et des données à enregistrer model = BaseEleve @@ -303,8 +321,8 @@ def check_spe(self,spes): else: list_type = [] for spe in spes: - if inscription.models.Spe.objects.filter(intitule=spe).values_list('type', flat=True).first() is not None: - list_type.append(inscription.models.Spe.objects.filter(intitule=spe).values_list('type', flat=True).first()) + if Spe.objects.filter(intitule=spe).values_list('type', flat=True).first() is not None: + list_type.append(Spe.objects.filter(intitule=spe).values_list('type', flat=True).first()) for elem in list_type: if list_type.count(elem) > 1: return True diff --git a/inscription/models.py b/inscription/models.py index 63a8476..c790936 100644 --- a/inscription/models.py +++ b/inscription/models.py @@ -61,6 +61,13 @@ def __str__(self): return u'%s' % (self.name) +class TroubleCognitif(models.Model): + trouble = models.CharField(max_length=100) + + def __str__(self): + return '%s' % self.trouble + + class Allergie(models.Model): allergene = models.CharField(max_length=100) @@ -140,22 +147,18 @@ def __iter__(self): tel_resp2 = PhoneNumberField(verbose_name="Numéro de téléphone", blank=True, null=True) sociopro_resp2 = models.ForeignKey(Sociopro, related_name='resp2', on_delete=models.CASCADE, verbose_name="Profession", blank=True, null=True) - DYS = ( - ('DL', 'Dyslexie'), - ('DC', 'Dyscalculie'), - ('DP', 'Dyspraxie'), - ('DG', 'Dysgraphie'), - ('DO', 'Dysorthographie') - ) - dys = MultiSelectField(choices=DYS, verbose_name='Troubles cognitifs', blank=True, null=True) - allergie = models.ManyToManyField(Allergie, blank=True, null=True) + spe1 = models.ManyToManyField(Spe, limit_choices_to={'groupe': '1'}, blank=True, related_name='spe1') spe2 = models.ManyToManyField(Spe, limit_choices_to={'groupe': '2'}, blank=True, related_name='spe2') spe3 = models.ManyToManyField(Spe, limit_choices_to={'groupe': '3'}, blank=True, related_name='spe3') NIVEAU = ( ('premiere', 'Première'), ('deter', 'Détermination (2nde)'), + ('premiere', 'Première'), ('term', 'Terminale'), ('crepa','CREPA'), ) niveau = models.CharField(max_length=10, choices=NIVEAU, verbose_name="Niveau d'inscription", default='deter') + # Scolarité passée + dys = models.ManyToManyField(TroubleCognitif, verbose_name="Troubles de l'apprentissage") + allergie = models.ManyToManyField(Allergie, verbose_name="Allergies") diff --git a/inscription/urls.py b/inscription/urls.py index 42da9f6..dea34a1 100644 --- a/inscription/urls.py +++ b/inscription/urls.py @@ -2,7 +2,7 @@ from django.contrib.auth.decorators import login_required from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.urls import path -from .views import InscriptionView, FormulaireInscription, fiche, fiche_pdf, carto, ajout_allergie +from .views import InscriptionView, FormulaireInscription, fiche, fiche_pdf, carto, ajout_allergie, ajout_dys app_name = 'inscription' @@ -14,6 +14,7 @@ path('pdf//', fiche_pdf, name='pdf'), path('carto', carto, name='carto'), path('allergie', ajout_allergie, name='allergie'), + path('dys', ajout_dys, name='dys'), ] # Serving the media files in development mode #if settings.DEBUG: diff --git a/inscription/views.py b/inscription/views.py index 2c62bf8..21ed183 100644 --- a/inscription/views.py +++ b/inscription/views.py @@ -19,7 +19,7 @@ from djangoLxp import settings from .filters import ListeEleveFiltre # Base BaseEleve -from .models import BaseEleve, Pays, Departement, Allergie +from .models import BaseEleve, Pays, Departement, Allergie, TroubleCognitif # Tableau des inscrits from .tables import ListeEleveTableau # Une vue pour afficher les inscriptions filtées @@ -73,6 +73,15 @@ def ajout_allergie(request): return HttpResponse('success') +def ajout_dys(request): + """Une vue pour ajouter un trouble en jquery depuis le formulaire Wizard""" + if request.POST: + p, created = TroubleCognitif.objects.get_or_create( + trouble=request.POST.get('trouble').capitalize(), + ) + return HttpResponse('success') + + class FormulaireInscription(SessionWizardView): """ Vue du formulaire wizard (en plusieurs étapes) diff --git a/static/css/custom-dark.css b/static/css/custom-dark.css index 82eafc9..4db3716 100644 --- a/static/css/custom-dark.css +++ b/static/css/custom-dark.css @@ -8,6 +8,15 @@ color: #b1b1b1; line-height: 24px; } + +.is-invalid { + border-color: #e74c3c !important; +} + +.select2-container--default { + width: 100% !important; +} + .select2-container--default .select2-selection--single .select2-selection__rendered { color: #b1b1b1; line-height: 24px; diff --git a/templates/inscription/formulaire_inscription.html b/templates/inscription/formulaire_inscription.html index e15bbdc..01c2af6 100644 --- a/templates/inscription/formulaire_inscription.html +++ b/templates/inscription/formulaire_inscription.html @@ -80,13 +80,10 @@

Inscription au Lycée Expérimental

//XHR.addEventListener('error', function(event) { // alert('Oups! Quelque chose s\'est mal passé.'); //}); - // Configurez la requête XHR.open('POST', 'allergie'); - // Ajoutez l'en-tête HTTP requise pour requêtes POST de données de formulaire XHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - // Finalement, envoyez les données. XHR.send(urlEncodedData); setTimeout(function () { @@ -95,9 +92,24 @@

Inscription au Lycée Expérimental

//location.load(); document.getElementById('id_2-ajout_allergie').value = ''; }, 500); - } } - + function ajoutDys() { + if(document.getElementById('id_2-ajout_dys').value) { + var XHR = new XMLHttpRequest(); + var urlEncodedData = ""; + var urlEncodedDataPairs = []; + urlEncodedDataPairs.push(encodeURIComponent('trouble') + '=' + encodeURIComponent(document.getElementById('id_2-ajout_dys').value)); + urlEncodedDataPairs.push(encodeURIComponent('csrfmiddlewaretoken') + '=' + encodeURIComponent("{{ csrf_token }}")); + urlEncodedData = urlEncodedDataPairs.join('&').replace(/%20/g, '+'); + XHR.open('POST', 'dys'); + XHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + XHR.send(urlEncodedData); + setTimeout(function () { + $('#dys').load(' #dys', {"csrfmiddlewaretoken":"{{ csrf_token }}", "wizard_goto_step": '2'}, function(){$(this).children().unwrap()}); + document.getElementById('id_2-ajout_dys').value = ''; + }, 500); + } + } {% endblock %}