Ajout page de focus sur 1 évaluation avec shearch des évaluation miroir
This commit is contained in:
@@ -5,8 +5,9 @@ from django.contrib import admin
|
||||
import uuid
|
||||
|
||||
EVAL_TYPE = [
|
||||
('1', 'Intervention/Exercice'),
|
||||
('1', 'Intervention'),
|
||||
('2', 'Journée'),
|
||||
('3','Exercice')
|
||||
]
|
||||
INTER_NATURE = [
|
||||
('1', 'Trauma'),
|
||||
@@ -39,21 +40,23 @@ EVAL_MODE = [
|
||||
('2', 'Encadrant'),
|
||||
]
|
||||
def increment_ID():
|
||||
last_id = cl_Student_eval.objects.all().order_by('ID').last()
|
||||
if not last_id:
|
||||
obj = cl_Student_eval.objects.all().order_by('ID').last()
|
||||
|
||||
if obj is None:
|
||||
return 1
|
||||
last_id = last_id.ID
|
||||
|
||||
last_id = int(obj.ID)
|
||||
return last_id + 1
|
||||
|
||||
class cl_Student_eval(models.Model):
|
||||
uuid = models.UUIDField(default=uuid.uuid4(), editable=False, primary_key=True)
|
||||
#ID = models.IntegerField("ID du Suivi", editable=False, unique=True, default=increment_ID)
|
||||
uuid = models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True)
|
||||
ID = models.IntegerField("ID du Suivi", editable=False, unique=True, default=increment_ID)
|
||||
|
||||
# Informations sur l'auteur
|
||||
Author = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name="Auteur", on_delete=models.SET_NULL, null=True, related_name="eval_author")
|
||||
sAuthor = models.CharField("Auteur", max_length=120)
|
||||
Author_2e = models.ForeignKey(settings.AUTH_USER_MODEL,limit_choices_to={'groups__name': "FI-Encadrants"}, verbose_name="Second auteur", on_delete=models.SET_NULL, null=True, related_name="eval_second_author", blank=True,)
|
||||
sAuthor_2e = models.CharField("Second auteur", max_length=120, blank=True,)
|
||||
Author_2e = models.ForeignKey(settings.AUTH_USER_MODEL,limit_choices_to={'groups__name': "FI-Encadrants"}, verbose_name="Co-auteur", on_delete=models.SET_NULL, null=True, related_name="eval_second_author", blank=True,)
|
||||
sAuthor_2e = models.CharField("Co-auteur", max_length=120, blank=True,)
|
||||
|
||||
#Information sur l 'étudiant/stagiaire
|
||||
Student = models.ForeignKey(settings.AUTH_USER_MODEL,limit_choices_to={'groups__name': "FI-Étudiants"}, verbose_name="Nom du stagiaire/étudaint", on_delete=models.SET_NULL, null=True)
|
||||
@@ -80,10 +83,17 @@ class cl_Student_eval(models.Model):
|
||||
dtUpdated = models.DateTimeField('date updated', auto_now=True)
|
||||
dtCreated = models.DateTimeField('date published', auto_now_add=True)
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.a_evals = None
|
||||
|
||||
self.o_Auto_eval = None
|
||||
self.o_Encadrant_eval = None
|
||||
self.mirrored = False
|
||||
|
||||
|
||||
|
||||
@admin.display(description='Référence du suivi')
|
||||
def get_ref_of_eval(self):
|
||||
sRet = ""
|
||||
@@ -94,28 +104,117 @@ class cl_Student_eval(models.Model):
|
||||
sRet = self.dtDate.strftime("%d.%b.%Y")
|
||||
|
||||
|
||||
print(sRet)
|
||||
print(f"Eval_Type = {self.nEval_Type} => {int(self.nEval_Type)-1}")
|
||||
#print(sRet)
|
||||
#print(f"Eval_Type = {self.nEval_Type} => {int(self.nEval_Type)-1}")
|
||||
return f"{EVAL_TYPE[int(self.nEval_Type)-1][1]}: {sRet}"
|
||||
|
||||
def get_all_evals_for_student(self,sStudent):
|
||||
def get_mirror_eval(self, evals):
|
||||
#print(self)
|
||||
for eval in evals:
|
||||
eval = eval["eval"]
|
||||
|
||||
to_be_set = False
|
||||
if eval.ID == self.ID:
|
||||
to_be_set = True
|
||||
else:
|
||||
#print(f"check eval {eval}")
|
||||
if eval.nEval_Type == "1" and eval.sRef == self.sRef:
|
||||
print(f"Eval mirror found {eval} / {self}")
|
||||
to_be_set = True
|
||||
elif eval.nEval_Type == "2" and eval.dtDate == self.dtDate:
|
||||
print(f"Eval mirror found {eval} / {self}")
|
||||
to_be_set = True
|
||||
|
||||
if to_be_set:
|
||||
match int(eval.nEval_Mode):
|
||||
case 1:
|
||||
self.o_Auto_eval = eval
|
||||
case 2:
|
||||
self.o_Encadrant_eval = eval
|
||||
|
||||
|
||||
|
||||
if self.o_Encadrant_eval is not None and self.o_Auto_eval is not None:
|
||||
self.mirrored = True
|
||||
#print(f" auto = {self.o_Auto_eval} / encadrant = {self.o_Encadrant_eval}")
|
||||
|
||||
|
||||
def get_all_evals_for_student(self,sStudent=None):
|
||||
if sStudent is None:
|
||||
sStudent = self.sStudent
|
||||
|
||||
self.a_evals = []
|
||||
evals = cl_Student_eval.objects.filter(sStudent=sStudent).order_by('sRef')
|
||||
for eval in evals:
|
||||
self.a_evals.append({"uuid":eval.uuid,"sRef":eval.sRef, "nEval_Mode": eval.nEval_Mode, "eval":eval})
|
||||
print(self.a_evals)
|
||||
self.a_evals.append({"uuid":eval.uuid,"sRef":eval.sRef, "nEval_Mode": eval.nEval_Mode, "nEval_Type": eval.nEval_Type, "eval":eval, "dtDate": eval.dtDate})
|
||||
|
||||
|
||||
#print(self.a_evals)
|
||||
return self.a_evals
|
||||
|
||||
@admin.display(description="Présence d'évaluation mirroir", boolean=True)
|
||||
def get_mirrored(self):
|
||||
self.get_all_evals_for_student()
|
||||
self.get_mirror_eval(self.a_evals)
|
||||
return self.mirrored
|
||||
|
||||
def get_eval_type(self):
|
||||
return EVAL_TYPE[int(self.nEval_Type)-1][1]
|
||||
|
||||
def get_inter_nature(self):
|
||||
return INTER_NATURE[int(self.nInter_Nature)-1][1]
|
||||
|
||||
def get_inter_complexity(self):
|
||||
return INTER_COMPLEXITY[int(self.nInter_Nature)-1][1]
|
||||
|
||||
def get_inter_priority(self):
|
||||
return INTER_PRIORITY[int(self.nInter_Priority)-1][1]
|
||||
|
||||
def get_eval_mode(self):
|
||||
return EVAL_MODE[int(self.nEval_Mode)-1][1]
|
||||
|
||||
def get_student_role(self):
|
||||
return STUDENT_ROLE[int(self.nStudent_Role)-1][1]
|
||||
|
||||
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"{ self.sStudent } => {self.sRef} ({EVAL_MODE[int(self.nEval_Mode)][1]})"
|
||||
try:
|
||||
return f"#{self.ID} { self.sStudent } => {self.get_ref_of_eval()} ({EVAL_MODE[int(self.nEval_Mode)-1][1]} / {EVAL_TYPE[int(self.nEval_Type)-1][1]})"
|
||||
except:
|
||||
return ""
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Suivi étudiants"
|
||||
verbose_name_plural = "Suivis étudiants"
|
||||
|
||||
|
||||
import csv
|
||||
import os
|
||||
from datetime import datetime
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
chemin_actuel = os.path.dirname(__file__)
|
||||
def import_data_csv():
|
||||
with open(os.path.join(chemin_actuel, 'import.csv'), 'r', encoding='utf-8') as file_csv:
|
||||
file_csv = csv.DictReader(file_csv)
|
||||
first_line = True
|
||||
for line in file_csv:
|
||||
# Ne rien faire avec la première ligne = Header
|
||||
|
||||
|
||||
new_eval = cl_Student_eval()
|
||||
|
||||
for key in line.keys():
|
||||
if key == "Zeitstempel":
|
||||
continue
|
||||
value = line[key]
|
||||
if key == "dtDate":
|
||||
value = datetime.strptime(value, "%d.%m.%Y").date()
|
||||
setattr(new_eval, key,value)
|
||||
|
||||
new_eval.save()
|
||||
print(f"Save new eval {new_eval.ID}")
|
||||
|
||||
#import_data_csv()
|
Reference in New Issue
Block a user