From b3159851a99a4ff6a5ee13dbe204cc0a72aff81e Mon Sep 17 00:00:00 2001
From: Markus Scheidgen <markus.scheidgen@gmail.com>
Date: Fri, 20 Dec 2019 13:12:16 +0100
Subject: [PATCH] Added parent_index for openSection in local backend.

---
 common/python/nomadcore/local_backend.py | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/common/python/nomadcore/local_backend.py b/common/python/nomadcore/local_backend.py
index fe7a9bd..d813849 100644
--- a/common/python/nomadcore/local_backend.py
+++ b/common/python/nomadcore/local_backend.py
@@ -86,10 +86,10 @@ class LocalBackend(object):
                                     (ik.name, superSectionNames))
                 self.dataManagers[ik.name] = DataManager(ik, self.sectionManagers[superSectionNames[0]])
 
-    def openSection(self, metaName):
+    def openSection(self, metaName, parent_index: int = -1):
         """opens a new section and returns its new unique gIndex"""
         manager = self.sectionManagers[metaName]
-        newIndex = manager.openSection(self)
+        newIndex = manager.openSection(self, parent_index=parent_index)
         self.__openSections.add((metaName, newIndex))
         return newIndex
 
@@ -613,12 +613,12 @@ class SectionManager(object):
         self.debug = debug
         self.openSections = []
 
-    def openSection(self, backend):
+    def openSection(self, backend, parent_index: int = -1):
         newGIndex = self.lastSectionGIndex + 1
-        self.openSectionWithGIndex(backend, newGIndex)
+        self.openSectionWithGIndex(backend, newGIndex, parent_index=parent_index)
         return newGIndex
 
-    def openSectionWithGIndex(self, backend, gIndex):
+    def openSectionWithGIndex(self, backend, gIndex, parent_index: int = -1):
         self.lastSectionGIndex = gIndex
         references = []
         parents = []
@@ -626,7 +626,8 @@ class SectionManager(object):
         for parentName in self.parentSectionNames:
             pSect = backend.sectionManagers.get(parentName)
             try:
-                parentSection = pSect.openSections[pSect.lastSectionGIndex]
+                parent_section_index = pSect.lastSectionGIndex if parent_index == -1 else parent_index
+                parentSection = pSect.openSections[parent_section_index]
             except IndexError:
                 pass
             except KeyError:
-- 
GitLab