diff --git a/codelist/autocomplete/biotope.py b/codelist/autocomplete/biotope.py
index 7e8047ed..4fe1e30b 100644
--- a/codelist/autocomplete/biotope.py
+++ b/codelist/autocomplete/biotope.py
@@ -109,3 +109,6 @@ class BiotopeExtraCodeAutocomplete(KonovaCodeAutocomplete):
def get_result_label(self, result):
return f"{result.long_name} ({result.short_name})"
+
+ def get_selected_result_label(self, result):
+ return f"{result.parent.short_name} > {result.long_name} ({result.short_name})"
\ No newline at end of file
diff --git a/codelist/migrations/0002_migrate_975_to_288.py b/codelist/migrations/0002_migrate_975_to_288.py
new file mode 100644
index 00000000..cf0d87cf
--- /dev/null
+++ b/codelist/migrations/0002_migrate_975_to_288.py
@@ -0,0 +1,49 @@
+# Generated by Django 5.0.7 on 2024-08-06 13:40
+
+from django.db import migrations
+from django.db.models import Q
+
+from codelist.settings import CODELIST_BIOTOPES_EXTRA_CODES_FULL_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID
+
+
+def migrate_975_to_288(apps, schema_editor):
+ KonovaCodeList = apps.get_model('codelist', 'KonovaCodeList')
+ CompensationState = apps.get_model('compensation', 'CompensationState')
+
+ list_288 = KonovaCodeList.objects.get(
+ id=CODELIST_BIOTOPES_EXTRA_CODES_FULL_ID
+ ).codes.all()
+
+ states_with_extra_code = CompensationState.objects.filter(
+ ~Q(biotope_type_details=None)
+ )
+
+ print(f"... Found {states_with_extra_code.count()} biotope state entries")
+ for state in states_with_extra_code:
+ extra_codes_975 = state.biotope_type_details.filter(
+ code_lists__in=[CODELIST_BIOTOPES_EXTRA_CODES_ID]
+ )
+ count_extra_codes_975 = extra_codes_975.count()
+ if count_extra_codes_975 > 0:
+ print(f" --> Found {count_extra_codes_975} codes from list 975 in biotope entry {state.id}")
+ extra_codes_288 = []
+ for extra_code_975 in extra_codes_975:
+ atom_id = extra_code_975.atom_id
+ codes_from_288 = list_288.filter(
+ atom_id=atom_id,
+ )
+ extra_codes_288 += codes_from_288
+
+ state.biotope_type_details.set(extra_codes_288)
+ print(" --> Migrated to list 288 for all biotope entries")
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('codelist', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.RunPython(migrate_975_to_288)
+ ]
diff --git a/codelist/models.py b/codelist/models.py
index 4821d9aa..1bd5da32 100644
--- a/codelist/models.py
+++ b/codelist/models.py
@@ -25,13 +25,11 @@ class KonovaCode(models.Model):
)
short_name = models.CharField(
max_length=500,
- null=True,
blank=True,
help_text="Short version of long name",
)
long_name = models.CharField(
max_length=1000,
- null=True,
blank=True,
help_text="",
)
@@ -54,12 +52,17 @@ class KonovaCode(models.Model):
long_name = self.long_name
short_name = self.short_name
- both_names_exist = long_name and short_name
+ both_names_exist = long_name is not None and short_name is not None
if both_names_exist:
- if with_parent:
- if self.parent and self.parent.long_name:
+ if with_parent and self.parent:
+ parent_short_name_exists = self.parent.short_name is not None
+ parent_long_name_exists = self.parent.long_name is not None
+ if parent_long_name_exists:
ret_val += self.parent.long_name + " > "
+ elif parent_short_name_exists:
+ ret_val += self.parent.short_name + " > "
+
ret_val += long_name
if short_name and short_name != long_name:
diff --git a/compensation/templates/compensation/detail/compensation/includes/actions.html b/compensation/templates/compensation/detail/compensation/includes/actions.html
index e4ec5b60..d832ad10 100644
--- a/compensation/templates/compensation/detail/compensation/includes/actions.html
+++ b/compensation/templates/compensation/detail/compensation/includes/actions.html
@@ -52,7 +52,7 @@
{% endfor %}
{% for detail in action.action_type_details.all %}
- {{detail.long_name}}
+ {{ detail.parent.long_name }} > {{detail.long_name}}
{% empty %}
{% trans 'No action type details' %}
{% endfor %}
diff --git a/compensation/templates/compensation/detail/compensation/includes/states-after.html b/compensation/templates/compensation/detail/compensation/includes/states-after.html
index dfda6aee..39e62048 100644
--- a/compensation/templates/compensation/detail/compensation/includes/states-after.html
+++ b/compensation/templates/compensation/detail/compensation/includes/states-after.html
@@ -51,7 +51,7 @@
{{ state.biotope_type.parent.long_name }} {% fa5_icon 'angle-right' %} {{ state.biotope_type.long_name }} ({{state.biotope_type.short_name}})
{% for detail in state.biotope_type_details.all %}
- {{detail.long_name}}
+ {{ detail.parent.short_name }} > {{ detail.long_name }}
{% empty %}
{% trans 'No biotope type details' %}
{% endfor %}
diff --git a/compensation/templates/compensation/detail/compensation/includes/states-before.html b/compensation/templates/compensation/detail/compensation/includes/states-before.html
index ff3d2673..25524c0c 100644
--- a/compensation/templates/compensation/detail/compensation/includes/states-before.html
+++ b/compensation/templates/compensation/detail/compensation/includes/states-before.html
@@ -51,7 +51,7 @@
{{ state.biotope_type.parent.long_name }} {% fa5_icon 'angle-right' %} {{ state.biotope_type.long_name }} ({{state.biotope_type.short_name}})
{% for detail in state.biotope_type_details.all %}
- {{detail.long_name}}
+ {{ detail.parent.short_name }} > {{ detail.long_name }}
{% empty %}
{% trans 'No biotope type details' %}
{% endfor %}
diff --git a/compensation/templates/compensation/detail/eco_account/includes/actions.html b/compensation/templates/compensation/detail/eco_account/includes/actions.html
index 52f86486..d83820a2 100644
--- a/compensation/templates/compensation/detail/eco_account/includes/actions.html
+++ b/compensation/templates/compensation/detail/eco_account/includes/actions.html
@@ -51,7 +51,7 @@
{% endfor %}
{% for detail in action.action_type_details.all %}
- {{detail.long_name}}
+ {{ detail.parent.long_name }} > {{detail.long_name}}
{% empty %}
{% trans 'No action type details' %}
{% endfor %}
diff --git a/compensation/templates/compensation/detail/eco_account/includes/states-after.html b/compensation/templates/compensation/detail/eco_account/includes/states-after.html
index d188f081..02ac15c1 100644
--- a/compensation/templates/compensation/detail/eco_account/includes/states-after.html
+++ b/compensation/templates/compensation/detail/eco_account/includes/states-after.html
@@ -51,7 +51,7 @@
{{ state.biotope_type.parent.long_name }} {% fa5_icon 'angle-right' %} {{ state.biotope_type.long_name }} ({{state.biotope_type.short_name}})
{% for detail in state.biotope_type_details.all %}
- {{detail.long_name}}
+ {{ detail.parent.short_name }} > {{ detail.long_name }}
{% empty %}
{% trans 'No biotope type details' %}
{% endfor %}
diff --git a/compensation/templates/compensation/detail/eco_account/includes/states-before.html b/compensation/templates/compensation/detail/eco_account/includes/states-before.html
index 56fe0b07..135c4c03 100644
--- a/compensation/templates/compensation/detail/eco_account/includes/states-before.html
+++ b/compensation/templates/compensation/detail/eco_account/includes/states-before.html
@@ -51,7 +51,7 @@
{{ state.biotope_type.parent.long_name }} {% fa5_icon 'angle-right' %} {{ state.biotope_type.long_name }} ({{state.biotope_type.short_name}})
{% for detail in state.biotope_type_details.all %}
- {{detail.long_name}}
+ {{ detail.parent.short_name }} > {{ detail.long_name }}
{% empty %}
{% trans 'No biotope type details' %}
{% endfor %}
diff --git a/ema/templates/ema/detail/includes/actions.html b/ema/templates/ema/detail/includes/actions.html
index 8a77c79d..0088bfe8 100644
--- a/ema/templates/ema/detail/includes/actions.html
+++ b/ema/templates/ema/detail/includes/actions.html
@@ -49,7 +49,7 @@
{% endfor %}
{% for detail in action.action_type_details.all %}
- {{detail.long_name}}
+ {{ detail.parent.long_name }} > {{detail.long_name}}
{% empty %}
{% trans 'No action type details' %}
{% endfor %}
diff --git a/ema/templates/ema/detail/includes/states-after.html b/ema/templates/ema/detail/includes/states-after.html
index 0277e021..fbee2899 100644
--- a/ema/templates/ema/detail/includes/states-after.html
+++ b/ema/templates/ema/detail/includes/states-after.html
@@ -49,7 +49,7 @@
{{ state.biotope_type.parent.long_name }} {% fa5_icon 'angle-right' %} {{ state.biotope_type.long_name }} ({{state.biotope_type.short_name}})
{% for detail in state.biotope_type_details.all %}
- {{detail.long_name}}
+ {{ detail.parent.short_name }} > {{ detail.long_name }}
{% empty %}
{% trans 'No biotope type details' %}
{% endfor %}
diff --git a/ema/templates/ema/detail/includes/states-before.html b/ema/templates/ema/detail/includes/states-before.html
index f0d4eddd..a69709ad 100644
--- a/ema/templates/ema/detail/includes/states-before.html
+++ b/ema/templates/ema/detail/includes/states-before.html
@@ -49,7 +49,7 @@
{{ state.biotope_type.parent.long_name }} {% fa5_icon 'angle-right' %} {{ state.biotope_type.long_name }} ({{state.biotope_type.short_name}})
{% for detail in state.biotope_type_details.all %}
- {{detail.long_name}}
+ {{ detail.parent.short_name }} > {{ detail.long_name }}
{% empty %}
{% trans 'No biotope type details' %}
{% endfor %}