Skip to content

Commit

Permalink
Ajout switch ancien/nouveau + GB/ECCO
Browse files Browse the repository at this point in the history
  • Loading branch information
davy39 committed Feb 10, 2022
1 parent 0de800a commit d33ea24
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 9 deletions.
1 change: 1 addition & 0 deletions djangoLxp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
url('^commune/$', AutocompleteCommune.as_view(model=Commune), name='commune'),
url('^pays/$', AutocompletePays.as_view(), name='pays'),
url('^departement/$', AutocompleteDepartement.as_view(), name='departement'),
url('^mee/$', AutocompleteMEE.as_view(), name='mee'),
]
10 changes: 7 additions & 3 deletions inscription/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from django.contrib import admin
from .models import BaseEleve, Departement, Commune
from .models import BaseEleve, MEE, Allergie, Spe, TroubleCognitif

# Register your models here.
admin.site.register(BaseEleve)
admin.site.register(Departement)
admin.site.register(Commune)
admin.site.register(MEE)
admin.site.register(Allergie)
admin.site.register(TroubleCognitif)
admin.site.register(Spe)

31 changes: 28 additions & 3 deletions inscription/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,11 @@ def __init__(self, *args, **kwargs):
Field('allergie', id='allergie'),
FieldWithButtons('ajout_allergie', StrictButton('Enregistrer', id='allergie-btn', css_class='btn-outline-success',
onclick="ajoutAllergie()")),
InlineCheckboxes('dys'),

Field('nouvelle', id='nouvelle', wrapper_class="custom-control custom-switch custom-switch-lg",
template='inscription/custom-field.html'),
'niveau_an_passe',
'gb_an_passe',
'ecco_an_passe',
)

class Media:
Expand All @@ -271,7 +274,29 @@ class Media:
class Meta:
# Définis le modèle utilisé et des données à enregistrer
model = BaseEleve
fields = ['allergie', 'dys']
fields = ['allergie', 'dys', 'nouvelle', 'niveau_an_passe', 'gb_an_passe', 'ecco_an_passe']
widgets = {
'ecco_an_passe': autocomplete.ModelSelect2(url='mee',
forward=('gb_an_passe',)),
}

def clean(self):
nouvelle = self.cleaned_data.get('nouvelle')
if nouvelle:
self.cleaned_data['ecco_an_passe'] = None
self.cleaned_data['gb_an_passe'] = None
self.cleaned_data['niveau_an_passe'] = None
else:
if not self.cleaned_data.get('ecco_an_passe'):
msg = forms.ValidationError("Indique ton MEE de groupe ECCO de l'an passé.")
self.add_error('ecco_an_passe', msg)
if not self.cleaned_data.get('gb_an_passe'):
msg = forms.ValidationError("Indique ton groupe de base de l'an passé.")
self.add_error('gb_an_passe', msg)
if not self.cleaned_data.get('niveau_an_passe'):
msg = forms.ValidationError("Indique le niveau dans lequel tu étais inscrit l'an passé.")
self.add_error('niveau_an_passe', msg)
return self.cleaned_data


class InscriptionForm4(forms.ModelForm):
Expand Down
32 changes: 32 additions & 0 deletions inscription/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
from phonenumber_field.modelfields import PhoneNumberField
from .utils import nom_photo, create_hash

GB = (
(1, 'G1'),
(2, 'G2'),
(3, 'G3'),
(4, 'G4'),
(5, 'G5'),
)

class Spe(models.Model):
code = models.CharField(max_length=10, verbose_name="Code Spé")
Expand Down Expand Up @@ -75,6 +82,20 @@ def __str__(self):
return '%s' % self.allergene


class MEE(models.Model):
nom = models.CharField(max_length=20, verbose_name="Nom")
prenom = models.CharField(max_length=20, verbose_name="Prénom")
gb_an_passe = models.IntegerField(choices=GB,
verbose_name="GB de l'an passé", blank=True, null=True)
gb_annee_en_cours = models.IntegerField(choices=GB,
verbose_name="GB de cette année", blank=True, null=True)
email = models.EmailField(verbose_name="Email", max_length=30, blank=True, null=True)
telephone = PhoneNumberField(verbose_name="Téléphone", blank=True, null=True)

def __str__(self):
return '%s' % self.prenom


class BaseEleve(models.Model):
"""
Modèle de base de donnée BaseEleve
Expand Down Expand Up @@ -162,3 +183,14 @@ def __iter__(self):
# Scolarité passée
dys = models.ManyToManyField(TroubleCognitif, verbose_name="Troubles de l'apprentissage")
allergie = models.ManyToManyField(Allergie, verbose_name="Allergies")

nouvelle = models.BooleanField(verbose_name='Première inscription au LXP', default=True)
niveau_an_passe = models.CharField(max_length=10, choices=NIVEAU,
verbose_name="Niveau d'inscription l'an passé", blank=True, null=True)
gb_an_passe = models.IntegerField(choices=GB,
verbose_name="Groupe de base", blank=True, null=True)
ecco_an_passe = models.ForeignKey(MEE, on_delete=models.CASCADE,
verbose_name="MEE d'ECCO", blank=True, null=True)

gb_annee_en_cours = models.IntegerField(choices=GB,
verbose_name="Groupe de base", blank=True, null=True)
14 changes: 12 additions & 2 deletions inscription/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
from djangoLxp import settings
from .filters import ListeEleveFiltre
# Base BaseEleve
from .models import BaseEleve, Pays, Departement, Allergie, TroubleCognitif
# Tableau des inscrits
from .models import BaseEleve, Pays, Departement, Allergie, TroubleCognitif, MEE
from .tables import ListeEleveTableau
# Une vue pour afficher les inscriptions filtées
from .utils import PagedFilteredTableView, MediaStorage, coordonnees
Expand Down Expand Up @@ -163,4 +162,15 @@ def get_queryset(self):
qs = Pays.objects.all().order_by('name')
if self.q:
qs = qs.filter(name__istartswith=self.q)
return qs


class AutocompleteMEE(autocomplete.Select2QuerySetView):
def get_queryset(self):
qs = MEE.objects.all().order_by('prenom')
gb = self.forwarded.get('gb_an_passe', None)
if gb:
qs = qs.filter(gb_an_passe=gb)
if self.q:
qs = qs.filter(prenom__istartswith=self.q)
return qs
25 changes: 24 additions & 1 deletion static/css/formulaire_inscription.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@
.asteriskField {
display: none;
}

input#nouvelle.checkboxinput.custom-control-input {
margin-left: 50px;
}
/* Customisation des checkboxes (alergie, dys...)*/
.custom-control.custom-checkbox {
display: inline-block;
Expand All @@ -95,4 +97,25 @@ fieldset {
margin: 0 0 30px 0;
border: 1px solid #515151;
border-radius: 10px;
}

.custom-switch.custom-switch-lg .custom-control-label {
padding-left: 3rem;
padding-bottom: 2rem;
}

.custom-switch.custom-switch-lg .custom-control-label::before {
height: 2rem;
width: calc(3rem + 0.75rem);
border-radius: 4rem;
}

.custom-switch.custom-switch-lg .custom-control-label::after {
width: calc(2rem - 4px);
height: calc(2rem - 4px);
border-radius: calc(3rem - (2rem / 2));
}

.custom-switch.custom-switch-lg .custom-control-input:checked ~ .custom-control-label::after {
transform: translateX(calc(2rem - 0.25rem));
}
21 changes: 21 additions & 0 deletions static/js/hide_lxp_an_passe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Fonction permettant de cacher les champs inutiles du resp2
function Hide() {
if(document.getElementById('nouvelle').checked) {
document.getElementById('div_id_2-niveau_an_passe').style.display = 'none';
document.getElementById('div_id_2-gb_an_passe').style.display = 'none';
document.getElementById('div_id_2-ecco_an_passe').style.display = 'none';
} else {
document.getElementById('div_id_2-niveau_an_passe').style.display = '';
document.getElementById('div_id_2-gb_an_passe').style.display = '';
document.getElementById('div_id_2-ecco_an_passe').style.display = '';
}
}
// Vérifie id_1-resp2 est à aucun (fonction Hide) après le chargement du document.
// Utile lors du retour en arrière dans le formulaire
document.addEventListener("DOMContentLoaded", function() {
Hide();
});
// Appelle la fonction quand on change le statut de resp2
window.onload = function() {
document.getElementById('nouvelle').onchange = Hide;
};
34 changes: 34 additions & 0 deletions templates/inscription/custom-field.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% load crispy_forms_field %}
<div class="form-group row">
{% if field.label and form_show_labels %}
{# not field|is_radioselect in row below can be removed once Django 3.2 is no longer supported #}
<label {% if field.id_for_label and not field|is_radioselect %}for="{{ field.id_for_label }}" {% endif %}class="{% if 'form-horizontal' in form_class %}col-form-label {% endif %}{{ label_class }}{% if field.field.required %} requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% endif %}
<div id="div_{{ field.auto_id }}" class="custom-control custom-checkbox{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">

{% if field|is_checkbox and form_show_labels %}
{%if use_custom_control%}
{% if field.errors %}
{% crispy_field field 'class' 'custom-control-input is-invalid' %}
{% else %}
{% crispy_field field 'class' 'custom-control-input' %}
{% endif %}
{% else %}
{% if field.errors %}
{% crispy_field field 'class' 'form-check-input is-invalid' %}
{% else %}
{% crispy_field field 'class' 'form-check-input' %}
{% endif %}
{% endif %}
<label for="{{ field.id_for_label }}" class="{%if use_custom_control%}custom-control-label{% else %}form-check-label{% endif %}{% if field.field.required %} requiredField{% endif %}">
{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% include 'bootstrap4/layout/help_text_and_errors.html' %}
{% endif %}

</div>

</div>

0 comments on commit d33ea24

Please sign in to comment.