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
26603a6c
Commit
26603a6c
authored
9 years ago
by
Martin Burchell
Browse files
Options
Downloads
Patches
Plain Diff
Updated item apply_terms to take multiple terms
parent
be880f89
No related branches found
Branches containing commit
No related tags found
2 merge requests
!46
Tagging frontend
,
!45
Add multiple terms api
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
django/website/data_layer/models.py
+10
-4
10 additions, 4 deletions
django/website/data_layer/models.py
django/website/data_layer/tests/item_tests.py
+14
-1
14 additions, 1 deletion
django/website/data_layer/tests/item_tests.py
with
24 additions
and
5 deletions
django/website/data_layer/models.py
+
10
−
4
View file @
26603a6c
...
...
@@ -23,7 +23,7 @@ class Message(DataLayerModel):
terms
=
models
.
ManyToManyField
(
Term
,
related_name
=
"
items
"
)
network_provider
=
models
.
CharField
(
max_length
=
200
,
blank
=
True
)
def
apply_terms
(
self
,
term
):
def
apply_terms
(
self
,
term
s
):
# TODO: test this
"""
Add or replace value of term.taxonomy for current Item
...
...
@@ -37,10 +37,16 @@ class Message(DataLayerModel):
# This should really be built out with an explicity through model
# in taxonomies, with a generic foreign ken to the content type
# being classified, then this logic could live there.
if
term
.
taxonomy
.
is_optional
:
self
.
delete_all_terms
(
term
.
taxonomy
)
if
isinstance
(
terms
,
Term
)
:
terms
=
[
terms
]
self
.
terms
.
add
(
term
)
if
len
(
terms
)
==
1
:
[
term
]
=
terms
if
term
.
taxonomy
.
is_optional
:
self
.
delete_all_terms
(
term
.
taxonomy
)
self
.
terms
.
add
(
*
terms
)
def
delete_all_terms
(
self
,
taxonomy
):
for
term
in
self
.
terms
.
filter
(
taxonomy
=
taxonomy
):
...
...
This diff is collapsed.
Click to expand it.
django/website/data_layer/tests/item_tests.py
+
14
−
1
View file @
26603a6c
...
...
@@ -143,4 +143,17 @@ def test_apply_terms_adds_term_for_tags():
assert
list
(
item
.
terms
.
all
())
==
[
term1
]
item
.
apply_terms
(
term2
)
assert
set
(
item
.
terms
.
all
())
==
set
([
term1
,
term2
])
assert
term1
in
item
.
terms
.
all
()
assert
term2
in
item
.
terms
.
all
()
@pytest.mark.django_db
def
test_apply_terms_adds_multiple_terms
():
item
=
ItemFactory
()
taxonomy
=
TaxonomyFactory
(
multiplicity
=
'
multiple
'
)
term1
=
TermFactory
(
taxonomy
=
taxonomy
)
term2
=
TermFactory
(
taxonomy
=
taxonomy
)
item
.
apply_terms
((
term1
,
term2
))
assert
term1
in
item
.
terms
.
all
()
assert
term2
in
item
.
terms
.
all
()
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