Add logs in tox settings

This commit is contained in:
Yohann D'ANELLO 2020-03-11 17:20:16 +01:00
parent 5d25f9830c
commit 695ef446ec
5 changed files with 12 additions and 10 deletions

View File

@ -16,4 +16,4 @@ class ChangelogSerializer(serializers.ModelSerializer):
model = Changelog model = Changelog
fields = '__all__' fields = '__all__'
# noinspection PyProtectedMember # noinspection PyProtectedMember
read_only_fields = [f.name for f in model._meta.get_fields()] # Changelogs are read-only protected read_only_fields = [f.name for f in model._meta.get_fields()] # Changelogs are read-only protected

View File

@ -2,6 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from django.apps import AppConfig from django.apps import AppConfig
from django.db.models.signals import pre_save, post_save, post_delete
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -11,4 +12,7 @@ class LogsConfig(AppConfig):
def ready(self): def ready(self):
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
import logs.signals from . import signals
pre_save.connect(signals.pre_save_object)
post_save.connect(signals.save_object)
post_delete.connect(signals.delete_object)

View File

@ -3,6 +3,7 @@
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from threading import local from threading import local

View File

@ -2,13 +2,13 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db.models.signals import pre_save, post_save, post_delete
from django.dispatch import receiver
from rest_framework.renderers import JSONRenderer from rest_framework.renderers import JSONRenderer
from rest_framework.serializers import ModelSerializer from rest_framework.serializers import ModelSerializer
import getpass import getpass
from note.models import NoteUser, Alias from note.models import NoteUser, Alias
from .middlewares import get_current_authenticated_user, get_current_ip from .middlewares import get_current_authenticated_user, get_current_ip
from .models import Changelog from .models import Changelog
@ -23,15 +23,14 @@ EXCLUDED = [
'cas_server.user', 'cas_server.user',
'cas_server.userattributes', 'cas_server.userattributes',
'contenttypes.contenttype', 'contenttypes.contenttype',
'logs.changelog', # Never remove this line 'logs.changelog', # Never remove this line
'migrations.migration', 'migrations.migration',
'note.note' # We only store the subclasses 'note.note' # We only store the subclasses
'note.transaction', 'note.transaction',
'sessions.session', 'sessions.session',
] ]
@receiver(pre_save)
def pre_save_object(sender, instance, **kwargs): def pre_save_object(sender, instance, **kwargs):
""" """
Avant la sauvegarde d'un modèle, on récupère l'ancienne instance actuellement en base de données Avant la sauvegarde d'un modèle, on récupère l'ancienne instance actuellement en base de données
@ -44,7 +43,6 @@ def pre_save_object(sender, instance, **kwargs):
instance._previous = None instance._previous = None
@receiver(post_save)
def save_object(sender, instance, **kwargs): def save_object(sender, instance, **kwargs):
""" """
Dès qu'un modèle est sauvegardé, une entrée dans la table `Changelog` est ajouté dans la base de données Dès qu'un modèle est sauvegardé, une entrée dans la table `Changelog` est ajouté dans la base de données
@ -102,7 +100,6 @@ def save_object(sender, instance, **kwargs):
).save() ).save()
@receiver(post_delete)
def delete_object(sender, instance, **kwargs): def delete_object(sender, instance, **kwargs):
""" """
Dès qu'un modèle est supprimé, une entrée dans la table `Changelog` est ajouté dans la base de données Dès qu'un modèle est supprimé, une entrée dans la table `Changelog` est ajouté dans la base de données

View File

@ -32,7 +32,7 @@ deps =
pep8-naming pep8-naming
pyflakes pyflakes
commands = commands =
flake8 apps/activity apps/api apps/member apps/note flake8 apps/activity apps/api apps/logs apps/member apps/note
[flake8] [flake8]
# Ignore too many errors, should be reduced in the future # Ignore too many errors, should be reduced in the future