Skip to content
Snippets Groups Projects
Commit 277f29bc authored by Martin Burchell's avatar Martin Burchell
Browse files

Merge branch 'add_multiple_terms_api' into tagging_frontend

parents f9fe28b7 74f7a277
No related branches found
No related tags found
1 merge request!46Tagging frontend
...@@ -44,7 +44,7 @@ class Message(DataLayerModel): ...@@ -44,7 +44,7 @@ class Message(DataLayerModel):
if not all(t.taxonomy == taxonomy for t in terms): if not all(t.taxonomy == taxonomy for t in terms):
raise ItemTermException("Terms cannot be applied from different taxonomies") raise ItemTermException("Terms cannot be applied from different taxonomies")
if taxonomy.is_optional: if not taxonomy.is_multiple:
if len(terms) > 1: if len(terms) > 1:
message = "Taxonomy '%s' does not support multiple terms" % taxonomy message = "Taxonomy '%s' does not support multiple terms" % taxonomy
raise ItemTermException(message) raise ItemTermException(message)
......
...@@ -138,7 +138,7 @@ def test_apply_terms_adds_term_for_tags(): ...@@ -138,7 +138,7 @@ def test_apply_terms_adds_term_for_tags():
taxonomy = TaxonomyFactory(multiplicity='multiple') taxonomy = TaxonomyFactory(multiplicity='multiple')
term1 = TermFactory(taxonomy=taxonomy) term1 = TermFactory(taxonomy=taxonomy)
term2 = TermFactory(taxonomy=taxonomy) term2 = TermFactory(taxonomy=taxonomy)
assert not taxonomy.is_optional assert taxonomy.is_multiple
item.apply_terms(term1) item.apply_terms(term1)
assert list(item.terms.all()) == [term1] assert list(item.terms.all()) == [term1]
......
...@@ -24,10 +24,6 @@ class Taxonomy(models.Model): ...@@ -24,10 +24,6 @@ class Taxonomy(models.Model):
self.slug = slugify(self.name) self.slug = slugify(self.name)
super(Taxonomy, self).save(*args, **kwargs) super(Taxonomy, self).save(*args, **kwargs)
@property
def is_optional(self):
return self.multiplicity == 'optional'
def __unicode__(self): def __unicode__(self):
return self.name return self.name
...@@ -42,6 +38,14 @@ class Taxonomy(models.Model): ...@@ -42,6 +38,14 @@ class Taxonomy(models.Model):
max_length=30, max_length=30,
) )
@property
def is_optional(self):
return self.multiplicity == 'optional'
@property
def is_multiple(self):
return self.multiplicity == 'multiple'
vocabulary = models.CharField( vocabulary = models.CharField(
choices=( choices=(
('fixed', _('Not modifiable by any user, system only')), ('fixed', _('Not modifiable by any user, system only')),
......
...@@ -52,6 +52,20 @@ def test_is_optional_false_for_multiplicity_multiple(): ...@@ -52,6 +52,20 @@ def test_is_optional_false_for_multiplicity_multiple():
assert not taxonomy.is_optional assert not taxonomy.is_optional
@pytest.mark.django_db
def test_is_multiple_false_for_multiplicity_optional():
taxonomy = TaxonomyFactory(multiplicity='optional')
assert not taxonomy.is_multiple
@pytest.mark.django_db
def test_is_multiple_true_for_multiplicity_multiple():
taxonomy = TaxonomyFactory(multiplicity='multiple')
assert taxonomy.is_multiple
@pytest.mark.django_db @pytest.mark.django_db
def test_is_open_true_for_vocabulary_open(): def test_is_open_true_for_vocabulary_open():
taxonomy = TaxonomyFactory(vocabulary='open') taxonomy = TaxonomyFactory(vocabulary='open')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment