From 03303363111c66f42c4004b4d57633fb2e848aa3 Mon Sep 17 00:00:00 2001 From: Olivier Keshavjee Date: Sat, 22 Jan 2022 09:53:36 +0100 Subject: [PATCH] Does not simply warn of duplicate IDs, but fixes them. --- manuskript/models/abstractItem.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/manuskript/models/abstractItem.py b/manuskript/models/abstractItem.py index a0f0993..333172d 100644 --- a/manuskript/models/abstractItem.py +++ b/manuskript/models/abstractItem.py @@ -224,15 +224,23 @@ class abstractItem(): if max([self.IDs.count(i) for i in self.IDs if i]) != 1: LOGGER.warning("There are some items with overlapping IDs: %s", [i for i in self.IDs if i and self.IDs.count(i) != 1]) + _IDs = [self.ID()] def checkChildren(item): + "Check recursively every children and give them unique, non-empty, non-zero IDs." for c in item.children(): _id = c.ID() - if not _id or _id == "0": + if not _id or _id == "0" or _id in _IDs: c.getUniqueID() + LOGGER.warning("* Item {} '{}' is given new unique ID: '{}'".format(_id, c.title(), c.ID())) + _IDs.append(_id) checkChildren(c) checkChildren(self) + # Not sure if self.IDs is still useful (it was used in the old unique ID generating system at least). + # It might be deleted everywhere. But just in the meantime, it should at least be up to date. + self.IDs = self.listAllIDs() + def listAllIDs(self): IDs = [self.ID()] for c in self.children():