Browse Source

EmType: implement select and unselect _field

ArnAud 9 years ago
parent
commit
34fdd8d8b3
3 changed files with 21 additions and 27 deletions
  1. 1
    1
      EditorialModel/fieldgroups.py
  2. 7
    7
      EditorialModel/test/me.json
  3. 13
    19
      EditorialModel/types.py

+ 1
- 1
EditorialModel/fieldgroups.py View File

@@ -46,7 +46,7 @@ class EmFieldGroup(EmComponent):
46 46
         if not type_id:
47 47
             fields = [field for field in self.model.components(EmField) if field.fieldgroup_id == self.uid]
48 48
         else:
49
-            # for an EmType, fileds have to be filtered
49
+            # for an EmType, fields have to be filtered
50 50
             em_type = self.model.component(type_id)
51 51
             fields = []
52 52
             for field in self.model.components(EmField):

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

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

+ 13
- 19
EditorialModel/types.py View File

@@ -46,7 +46,6 @@ class EmType(EmComponent):
46 46
         self.icon = icon
47 47
         self.sortcolumn = sortcolumn
48 48
         super(EmType, self).__init__(model=model, uid=uid, name=name, string=string, help_text=help_text, date_update=date_update, date_create=date_create, rank=rank)
49
-        pass
50 49
 
51 50
     @classmethod
52 51
     ## Create a new EmType and instanciate it
@@ -117,7 +116,9 @@ class EmType(EmComponent):
117 116
     # @throw ValueError if field is not optional or is not associated with this type
118 117
     # @see EmType::_opt_field_act()
119 118
     def select_field(self, field):
120
-        return self._opt_field_act(field, True)
119
+        if field.uid in self.fields_list:
120
+            return True
121
+        return self._change_field_list(field, True)
121 122
 
122 123
     ## Unselect_field (Function)
123 124
     #
@@ -130,7 +131,9 @@ class EmType(EmComponent):
130 131
     # @throw ValueError if field is not optional or is not associated with this type
131 132
     # @see EmType::_opt_field_act()
132 133
     def unselect_field(self, field):
133
-        return self._opt_field_act(field, False)
134
+        if field.uid not in self.fields_list:
135
+            return True
136
+        return self._change_field_list(field, False)
134 137
 
135 138
     ## @brief Select or unselect an optional field
136 139
     # @param field EmField: The EmField to select or unselect
@@ -139,29 +142,20 @@ class EmType(EmComponent):
139 142
     #
140 143
     # @throw TypeError if field is not an EmField instance
141 144
     # @throw ValueError if field is not optional or is not associated with this type
142
-    def _opt_field_act(self, field, select=True):  # TODO voir si on conserve l'argument "select"
145
+    def _change_field_list(self, field, add=True):  # TODO voir si on conserve l'argument "select"
143 146
         if not isinstance(field, EmField):
144 147
             raise TypeError("Excepted <class EmField> as field argument. But got " + str(type(field)))
145
-        if not field in self.all_fields():
148
+        if not field in self.em_class.fields():
146 149
             raise ValueError("This field is not part of this type")
147 150
         if not field.optional:
148 151
             raise ValueError("This field is not optional")
149 152
 
150
-        # TODO Réimplémenter
153
+        if add:
154
+            self.fields_list.append(field.uid)
155
+        else:
156
+            self.fields_list.remove(field.uid)
151 157
 
152
-        # dbe = self.db_engine
153
-        # meta = sqlutils.meta(dbe)
154
-        # conn = dbe.connect()
155
-        #
156
-        # table = sql.Table('em_field_type', meta)
157
-        # if select:
158
-        #     req = table.insert({'type_id': self.uid, 'field_id': field.uid})
159
-        # else:
160
-        #     req = table.delete().where(table.c.type_id == self.uid and table.c.field_id == field.uid)
161
-        #
162
-        # res = conn.execute(req)
163
-        # conn.close()
164
-        # return bool(res)
158
+        return True
165 159
 
166 160
     ## Get the list of associated hooks
167 161
     # @note Not conceptualized yet

Loading…
Cancel
Save