from django_unicorn.components import UnicornView

from BasicData.models import Note


class NoteRowView(UnicornView):
    etudiant = None
    evaluation = None
    disabled = False
    note = None

    def mount(self):
        try:
            self.note = Note.objects.get(etudiant=self.etudiant, evaluation=self.evaluation)
            if self.note.isBlocked:
                self.disabled = True
            self.note = self.note.note
        except Note.DoesNotExist:
                pass
        
    def enregistrer(self):
        if self.note:
            Note.objects.update_or_create(etudiant=self.etudiant, evaluation=self.evaluation, defaults={'note': self.note })
       
