From e4ec030a7fd2aa76d00b62309da4bba4f352a526 Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Wed, 6 May 2020 11:32:38 +0200
Subject: [PATCH] DOC: update CHANGELOG and Docstring

---
 CHANGELOG.md                |  3 +++
 src/caosdb/common/models.py | 30 ++++++++++++++++++++++--------
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f72543af..007370aa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed ###
 
+* `get_property` method also accepts instances of properties now, e.g.
+  `record.get_property(Property(name="length"))`
+
 ### Deprecated ###
 
 ### Removed ###
diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py
index d5a56257..ca13c23e 100644
--- a/src/caosdb/common/models.py
+++ b/src/caosdb/common/models.py
@@ -537,23 +537,37 @@ class Entity(object):
 
         return self.properties
 
-    def get_property(self, key):
+    def get_property(self, pattern):
+        """ Return the first matching property or None.
+
+        Parameters
+        ----------
+        pattern : str or int or Entity
+            The name or id to look for (case-insensitive) or an Entity where
+            the name or id is used to match the properites of this instance.
+
+        Returns
+        -------
+        property : Property
+            The first Property of this Entity with a matching name or id.
+
+        """
         result = None
-        if hasattr(key, "name"):
-            result = self.get_property(key.name)
-        if result is None and hasattr(key, "id"):
-            result = self.get_property(key.id)
+        if hasattr(pattern, "name"):
+            result = self.get_property(pattern.name)
+        if result is None and hasattr(pattern, "id"):
+            result = self.get_property(pattern.id)
         if result is not None:
             return result
 
-        if isinstance(key, int):
+        if isinstance(pattern, int):
             for p in self.properties:
-                if p.id is not None and int(p.id) == int(key):
+                if p.id is not None and int(p.id) == int(pattern):
                     return p
         else:
             for p in self.properties:
                 if (p.name is not None
-                        and str(p.name).lower() == str(key).lower()):
+                        and str(p.name).lower() == str(pattern).lower()):
 
                     return p
 
-- 
GitLab