Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
internewshid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
aptivate
client-projects
internewshid
Commits
19a41aee
Commit
19a41aee
authored
9 years ago
by
Martin Burchell
Browse files
Options
Downloads
Patches
Plain Diff
Fixed multiple updates of item last_modified field
parent
135d705d
No related branches found
Branches containing commit
No related tags found
1 merge request
!7
Data Layer updates a "last edit date" field on the Item
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
django/website/data_layer/models.py
+4
-3
4 additions, 3 deletions
django/website/data_layer/models.py
django/website/data_layer/tests/item_tests.py
+13
-3
13 additions, 3 deletions
django/website/data_layer/tests/item_tests.py
with
17 additions
and
6 deletions
django/website/data_layer/models.py
+
4
−
3
View file @
19a41aee
...
...
@@ -13,7 +13,7 @@ class DataLayerModel(models.Model):
abstract
=
True
def
note_external_modification
(
self
):
self
.
last_modified
=
timezone
.
now
()
# This will set the last_modified field
self
.
save
()
...
...
@@ -55,5 +55,6 @@ Item = Message
@receiver
(
models
.
signals
.
m2m_changed
,
sender
=
Item
.
terms
.
through
,
dispatch_uid
=
"
data_layer.models.terms_signal_handler
"
)
def
terms_signal_handler
(
sender
,
**
kwargs
):
instance
=
kwargs
.
get
(
'
instance
'
)
instance
.
note_external_modification
()
if
kwargs
.
get
(
'
action
'
)
==
'
post_add
'
:
instance
=
kwargs
.
get
(
'
instance
'
)
instance
.
note_external_modification
()
This diff is collapsed.
Click to expand it.
django/website/data_layer/tests/item_tests.py
+
13
−
3
View file @
19a41aee
...
...
@@ -17,13 +17,23 @@ def last_modified(item):
# Ensure value of "now" always increases by amount sufficient
# to show up as a change, even if db resolution for datetime
# is one second.
def
time_granularity
():
return
datetime
.
timedelta
(
hours
=
1
)
def
now_iter
(
start
):
t
=
start
while
True
:
t
+=
datetime
.
timedelta
(
hours
=
1
)
t
+=
time_granularity
(
)
yield
t
def
num_updates
(
old_time
,
new_time
):
elapsed_time
=
new_time
-
old_time
return
elapsed_time
.
seconds
/
time_granularity
().
seconds
@pytest.mark.django_db
def
test_last_modified_date_updates_on_body_change
():
item
=
ItemFactory
()
...
...
@@ -35,7 +45,7 @@ def test_last_modified_date_updates_on_body_change():
item
.
body
=
'
replacement text
'
item
.
save
()
assert
orig_last_modified
<
last_modified
(
item
)
assert
num_updates
(
orig_last_modified
,
last_modified
(
item
)
)
==
1
@pytest.mark.django_db
...
...
@@ -49,4 +59,4 @@ def test_last_modified_date_updates_on_category_change():
term
=
TermFactory
()
item
.
terms
.
add
(
term
)
assert
orig_last_modified
<
last_modified
(
item
)
assert
num_updates
(
orig_last_modified
,
last_modified
(
item
)
)
==
1
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