Skip to content

Commit

Permalink
Ajout troubles cognitifes
Browse files Browse the repository at this point in the history
  • Loading branch information
davy39 committed Feb 10, 2022
1 parent f0c6a28 commit 0de800a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 23 deletions.
32 changes: 25 additions & 7 deletions inscription/forms.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -242,14 +249,25 @@ 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()")),
InlineCheckboxes('dys'),

)

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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions inscription/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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")
3 changes: 2 additions & 1 deletion inscription/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -14,6 +14,7 @@
path('pdf/<int:id>/<hash>', 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:
Expand Down
11 changes: 10 additions & 1 deletion inscription/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions static/css/custom-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 17 additions & 5 deletions templates/inscription/formulaire_inscription.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,10 @@ <h1 class=text-center >Inscription au Lycée Expérimental</h1>
//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 () {
Expand All @@ -95,9 +92,24 @@ <h1 class=text-center >Inscription au Lycée Expérimental</h1>
//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);
}
}
</script>
{% endblock %}

0 comments on commit 0de800a

Please sign in to comment.