Author: jmorliaguet
Date: Sun Apr  9 23:03:47 2006
New Revision: 2802

Modified:
   cpsskins/branches/jmo-perspectives/elements/element.py
Log:

- simpler code to avoid duplicates



Modified: cpsskins/branches/jmo-perspectives/elements/element.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/elements/element.py      (original)
+++ cpsskins/branches/jmo-perspectives/elements/element.py      Sun Apr  9 
23:03:47 2006
@@ -33,6 +33,10 @@
 from cpsskins.relations.interfaces import IRelatable
 from cpsskins.setup.interfaces import IResourceType
 
+def uniq(seq):
+    set = {}
+    return [set.setdefault(e, e) for e in seq if e not in set]
+
 class Element(Contained):
     """An element
     """
@@ -78,12 +82,8 @@
             relatable = IRelatable(getParent(element), u'')
         identifier = str(relatable)
 
-        parts = elementname, resourcename
-        if contentname != resourcename:
-            parts += contentname,
-        parts += identifier,
-
-        return '-'.join(parts)
+        prefix = uniq([elementname, resourcename, contentname])
+        return '-'.join(prefix + [identifier])
 
 class Node(Element):
     """A Node is an element in a tree structure.
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to