Browse Source

Small changes in Datahandlers

- deletion of unused attributes
- copy the back_reference checks in _set_back_reference function and use it in Reference.__init__()
Yann Weber 8 years ago
parent
commit
0fc8616c02
2 changed files with 12 additions and 11 deletions
  1. 11
    10
      lodel/leapi/datahandlers/base_classes.py
  2. 1
    1
      lodel/leapi/datahandlers/references.py

+ 11
- 10
lodel/leapi/datahandlers/base_classes.py View File

@@ -31,7 +31,6 @@ class DataHandler(object):
31 31
     ##@brief List fields that will be exposed to the construct_data_method
32 32
     _construct_datas_deps = []
33 33
     
34
-    directly_editable = True
35 34
     ##@brief constructor
36 35
     # @param internal False | str : define whether or not a field is internal
37 36
     # @param immutable bool : indicates if the fieldtype has to be defined in child classes of LeObject or if it is
@@ -251,15 +250,11 @@ class Reference(DataHandler):
251 250
     # @param internal bool : if False, the field is not internal
252 251
     # @param **kwargs : other arguments
253 252
     def __init__(self, allowed_classes = None, back_reference = None, internal=False, **kwargs):
253
+        ##@brief set of allowed LeObject child classes
254 254
         self.__allowed_classes = set() if allowed_classes is None else set(allowed_classes)
255
-        self.allowed_classes = list() if allowed_classes is None else allowed_classes
256
-        
257
-        if back_reference is not None:
258
-            if len(back_reference) != 2:
259
-                raise ValueError("A tuple (classname, fieldname) expected but got '%s'" % back_reference)
260
-            #if not issubclass(lodel.leapi.leobject.LeObject, back_reference[0]) or not isinstance(back_reference[1], str):
261
-            #    raise TypeError("Back reference was expected to be a tuple(<class LeObject>, str) but got : (%s, %s)" % (back_reference[0], back_reference[1]))
262
-        self.__back_reference = back_reference
255
+        ##@brief Stores back references informations
256
+        self.__back_reference = None
257
+        self.__set_back_reference(back_reference)
263 258
         super().__init__(internal=internal, **kwargs)
264 259
     
265 260
     @property
@@ -271,7 +266,13 @@ class Reference(DataHandler):
271 266
         return copy.copy(self.__allowed_classes)
272 267
 
273 268
     ##@brief Set the back reference for this field.
274
-    def _set_back_reference(self, back_reference):
269
+    def __set_back_reference(self, back_reference):
270
+        if back_reference is None:
271
+            return
272
+        if len(back_reference) != 2:
273
+            raise LodelDataHandlerException("A tuple(LeObjectChild, fieldname) \
274
+expected but got '%s'" % back_reference)
275
+        
275 276
         self.__back_reference = back_reference
276 277
 
277 278
     ##@brief Check value

+ 1
- 1
lodel/leapi/datahandlers/references.py View File

@@ -74,7 +74,6 @@ class Map(MultipleRef):
74 74
 ##@brief This Reference class is designed to handler hierarchy with some constraint
75 75
 class Hierarch(MultipleRef):
76 76
     
77
-    directly_editable = False
78 77
     ##@brief Instanciate a data handler handling hierarchical relation with constraints
79 78
     # @param back_reference tuple : Here it is mandatory to have a back ref (like a parent field)
80 79
     # @param max_depth int | None :  limit of depth
@@ -91,3 +90,4 @@ class Hierarch(MultipleRef):
91 90
         else:
92 91
             return None, FieldValidationError("Set or string expected for a set field")
93 92
         return val, expt
93
+

Loading…
Cancel
Save