change item natural key def to include the collection name
authorymh <ymh.work@gmail.com>
Sat, 23 Jun 2018 01:59:36 +0200
changeset 547 f19bef104a77
parent 546 59d7cb99f4df
child 548 87ca5b16bea1
change item natural key def to include the collection name
src/iconolab/__init__.py
src/iconolab/migrations/0029_auto_itemmetadata_metadata_data.py
src/iconolab/models.py
src/iconolab/templates/partials/header_breadcrumbs.html
--- a/src/iconolab/__init__.py	Fri Jun 22 11:33:17 2018 +0200
+++ b/src/iconolab/__init__.py	Sat Jun 23 01:59:36 2018 +0200
@@ -1,4 +1,4 @@
-VERSION = (0, 1, 0, "final", 0)
+VERSION = (0, 1, 1, "final", 0)
 
 VERSION_STR = ".".join(map(lambda i:"%02d" % (i,), VERSION[:2]))
 
--- a/src/iconolab/migrations/0029_auto_itemmetadata_metadata_data.py	Fri Jun 22 11:33:17 2018 +0200
+++ b/src/iconolab/migrations/0029_auto_itemmetadata_metadata_data.py	Sat Jun 23 01:59:36 2018 +0200
@@ -25,7 +25,7 @@
         }
 
         item_metadata.metadata = json.dumps(new_metadata)
-        item_metadata.natural_key = item_metadata.joconde_ref
+        item_metadata.natural_key = "%s|%s" % (item_metadata.collection.name, item_metadata.joconde_ref)
         item_metadata.save()
 
 class Migration(migrations.Migration):
--- a/src/iconolab/models.py	Fri Jun 22 11:33:17 2018 +0200
+++ b/src/iconolab/models.py	Sat Jun 23 01:59:36 2018 +0200
@@ -136,11 +136,14 @@
 
     def __init__(self, *args, **kwargs):
         self.__metadata_obj = None
+        self.__raw_natural_key = None
         super().__init__(*args, **kwargs)
 
     def __setattr__(self, name, value):
         if name == 'metadata':
             self.__metadata_obj = None
+        elif name == 'natural_key'
+            self.__raw_natural_key = None
         return super().__setattr__(name, value)
 
     @property
@@ -149,6 +152,12 @@
             self.__metadata_obj = json.loads(self.metadata)
         return self.__metadata_obj
 
+    @property
+    def raw_natural_key(self):
+        if self.__raw_natural_key is None:
+            self.__raw_natural_key = (self.natural_key or "").split("|")[-1]
+        return self.__raw_natural_key
+
 
     def __str__(self):
         return "metadatas:for:" + str(self.item.item_guid)
--- a/src/iconolab/templates/partials/header_breadcrumbs.html	Fri Jun 22 11:33:17 2018 +0200
+++ b/src/iconolab/templates/partials/header_breadcrumbs.html	Sat Jun 23 01:59:36 2018 +0200
@@ -6,9 +6,9 @@
   {% else %}
     <li><a href="{% url 'collection_home' collection.name %}">Fond {{collection.verbose_name}}</a></li>
     {% if not annotation %}
-      <li class="active">Objet {{ item.metadatas.natural_key }}</li>
+      <li class="active">Objet {{ item.metadatas.raw_natural_key }}</li>
     {% else %}
-      <li><a href="{% url 'item_detail' collection.name image.item.item_guid %}">Objet {{ image.item.metadatas.natural_key }}</a></li>
+      <li><a href="{% url 'item_detail' collection.name image.item.item_guid %}">Objet {{ image.item.metadatas.raw_natural_key }}</a></li>
       {% if not revision %}
         <li class="active">Annotation</li>
       {% else %}