Skip to content
Snippets Groups Projects
Commit 6c2cdf06 authored by ynerant's avatar ynerant
Browse files

Remove warning when no user is detected while a modification is made

parent daef8065
No related branches found
No related tags found
1 merge request!56Corrections
Pipeline #7918 passed with stages
in 4 minutes and 3 seconds
...@@ -67,9 +67,10 @@ def save_object(sender, instance, **kwargs): ...@@ -67,9 +67,10 @@ def save_object(sender, instance, **kwargs):
ip = "127.0.0.1" ip = "127.0.0.1"
username = Alias.normalize(getpass.getuser()) username = Alias.normalize(getpass.getuser())
note = NoteUser.objects.filter(alias__normalized_name=username) note = NoteUser.objects.filter(alias__normalized_name=username)
if not note.exists(): # if not note.exists():
print("WARNING: A model attempted to be saved in the DB, but the actor is unknown: " + username) # print("WARNING: A model attempted to be saved in the DB, but the actor is unknown: " + username)
else: # else:
if note.exists():
user = note.get().user user = note.get().user
# noinspection PyProtectedMember # noinspection PyProtectedMember
...@@ -113,6 +114,19 @@ def delete_object(sender, instance, **kwargs): ...@@ -113,6 +114,19 @@ def delete_object(sender, instance, **kwargs):
# Si un utilisateur est connecté, on récupère l'utilisateur courant ainsi que son adresse IP # Si un utilisateur est connecté, on récupère l'utilisateur courant ainsi que son adresse IP
user, ip = get_current_authenticated_user(), get_current_ip() user, ip = get_current_authenticated_user(), get_current_ip()
if user is None:
# Si la modification n'a pas été faite via le client Web, on suppose que c'est du à `manage.py`
# On récupère alors l'utilisateur·trice connecté·e à la VM, et on récupère la note associée
# IMPORTANT : l'utilisateur dans la VM doit être un des alias note du respo info
ip = "127.0.0.1"
username = Alias.normalize(getpass.getuser())
note = NoteUser.objects.filter(alias__normalized_name=username)
# if not note.exists():
# print("WARNING: A model attempted to be saved in the DB, but the actor is unknown: " + username)
# else:
if note.exists():
user = note.get().user
# On crée notre propre sérialiseur JSON pour pouvoir sauvegarder les modèles # On crée notre propre sérialiseur JSON pour pouvoir sauvegarder les modèles
class CustomSerializer(ModelSerializer): class CustomSerializer(ModelSerializer):
class Meta: class Meta:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment