Browse Source

EmField: type attribute is now called fieldtype

ArnAud 9 years ago
parent
commit
9131f7bcd2
3 changed files with 15 additions and 19 deletions
  1. 0
    1
      EditorialModel/components.py
  2. 8
    11
      EditorialModel/model.py
  3. 7
    7
      EditorialModel/test/me.json

+ 0
- 1
EditorialModel/components.py View File

83
                 attr[attr_f] = attr[attr_f].__str__()
83
                 attr[attr_f] = attr[attr_f].__str__()
84
         if isinstance(self, EditorialModel.fields.EmField):
84
         if isinstance(self, EditorialModel.fields.EmField):
85
             attr['component'] = 'EmField'
85
             attr['component'] = 'EmField'
86
-            attr['type'] = self.fieldtype
87
         else:
86
         else:
88
             attr['component'] = self.__class__.__name__
87
             attr['component'] = self.__class__.__name__
89
         return attr
88
         return attr

+ 8
- 11
EditorialModel/model.py View File

53
     ## Given a python class return a name
53
     ## Given a python class return a name
54
     # @param cls : The python class we want the name
54
     # @param cls : The python class we want the name
55
     # @return A class name as string or False if cls is not an EmComponent child class
55
     # @return A class name as string or False if cls is not an EmComponent child class
56
+    # @todo réécrire le split, c'est pas bô
56
     def name_from_emclass(em_class):
57
     def name_from_emclass(em_class):
57
         if em_class not in Model.components_class:
58
         if em_class not in Model.components_class:
58
             spl = em_class.__module__.split('.')
59
             spl = em_class.__module__.split('.')
72
             #Store and delete the EmComponent class name from datas
73
             #Store and delete the EmComponent class name from datas
73
             cls_name = kwargs['component']
74
             cls_name = kwargs['component']
74
             del kwargs['component']
75
             del kwargs['component']
75
-            
76
+
76
             if cls_name == 'EmField':
77
             if cls_name == 'EmField':
77
                 #Special EmField process because of fieldtypes
78
                 #Special EmField process because of fieldtypes
78
-                if not 'type' in kwargs:
79
-                    raise AttributeError("Missing 'type' from EmField instanciation")
80
-                cls = EditorialModel.fields.EmField.get_field_class(kwargs['type'])
81
-                kwargs['fieldtype'] = kwargs['type']
82
-                del(kwargs['type'])
79
+                if not 'fieldtype' in kwargs:
80
+                    raise AttributeError("Missing 'fieldtype' from EmField instanciation")
81
+                cls = EditorialModel.fields.EmField.get_field_class(kwargs['fieldtype'])
83
             else:
82
             else:
84
                 cls = self.emclass_from_name(cls_name)
83
                 cls = self.emclass_from_name(cls_name)
85
 
84
 
150
     # @todo Handle a raise from the migration handler
149
     # @todo Handle a raise from the migration handler
151
     # @todo Transform the datas arg in **datas ?
150
     # @todo Transform the datas arg in **datas ?
152
     def create_component(self, component_type, datas, uid=None):
151
     def create_component(self, component_type, datas, uid=None):
153
-        
154
         if component_type == 'EmField':
152
         if component_type == 'EmField':
155
             #special process for EmField
153
             #special process for EmField
156
-            if not 'type' in datas:
157
-                raise AttributeError("Missing 'type' from EmField instanciation")
158
-            em_obj = EditorialModel.fields.EmField.get_field_class(datas['type'])
159
-            del(datas['type'])
154
+            if not 'fieldtype' in datas:
155
+                raise AttributeError("Missing 'fieldtype' from EmField instanciation")
156
+            em_obj = EditorialModel.fields.EmField.get_field_class(datas['fieldtype'])
160
         else:
157
         else:
161
             em_obj = self.emclass_from_name(component_type)
158
             em_obj = self.emclass_from_name(component_type)
162
 
159
 

+ 7
- 7
EditorialModel/test/me.json View File

9
     "component":"EmFieldGroup", "name":"info", "string":"{\"fre\":\"Info\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1"
9
     "component":"EmFieldGroup", "name":"info", "string":"{\"fre\":\"Info\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1"
10
   },
10
   },
11
   "4" : {
11
   "4" : {
12
-    "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"3", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
12
+    "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "fieldtype":"char", "fieldgroup_id":"3", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
13
   },
13
   },
14
   "5" : {
14
   "5" : {
15
     "component":"EmType", "name":"article", "string":"{\"fre\":\"Article\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1", "icon":"0", "sortcolumn":"rank", "fields_list":[7], "superiors_list":{"parent":14}
15
     "component":"EmType", "name":"article", "string":"{\"fre\":\"Article\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1", "icon":"0", "sortcolumn":"rank", "fields_list":[7], "superiors_list":{"parent":14}
18
     "component":"EmType", "name":"personne", "string":"{\"fre\":\"Personne\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2", "icon":"0", "sortcolumn":"rank", "fields_list":[10]
18
     "component":"EmType", "name":"personne", "string":"{\"fre\":\"Personne\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2", "icon":"0", "sortcolumn":"rank", "fields_list":[10]
19
   },
19
   },
20
   "7" : {
20
   "7" : {
21
-    "component":"EmField", "name":"soustitre", "string":"{\"fre\":\"Sous-titre\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"3", "rel_field_id":"", "optional":1, "internal":"", "icon":"0"
21
+    "component":"EmField", "name":"soustitre", "string":"{\"fre\":\"Sous-titre\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "fieldtype":"char", "fieldgroup_id":"3", "rel_field_id":"", "optional":1, "internal":"", "icon":"0"
22
   },
22
   },
23
   "8" : {
23
   "8" : {
24
     "component":"EmFieldGroup", "name":"civilité", "string":"{\"fre\":\"Civilité\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2"
24
     "component":"EmFieldGroup", "name":"civilité", "string":"{\"fre\":\"Civilité\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2"
25
   },
25
   },
26
   "9" : {
26
   "9" : {
27
-    "component":"EmField", "name":"nom", "string":"{\"fre\":\"Nom\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"8", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
27
+    "component":"EmField", "name":"nom", "string":"{\"fre\":\"Nom\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "fieldtype":"char", "fieldgroup_id":"8", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
28
   },
28
   },
29
   "10" : {
29
   "10" : {
30
-    "component":"EmField", "name":"prenom", "string":"{\"fre\":\"Preom\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"8", "rel_field_id":"", "optional":1, "internal":"", "icon":"0"
30
+    "component":"EmField", "name":"prenom", "string":"{\"fre\":\"Preom\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "fieldtype":"char", "fieldgroup_id":"8", "rel_field_id":"", "optional":1, "internal":"", "icon":"0"
31
   },
31
   },
32
   "11" : {
32
   "11" : {
33
-    "component":"EmField", "name":"auteur", "string":"{\"fre\":\"Auteur\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "type":"rel2type", "fieldgroup_id":"17", "rel_to_type_id":"6", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
33
+    "component":"EmField", "name":"auteur", "string":"{\"fre\":\"Auteur\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "fieldtype":"rel2type", "fieldgroup_id":"17", "rel_to_type_id":"6", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
34
   },
34
   },
35
   "12" : {
35
   "12" : {
36
-    "component":"EmField", "name":"adresse", "string":"{\"fre\":\"Adresse\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"17", "rel_field_id":"11", "optional":0, "internal":"", "icon":"0"
36
+    "component":"EmField", "name":"adresse", "string":"{\"fre\":\"Adresse\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "fieldtype":"char", "fieldgroup_id":"17", "rel_field_id":"11", "optional":0, "internal":"", "icon":"0"
37
   },
37
   },
38
   "13" : {
38
   "13" : {
39
     "component":"EmClass", "name":"publication", "string":"{\"fre\":\"Publication\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "classtype":"entity", "icon":"0", "sortcolumn":"rank"
39
     "component":"EmClass", "name":"publication", "string":"{\"fre\":\"Publication\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "classtype":"entity", "icon":"0", "sortcolumn":"rank"
45
     "component":"EmFieldGroup", "name":"info", "string":"{\"fre\":\"Info\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"13"
45
     "component":"EmFieldGroup", "name":"info", "string":"{\"fre\":\"Info\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"13"
46
   },
46
   },
47
   "16" : {
47
   "16" : {
48
-    "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "type":"char", "fieldgroup_id":"15", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
48
+    "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "fieldtype":"char", "fieldgroup_id":"15", "rel_field_id":"", "optional":0, "internal":"", "icon":"0"
49
   },
49
   },
50
   "17" : {
50
   "17" : {
51
     "component":"EmFieldGroup", "name":"gens", "string":"{\"fre\":\"Gens\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "class_id":"1"
51
     "component":"EmFieldGroup", "name":"gens", "string":"{\"fre\":\"Gens\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "class_id":"1"

Loading…
Cancel
Save