-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajouter un suivi des versions pour la fiche détection
Ce commit permet d'utiliser django-revision afin de suivre les modifications réalisées sur une fiche détection et les objets sous-jacents (Lieu, Prélèvement) afin de pouvoir afficher la date de dernière modification ainsi que l'utilisateur / l'utilisatrice à l'origine de cette modification. Je n'ai pas utilisé un simple champ date et une FK vers le User car nous savons que nous voulons être en mesure d'afficher un diff plus complet avec les différentes dates de modification. Autres modifications: - Changement de format de date pour utiliser une vrai date plutôt qu'une chaine de caractères (tests en erreurs après l'ajout de Django revision) - Changement dans l'admin afin que l'on puisse charger l'admin des fiches - Changement d'un test pour ne plus utiliser la factory qui a été améliorée entre temps et rendre le test OK
- Loading branch information
Showing
16 changed files
with
242 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ faker | |
django-debug-toolbar | ||
django-post_office | ||
factory-boy | ||
django-reversion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from django.db.models.signals import pre_delete, post_save | ||
from django.dispatch import receiver | ||
from django.db import transaction | ||
import reversion | ||
|
||
from sv.models import Lieu, Prelevement | ||
|
||
|
||
@receiver(pre_delete, sender=Lieu) | ||
def create_fiche_detection_version_on_lieu_delete(sender, instance: Lieu, **kwargs): | ||
fiche = instance.fiche_detection | ||
|
||
with transaction.atomic(): | ||
with reversion.create_revision(): | ||
reversion.set_comment(f"Le lieu '{instance.nom}' a été supprimé de la fiche") | ||
reversion.add_to_revision(fiche) | ||
|
||
|
||
@receiver(post_save, sender=Lieu) | ||
def create_fiche_detection_version_on_lieu_add(sender, instance: Lieu, created, **kwargs): | ||
if not created: | ||
return | ||
fiche = instance.fiche_detection | ||
|
||
with transaction.atomic(): | ||
with reversion.create_revision(): | ||
reversion.set_comment(f"Le lieu '{instance.nom}' a été ajouté à la fiche") | ||
reversion.add_to_revision(fiche) | ||
|
||
|
||
@receiver(post_save, sender=Prelevement) | ||
def create_fiche_detection_version_on_prelevement_add(sender, instance: Prelevement, created, **kwargs): | ||
if not created: | ||
return | ||
fiche = instance.lieu.fiche_detection | ||
|
||
with transaction.atomic(): | ||
with reversion.create_revision(): | ||
reversion.set_comment( | ||
f"Le prélèvement pour le lieu '{instance.lieu.nom}' et la structure '{instance.structure_preleveuse}' a été ajouté à la fiche" | ||
) | ||
reversion.add_to_revision(fiche) | ||
|
||
|
||
@receiver(pre_delete, sender=Prelevement) | ||
def create_fiche_detection_version_on_prelevement_delete(sender, instance: Prelevement, **kwargs): | ||
fiche = instance.lieu.fiche_detection | ||
|
||
with transaction.atomic(): | ||
with reversion.create_revision(): | ||
reversion.set_comment( | ||
f"Le prélèvement pour le lieu '{instance.lieu.nom}' et la structure '{instance.structure_preleveuse}' a été supprimé de la fiche" | ||
) | ||
reversion.add_to_revision(fiche) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.