Browse Source

Updated EmClass fields overriding checks (still incomplete)

Yann Weber 8 years ago
parent
commit
a87ade8803
1 changed files with 9 additions and 2 deletions
  1. 9
    2
      lodel/editorial_model/components.py

+ 9
- 2
lodel/editorial_model/components.py View File

93
     # @param emfield EmField : an EmField instance
93
     # @param emfield EmField : an EmField instance
94
     # @warning do not add an EmField allready in another class !
94
     # @warning do not add an EmField allready in another class !
95
     # @throw EditorialModelException if an EmField with same uid allready in this EmClass (overwritting allowed from parents)
95
     # @throw EditorialModelException if an EmField with same uid allready in this EmClass (overwritting allowed from parents)
96
+    # @todo End the override checks (needs methods in data_handlers)
96
     def add_field(self, emfield):
97
     def add_field(self, emfield):
97
         if emfield.uid in self.__fields:
98
         if emfield.uid in self.__fields:
98
             raise EditorialModelException("Duplicated uid '%s' for EmField in this class ( %s )" % (emfield.uid, self))
99
             raise EditorialModelException("Duplicated uid '%s' for EmField in this class ( %s )" % (emfield.uid, self))
100
+        # Incomplete field override check
101
+        if emfield.uid in self.__all_fields:
102
+            parent_field = self.__all_fields[emfield.uid]
103
+            if emfield.data_handler_name != parent_field.data_handler_name:
104
+                raise AttributeError("'%s' field override a parent field, but data_handles are not compatible" % emfield.uid)
99
         self.__fields[emfield.uid] = emfield
105
         self.__fields[emfield.uid] = emfield
100
         emfield._emclass = self
106
         emfield._emclass = self
101
         return emfield
107
         return emfield
102
     
108
     
103
     ## @brief Create a new EmField and add it to the EmClass
109
     ## @brief Create a new EmField and add it to the EmClass
110
+    # @param data_handler str : A DataHandler name
104
     # @param uid str : the EmField uniq id
111
     # @param uid str : the EmField uniq id
105
     # @param **field_kwargs :  EmField constructor parameters ( see @ref EmField.__init__() ) 
112
     # @param **field_kwargs :  EmField constructor parameters ( see @ref EmField.__init__() ) 
106
-    def new_field(self, uid, **field_kwargs):
107
-        return self.add_field(EmField(uid, **field_kwargs))
113
+    def new_field(self, uid, data_handler, **field_kwargs):
114
+        return self.add_field(EmField(uid, data_handler, **field_kwargs))
108
 
115
 
109
     def d_hash(self):
116
     def d_hash(self):
110
         m = hashlib.md5()
117
         m = hashlib.md5()

Loading…
Cancel
Save