Bladeren bron

Updated EmClass fields overriding checks (still incomplete)

Yann Weber 8 jaren geleden
bovenliggende
commit
a87ade8803
1 gewijzigde bestanden met toevoegingen van 9 en 2 verwijderingen
  1. 9
    2
      lodel/editorial_model/components.py

+ 9
- 2
lodel/editorial_model/components.py Bestand weergeven

@@ -93,18 +93,25 @@ class EmClass(EmComponent):
93 93
     # @param emfield EmField : an EmField instance
94 94
     # @warning do not add an EmField allready in another class !
95 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 97
     def add_field(self, emfield):
97 98
         if emfield.uid in self.__fields:
98 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 105
         self.__fields[emfield.uid] = emfield
100 106
         emfield._emclass = self
101 107
         return emfield
102 108
     
103 109
     ## @brief Create a new EmField and add it to the EmClass
110
+    # @param data_handler str : A DataHandler name
104 111
     # @param uid str : the EmField uniq id
105 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 116
     def d_hash(self):
110 117
         m = hashlib.md5()

Loading…
Annuleren
Opslaan