Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nk20
Manage
Activity
Members
Labels
Plan
Issues
31
Issue boards
Milestones
Wiki
Code
Merge requests
6
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BDE
nk20
Commits
9cd050e2
Commit
9cd050e2
authored
5 years ago
by
ynerant
Browse files
Options
Downloads
Patches
Plain Diff
Logging is finally processed at post saved, but old instance is querried
parent
bcee5f8f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!28
Logs
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/logs/signals.py
+17
-7
17 additions, 7 deletions
apps/logs/signals.py
apps/member/apps.py
+2
-2
2 additions, 2 deletions
apps/member/apps.py
apps/member/signals.py
+2
-2
2 additions, 2 deletions
apps/member/signals.py
with
21 additions
and
11 deletions
apps/logs/signals.py
+
17
−
7
View file @
9cd050e2
...
...
@@ -5,7 +5,7 @@ import inspect
from
django.contrib.contenttypes.models
import
ContentType
from
django.core
import
serializers
from
django.db.models.signals
import
pre_save
,
p
re
_delete
from
django.db.models.signals
import
pre_save
,
p
ost_save
,
post
_delete
from
django.dispatch
import
receiver
from
.models
import
Changelog
...
...
@@ -58,22 +58,32 @@ EXCLUDED = [
'
reversion.version
'
,
]
@receiver
(
pre_save
)
def
pre_save_object
(
sender
,
instance
,
**
kwargs
):
qs
=
sender
.
objects
.
filter
(
pk
=
instance
.
pk
).
all
()
if
qs
.
exists
():
instance
.
_previous
=
qs
.
get
()
else
:
instance
.
_previous
=
None
@receiver
(
post_save
)
def
save_object
(
sender
,
instance
,
**
kwargs
):
# noinspection PyProtectedMember
if
instance
.
_meta
.
label_lower
in
EXCLUDED
:
return
previous
=
sender
.
objects
.
filter
(
pk
=
instance
.
pk
).
all
()
previous
=
instance
.
_previous
user
,
ip
=
get_user_and_ip
(
sender
)
if
user
is
not
None
and
instance
.
_meta
.
label_lower
==
"
auth.user
"
and
previous
.
exists
()
:
if
user
is
not
None
and
instance
.
_meta
.
label_lower
==
"
auth.user
"
and
previous
:
# Don't save last login modifications
if
instance
.
last_login
!=
previous
.
get
().
last_login
:
if
instance
.
last_login
!=
previous
.
last_login
:
return
previous_json
=
serializers
.
serialize
(
'
json
'
,
previous
)[
1
:
-
1
]
if
previous
.
exists
()
else
None
previous_json
=
serializers
.
serialize
(
'
json
'
,
[
previous
,
]
)[
1
:
-
1
]
if
previous
else
None
instance_json
=
serializers
.
serialize
(
'
json
'
,
[
instance
,
])[
1
:
-
1
]
if
previous_json
==
instance_json
:
...
...
@@ -86,11 +96,11 @@ def save_object(sender, instance, **kwargs):
instance_pk
=
instance
.
pk
,
previous
=
previous_json
,
data
=
instance_json
,
action
=
(
"
edit
"
if
previous
.
exists
()
else
"
create
"
)
action
=
(
"
edit
"
if
previous
else
"
create
"
)
).
save
()
@receiver
(
p
re
_delete
)
@receiver
(
p
ost
_delete
)
def
delete_object
(
sender
,
instance
,
**
kwargs
):
# noinspection PyProtectedMember
if
instance
.
_meta
.
label_lower
in
EXCLUDED
:
...
...
This diff is collapsed.
Click to expand it.
apps/member/apps.py
+
2
−
2
View file @
9cd050e2
...
...
@@ -6,7 +6,7 @@ from django.conf import settings
from
django.db.models.signals
import
post_save
from
django.utils.translation
import
gettext_lazy
as
_
from
.signals
import
save_user_
not
e
from
.signals
import
save_user_
profil
e
class
MemberConfig
(
AppConfig
):
...
...
@@ -18,6 +18,6 @@ class MemberConfig(AppConfig):
Define app internal signals to interact with other apps
"""
post_save
.
connect
(
save_user_
not
e
,
save_user_
profil
e
,
sender
=
settings
.
AUTH_USER_MODEL
,
)
This diff is collapsed.
Click to expand it.
apps/member/signals.py
+
2
−
2
View file @
9cd050e2
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
def
save_user_
not
e
(
instance
,
created
,
raw
,
**
_kwargs
):
def
save_user_
profil
e
(
instance
,
created
,
raw
,
**
_kwargs
):
"""
Hook to create and save a profile when an user is updated if it is not registered with the signup form
"""
...
...
@@ -11,5 +11,5 @@ def save_user_note(instance, created, raw, **_kwargs):
if
created
:
from
.models
import
Profile
Profile
.
objects
.
get_or_create
(
user
=
instance
)
#
Profile.objects.get_or_create(user=instance)
instance
.
profile
.
save
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment