Browse Source

LeObject: first shot at _prepare_filters()

ArnAud 9 years ago
parent
commit
28c068712a
1 changed files with 28 additions and 2 deletions
  1. 28
    2
      leobject/leobject.py

+ 28
- 2
leobject/leobject.py View File

@@ -3,6 +3,7 @@
3 3
 ## Main class to handle objects defined by the types of an Editorial Model
4 4
 # an instance of these objects is pedantically called LeObject !
5 5
 
6
+from EditorialModel.types import EmType
6 7
 
7 8
 class LeObject(object):
8 9
 
@@ -83,9 +84,34 @@ class LeObject(object):
83 84
     # @todo implent !
84 85
     def _prepare_filters(self, query_filters):
85 86
         if query_filters is None:
86
-            query_filters = ()
87
-        elif isinstance(query_filters, str):
87
+            return ()
88
+        elif isinstance(query_filters[0], str):
88 89
             query_filters = (query_filters)
90
+        
91
+        fields, operators, queries = zip(*query_filters)
92
+        
93
+        # find name of the type in filters
94
+        try:
95
+            type_index = fields.index('type')
96
+            if operators[type_index] != '=':
97
+                raise ValueError
98
+            type_name = queries[type_index]
99
+            del query_filters[type_index]
100
+        except ValueError:
101
+            print ("Le champ type est obligatoire dans une requête")
102
+            raise
103
+
104
+        
105
+        comps = self.model.components(EmType)
106
+        for comp in comps:
107
+            if comp.name == type_name:
108
+                em_type = comp
109
+                break
110
+        
111
+        class_name = em_type.em_class.name
112
+        fields = em_type.fields()
113
+        field_list = [f.name for f in fields]
114
+        print (em_type, class_name, type_name, fields, field_list)
89 115
 
90 116
         prepared_filters = query_filters
91 117
         return prepared_filters

Loading…
Cancel
Save