Compare commits
1 Commits
main
...
Affichage_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d28bf85556 |
@@ -1,12 +1,11 @@
|
||||
from django import forms
|
||||
from .models import Contrat, Departement, Employe,Affectation,Formation
|
||||
|
||||
class EmployeForm(forms.ModelForm):
|
||||
"""Formulaire pour modifier les informations de profil d'un employé"""
|
||||
class Meta:
|
||||
model = Employe
|
||||
fields = (
|
||||
'departement',
|
||||
'fonction',
|
||||
'adresse',
|
||||
'telephone',
|
||||
'CV',
|
||||
@@ -14,18 +13,7 @@ class EmployeForm(forms.ModelForm):
|
||||
'rib',
|
||||
'photo',
|
||||
'casier_judiciaire'
|
||||
)
|
||||
widgets = {
|
||||
'departement': forms.Select(attrs={'class': 'form-select'}),
|
||||
'fonction': forms.Select(attrs={'class': 'form-select'}),
|
||||
'adresse': forms.TextInput(attrs={'class': 'form-control'}),
|
||||
'telephone': forms.TextInput(attrs={'class': 'form-control'}),
|
||||
'CV': forms.FileInput(attrs={'class': 'form-control'}),
|
||||
'diplome': forms.FileInput(attrs={'class': 'form-control'}),
|
||||
'rib': forms.FileInput(attrs={'class': 'form-control'}),
|
||||
'photo': forms.FileInput(attrs={'class': 'form-control'}),
|
||||
'casier_judiciaire': forms.FileInput(attrs={'class': 'form-control'}),
|
||||
}
|
||||
)
|
||||
|
||||
class AffectationForm(forms.ModelForm):
|
||||
class Meta:
|
||||
|
||||
@@ -12,6 +12,7 @@ const tableau_liste_employe = new Tabulator("#tableau_liste_employe", {
|
||||
// ajaxURL: url_liste_employe,
|
||||
pagination: true,
|
||||
paginationSize: 10,
|
||||
responsiveLayout : "hide"
|
||||
})
|
||||
|
||||
fetch(url_liste_employe)
|
||||
@@ -28,8 +29,6 @@ fetch(url_liste_employe)
|
||||
|
||||
tableau_liste_employe.on("rowClick", function (row, rowData) {
|
||||
const data = rowData.getData();
|
||||
console.log('Employé cliqué:', data);
|
||||
|
||||
document.getElementById('detail-id').value = data.id;
|
||||
document.getElementById('detail-matricule').value = data.matricule;
|
||||
document.getElementById('detail-employe').value = data.employe;
|
||||
@@ -212,41 +211,23 @@ $("enregistrerDetail").addEventListener("click", function() {
|
||||
const fonction = document.getElementById('detail-fonction').value;
|
||||
const dateEmbauche = document.getElementById('detail-dateEmbauche').value;
|
||||
const matricule = document.getElementById('detail-matricule').value;
|
||||
const departement = document.getElementById('detail-departement').value;
|
||||
|
||||
console.log('=== ENREGISTREMENT DÉTAILS ===');
|
||||
console.log('ID:', id_);
|
||||
console.log('Fonction:', fonction);
|
||||
console.log('Date embauche:', dateEmbauche);
|
||||
console.log('Matricule:', matricule);
|
||||
console.log('Département (valeur brute):', departement);
|
||||
console.log('Département (type):', typeof departement);
|
||||
console.log('Département est vide:', !departement);
|
||||
|
||||
const url_enregistrer_detail = $("modalDetailEmployeBody").dataset.url;
|
||||
|
||||
const payload = {
|
||||
"id": id_,
|
||||
"fonction": fonction,
|
||||
"date_embauche": dateEmbauche,
|
||||
"matricule": matricule,
|
||||
"departement": departement
|
||||
};
|
||||
|
||||
console.log('Payload JSON:', payload);
|
||||
console.log('Payload stringifié:', JSON.stringify(payload));
|
||||
|
||||
fetch(url_enregistrer_detail, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-CSRFToken": document.querySelector('[name=csrfmiddlewaretoken]').value
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
body: JSON.stringify({
|
||||
"id": id_,
|
||||
"fonction": fonction,
|
||||
"date_embauche": dateEmbauche,
|
||||
"matricule": matricule
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('Réponse du serveur:', data);
|
||||
alert(data.message);
|
||||
location.reload();
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body" id="modalDetailEmployeBody" data-url="{% url 'gestion_employe:enregistrer-detail-employe' %}" data-url-departements="{% url 'gestion_employe:liste-departements' %}">
|
||||
<div class="modal-body" id="modalDetailEmployeBody" data-url="{% url 'gestion_employe:enregistrer-detail-employe' %}">
|
||||
<div class="row g-3">
|
||||
<input type="hidden" id="detail-id">
|
||||
<div class="col-md-6">
|
||||
@@ -23,12 +23,7 @@
|
||||
</div>
|
||||
<div class="form-group mb-2">
|
||||
<label>Département :</label>
|
||||
<select class="form-select" id="detail-departement">
|
||||
<option value="">-- Sélectionner --</option>
|
||||
{% for dept in departements %}
|
||||
<option value="{{ dept.id }}">{{ dept.nom }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<input type="text" class="form-control" id="detail-departement">
|
||||
</div>
|
||||
<div class="form-group mb-2">
|
||||
<label>Sexe :</label>
|
||||
|
||||
@@ -83,10 +83,5 @@ urlpatterns = [
|
||||
"liste-contrat-expirants",
|
||||
views.liste_contrat_expirants,
|
||||
name='liste-contrat-expirants'
|
||||
),
|
||||
path(
|
||||
"liste-departements/",
|
||||
views.liste_departements,
|
||||
name='liste-departements'
|
||||
)
|
||||
]
|
||||
@@ -13,13 +13,16 @@ from django.http import JsonResponse
|
||||
from django.forms.models import model_to_dict
|
||||
from django.db.models import Sum
|
||||
|
||||
from .models import Employe, Contrat, Affectation, Formation, Departement
|
||||
from .models import Employe, Contrat, Affectation, Formation
|
||||
from .forms import AffectationForm, ContratForm, FormationForm
|
||||
from fonction_utilitaire import fonctions_utilitaire
|
||||
|
||||
@login_required
|
||||
def index(request):
|
||||
"""Vue d'index"""
|
||||
if not request.user.groups.filter(name="ressource_humaine").exists():
|
||||
return redirect('gestion_employe:mon-profil')
|
||||
|
||||
employes = Employe.objects.all().order_by('-user__date_joined')
|
||||
nombre_employes = Employe.objects.count()
|
||||
nombre_cps = Contrat.objects.filter(type_contrat='contrat_prestation').count()
|
||||
@@ -38,8 +41,7 @@ def index(request):
|
||||
'nombre_stage': nombre_stage,
|
||||
'nombre_expirants': nombre_expirants,
|
||||
'affectation_form': AffectationForm(),
|
||||
'contrat_form': ContratForm(),
|
||||
'departements': Departement.objects.all()
|
||||
'contrat_form': ContratForm()
|
||||
})
|
||||
|
||||
@login_required
|
||||
@@ -95,7 +97,7 @@ def affecter_employe_projet(request):
|
||||
elif total_affectation + temps_nouveau > 100:
|
||||
messages.warning(
|
||||
request,
|
||||
f"Les pourcentages d'affectation de l'employé {employe.first_name} {employe.last_name} dépasse 100% sur les différents projets ({total_affectation + temps_nouveau}%)."
|
||||
f"Les pourcentages d'affectation de l'employé {employe.user.first_name} {employe.user.last_name} dépasse 100% sur les différents projets ({total_affectation + temps_nouveau}%)."
|
||||
)
|
||||
return redirect('gestion_employe:index')
|
||||
|
||||
@@ -301,30 +303,10 @@ def enregistrer_detail_employe(request):
|
||||
except Employe.DoesNotExist:
|
||||
return JsonResponse({"error": "Employé non trouvé."}, status=404)
|
||||
|
||||
employe.fonction = data.get('fonction')
|
||||
employe.date_embauche = data.get('date_embauche')
|
||||
employe.matricule = data.get('matricule')
|
||||
|
||||
# Traiter le département
|
||||
dept_value = data.get('departement')
|
||||
print(f"[DEBUG] Département brut: {dept_value!r}")
|
||||
print(f"[DEBUG] Type département: {type(dept_value).__name__}")
|
||||
print(f"[DEBUG] Est vide: {not dept_value}")
|
||||
|
||||
if dept_value and str(dept_value).strip():
|
||||
try:
|
||||
dept_id = int(dept_value)
|
||||
departement = Departement.objects.get(id=dept_id)
|
||||
employe.departement = departement
|
||||
except Departement.DoesNotExist:
|
||||
employe.departement = None
|
||||
except (ValueError, TypeError) as e:
|
||||
employe.departement = None
|
||||
else:
|
||||
employe.departement = None
|
||||
|
||||
employe.fonction = data['fonction']
|
||||
employe.date_embauche = data['date_embauche']
|
||||
employe.matricule = data['matricule']
|
||||
employe.save()
|
||||
|
||||
return JsonResponse({"message": "Détails de l'employé mis à jour avec succès."})
|
||||
else:
|
||||
return JsonResponse({"message": "Méthode non autorisée."}, status=405)
|
||||
@@ -386,7 +368,7 @@ def liste_employe(request):
|
||||
"affectations": affectations,
|
||||
"projet": projets,
|
||||
"contrats": contrats,
|
||||
"departement": employe.departement.id if employe.departement else "",
|
||||
"departement": employe.departement.nom if employe.departement else "",
|
||||
"fonction": employe.fonction,
|
||||
"date_embauche": employe.date_embauche,
|
||||
"adresse": employe.adresse,
|
||||
@@ -458,15 +440,3 @@ def supprimer_formation(request, id_formation):
|
||||
formation.delete()
|
||||
messages.success(request, "Formation supprimée ")
|
||||
return redirect("mes_formations")
|
||||
|
||||
def liste_departements(request):
|
||||
"""Vue pour retourner la liste de tous les départements en JSON"""
|
||||
departements = Departement.objects.all()
|
||||
data = [
|
||||
{
|
||||
"id": dept.id,
|
||||
"nom": dept.nom
|
||||
}
|
||||
for dept in departements
|
||||
]
|
||||
return JsonResponse(data, safe=False)
|
||||
|
||||
Reference in New Issue
Block a user