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
135d705d
Commit
135d705d
authored
9 years ago
by
Martin Burchell
Browse files
Options
Downloads
Patches
Plain Diff
Made last_modified on item update when term added
parent
13796d18
Branches
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
+12
-0
12 additions, 0 deletions
django/website/data_layer/models.py
django/website/data_layer/tests/item_tests.py
+15
-0
15 additions, 0 deletions
django/website/data_layer/tests/item_tests.py
with
27 additions
and
0 deletions
django/website/data_layer/models.py
+
12
−
0
View file @
135d705d
from
django.db
import
models
from
django.dispatch.dispatcher
import
receiver
from
django.utils
import
timezone
from
taxonomies.models
import
Term
...
...
@@ -11,6 +12,10 @@ class DataLayerModel(models.Model):
class
Meta
:
abstract
=
True
def
note_external_modification
(
self
):
self
.
last_modified
=
timezone
.
now
()
self
.
save
()
class
Message
(
DataLayerModel
):
body
=
models
.
TextField
()
...
...
@@ -45,3 +50,10 @@ class Message(DataLayerModel):
# TODO: rename this class
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
()
This diff is collapsed.
Click to expand it.
django/website/data_layer/tests/item_tests.py
+
15
−
0
View file @
135d705d
...
...
@@ -4,6 +4,7 @@ from django.utils import timezone
from
factories
import
ItemFactory
from
..models
import
Item
from
taxonomies.tests.factories
import
TermFactory
import
datetime
from
mock
import
patch
,
MagicMock
...
...
@@ -35,3 +36,17 @@ def test_last_modified_date_updates_on_body_change():
item
.
save
()
assert
orig_last_modified
<
last_modified
(
item
)
@pytest.mark.django_db
def
test_last_modified_date_updates_on_category_change
():
item
=
ItemFactory
()
magic_mock
=
MagicMock
(
wraps
=
timezone
.
now
,
side_effect
=
now_iter
(
timezone
.
now
()))
with
patch
(
'
django.utils.timezone.now
'
,
new
=
magic_mock
):
orig_last_modified
=
last_modified
(
item
)
term
=
TermFactory
()
item
.
terms
.
add
(
term
)
assert
orig_last_modified
<
last_modified
(
item
)
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