From 33c581a018967fe8a1c064d38d34356bb145ce6c Mon Sep 17 00:00:00 2001
From: vermeul <swen@ethz.ch>
Date: Fri, 15 Dec 2017 15:01:29 +0100
Subject: [PATCH] added get_sample for project; corrected autoGeneratedCode
 detection

---
 src/python/PyBis/pybis/pybis.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/python/PyBis/pybis/pybis.py b/src/python/PyBis/pybis/pybis.py
index c17a6bb2382..966e2bb903f 100644
--- a/src/python/PyBis/pybis/pybis.py
+++ b/src/python/PyBis/pybis/pybis.py
@@ -3001,8 +3001,8 @@ class AttrHolder():
             raise KeyError("you can not modify the {}".format(name))
         elif name == "code":
             try:
-                if self._type.data['autoGeneratedCode']:
-                    raise KeyError("for this {}Type you can not set a code".format(self.entity))
+                if self._type['autoGeneratedCode']:
+                    raise KeyError("This {}Type has auto-generated code. You cannot set a code".format(self.entity))
             except AttributeError:
                 pass
 
@@ -3801,6 +3801,13 @@ class Project(OpenBisObject):
     def get_samples(self, **kwargs):
         return self.openbis.get_samples(project=self.permId, **kwargs)
 
+    def get_sample(self, sample_code):
+        if is_identifier(sample_code) or is_permid(sample_code):
+            return self.openbis.get_sample(sample_code)
+        else:
+            # we assume we just got the code
+            return self.openbis.get_sample(project=self, code=sample_code)
+
     get_objects = get_samples # Alias
 
     def get_experiments(self):
-- 
GitLab