Browse Source

Ecriture de la méthode LinkedTypes dans EmType

Roland Haroutiounian 9 years ago
parent
commit
3f250baea8
1 changed files with 19 additions and 1 deletions
  1. 19
    1
      EditorialModel/types.py

+ 19
- 1
EditorialModel/types.py View File

@@ -222,5 +222,23 @@ class EmType(EmComponent):
222 222
     # @return a list of EmType
223 223
     # @see EmFields
224 224
     def linked_types(self):
225
-        pass
225
+        return self._linked_types_Db()
226
+
227
+    ## @brief Return the list of all the types linked to this type, should they be superiors or subordinates
228
+    # @return A list of EmType objects
229
+    def _linked_types_Db(self):
230
+        conn = self.getDbE().connect()
231
+        htable = self.__class__._tableHierarchy()
232
+        req = htable.select(htable.c.superior_id, htable.c.subordinate_id)
233
+        req = req.where(sql.or_(htable.c.subordinate_id == self.uid, htable.c.superior_id == self.uid))
234
+
235
+        res = conn.execute(req)
236
+        rows = res.fetchall()
237
+        conn.close()
238
+
239
+        rows = dict(zip(rows.keys(), rows))
240
+        result = []
241
+        for row in rows:
242
+            result.append(EmType(row['subordinate_id'] if row['superior_id']==self.uid else row['superior_id']))
226 243
 
244
+        return result

Loading…
Cancel
Save