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

Changed free tagging taxonomy to be 'tags'

This matches the field name and simplifies the code somewhat
parent 3e464139
No related branches found
No related tags found
1 merge request!46Tagging frontend
......@@ -7,8 +7,8 @@ from django.db import migrations
def create_taxonomy(apps, schema_editor):
Taxonomy = apps.get_model('taxonomies', 'Taxonomy')
taxonomy = Taxonomy(
name='Free Tags',
slug='free-tags',
name='Tags',
slug='tags',
multiplicity='multiple')
taxonomy.save()
......
......@@ -739,12 +739,12 @@ def test_free_tags_created_on_item_update(view, form):
assert 'age 35-40' in terms
taxonomies = [t['taxonomy'] for t in item['terms']]
assert 'free-tags' in taxonomies
assert 'tags' in taxonomies
@pytest.mark.django_db
def test_existing_tag_deleted_on_item_update(view, form):
transport.items.add_free_terms(view.item['id'], 'free-tags', ['age 35-40'])
transport.items.add_free_terms(view.item['id'], 'tags', ['age 35-40'])
form.cleaned_data['tags'] = 'Monrovia'
......@@ -774,7 +774,7 @@ def test_free_tags_created_for_new_item(add_view, form):
assert 'age 35-40' in terms
taxonomies = [t['taxonomy'] for t in item['terms']]
assert 'free-tags' in taxonomies
assert 'tags' in taxonomies
@pytest.mark.django_db
......@@ -782,17 +782,17 @@ def test_form_initial_values_include_tags(generic_item):
with patch('hid.views.item.transport.items.get') as get_item:
generic_item['terms'] = [
{
'taxonomy': 'free-tags',
'taxonomy': 'tags',
'name': 'Monrovia',
'long_name': 'Monrovia',
},
{
'taxonomy': 'free-tags',
'taxonomy': 'tags',
'name': 'age 35-40',
'long_name': 'Age 35-40',
},
{
'taxonomy': 'free-tags',
'taxonomy': 'tags',
'name': 'interesting',
'long_name': 'Interesting',
},
......
......@@ -25,7 +25,7 @@ class ItemNotFound(Exception):
class AddEditItemView(FormView):
template_name = "hid/add_edit_item.html"
form_class = AddEditItemForm
field_taxonomies = {'tags': 'free-tags'}
taxonomy_fields = ('tags',)
tag_delimiter = ','
def _initialize_item(self, item_id, item_type):
......@@ -167,14 +167,10 @@ class AddEditItemView(FormView):
and len(self.item_terms[taxonomy]) > 0):
initial['category'] = self.item_terms[taxonomy][0]['name']
taxonomy_fields = dict(zip(self.field_taxonomies.values(),
self.field_taxonomies.keys()))
for taxonomy, terms in self.item_terms.iteritems():
field_name = taxonomy_fields.get(taxonomy)
if field_name:
if taxonomy in self.taxonomy_fields:
term_names = [t['name'] for t in terms]
initial[field_name] = self.tag_delimiter.join(term_names)
initial[taxonomy] = self.tag_delimiter.join(term_names)
return initial
......@@ -251,9 +247,8 @@ class AddEditItemView(FormView):
regular_fields = {}
for (field_name, field_value) in data.iteritems():
taxonomy = self.field_taxonomies.get(field_name)
if taxonomy is not None:
free_terms[taxonomy] = field_value
if field_name in self.taxonomy_fields:
free_terms[field_name] = field_value
else:
regular_fields[field_name] = field_value
......
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