Browse Source

Updated the DummyDatasource + documenting query filters

Yann Weber 9 years ago
parent
commit
46c98dc046
2 changed files with 75 additions and 23 deletions
  1. 22
    20
      leobject/datasources/dummy.py
  2. 53
    3
      leobject/leobject.py

+ 22
- 20
leobject/datasources/dummy.py View File

@@ -1,10 +1,9 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3
-
4
-## dummy datasource for LeObject
3
+## @brief Dummy datasource for LeObject
4
+#
5 5
 # This class has to be extended to apply to a real datasource
6 6
 # But it can be used as an empty and debug datasource
7
-
8 7
 class DummyDatasource(object):
9 8
 
10 9
     def __init__(self, module=None, *conn_args, **conn_kargs):
@@ -13,39 +12,42 @@ class DummyDatasource(object):
13 12
         self.conn_kargs = conn_kargs
14 13
 
15 14
     ## @brief update an existing LeObject
16
-    # @param lodel_id (int) : list of lodel_id
17
-    # @param checked_data dict
18
-    # @param filters
19
-    # @param relational_filters
20
-    def update(self, lodel_id, checked_data, filters, relational_filters):
15
+    # @param letype LeType : LeType child class
16
+    # @param leclass LeClass : LeClass child class
17
+    # @param filters list : List of filters (see @ref leobject_filters )
18
+    # @param rel_filters list : List of relationnal filters (see @ref leobject_filters )
19
+    # @param data dict : Dict representing fields and there values
20
+    # @return True if success
21
+    def update(self, letype, leclass, filters, rel_filters, data):
21 22
         print ("DummyDatasource.update: ", lodel_id, checked_data, filters, relational_filters)
22 23
         return True
23 24
 
24 25
     ## @brief create a new LeObject
25
-    # @param letype LeType
26
-    # @param leclass LeClass
27
-    # @param data dict: a dictionnary of field:value to save
26
+    # @param letype LeType : LeType child class
27
+    # @param leclass LeClass : LeClass child class
28
+    # @param data list: a lis of dictionnary of field:value to save
28 29
     # @return lodel_id int: new lodel_id of the newly created LeObject
29 30
     def insert(self, letype, leclass, **datas):
30 31
         print("DummyDatasource.insert: ", letype, leclass, datas)
31 32
         return 42
32 33
 
33 34
     ## @brief delete an existing LeObject
34
-    # @param lodel_id int | (int): lodel_id of the object(s) to delete
35
-    # @param filters list : list of tuples formatted as (FIELD, OPERATOR, VALUE)
36
-    # @param relational_filters list
35
+    # @param letype LeType : LeType child class
36
+    # @param leclass LeClass : LeClass child class
37
+    # @param filters list : list of tuples formatted as (FIELD, OPERATOR, VALUE) (see @ref leobject_filters )
38
+    # @param relational_filters list : relationnal filters list (see @ref leobject_filters )
37 39
     # @return okay bool: True on success, it will raise on failure
38
-    def delete(self, lodel_id, filters, relational_filters):
40
+    def delete(self, letype, leclass, filters, relational_filters):
39 41
         print("DummyDatasource.delete: ", lodel_id)
40 42
         return True
41 43
 
42 44
     ## @brief search for a collection of objects
43
-    # @param emclass LeClass : LeClass instance
44
-    # @param emtype LeType : LeType instance
45
+    # @param leclass LeClass : LeClass instance
46
+    # @param letype LeType : LeType instance
45 47
     # @param field_list list : list of fields to get from the datasource
46
-    # @param filters list : list of tuples formatted as (FIELD, OPERATOR, VALUE)
47
-    # @param relational_filters list
48
+    # @param filters list : list of tuples formatted as (FIELD, OPERATOR, VALUE) (see @ref leobject_filters )
49
+    # @param relational_filters list : relationnal filters list (see @ref leobject_filters )
48 50
     # @return responses ({string:*}): a list of dict with field:value
49
-    def get(self, emclass, emtype, field_list, filters, relational_filters):
51
+    def get(self, leclass, letype, field_list, filters, relational_filters):
50 52
         print("DummyDatasource.get: ", emclass, emtype, field_list, filters, relational_filters)
51 53
         return []

+ 53
- 3
leobject/leobject.py View File

@@ -16,6 +16,9 @@ import leobject
16 16
 import EditorialModel
17 17
 from EditorialModel.types import EmType
18 18
 
19
+REL_SUP = 0
20
+REL_SUB = 1
21
+
19 22
 ## @brief Main class to handle objects defined by the types of an Editorial Model
20 23
 class _LeObject(object):
21 24
     
@@ -95,8 +98,8 @@ class _LeObject(object):
95 98
         return okay
96 99
 
97 100
     ## @brief make a search to retrieve a collection of LeObject
98
-    # @param query_filters list : list of string of query filters (or tuple (FIELD, OPERATOR, VALUE) )
99
-    # @param field_list list|None : list of string representing fields
101
+    # @param query_filters list : list of string of query filters (or tuple (FIELD, OPERATOR, VALUE) ) see @ref leobject_filters
102
+    # @param field_list list|None : list of string representing fields see @ref leobject_filters
100 103
     # @param typename str : The name of the LeType we want
101 104
     # @param classname str : The name of the LeClass we want
102 105
     # @return responses ({string:*}): a list of dict with field:value
@@ -176,6 +179,8 @@ class _LeObject(object):
176 179
     # @throw LeObjectQueryError if their is some problems
177 180
     # @throw AttributeError if letype is not from the leclass class
178 181
     # @todo Delete the checks of letype and leclass and ensure that this method is called with letype and leclass arguments from _prepare_targets()
182
+    #
183
+    # @see @ref leobject_filters
179 184
     @staticmethod
180 185
     def _check_fields(letype, leclass, fields):
181 186
         #Checking that fields in the query_filters are correct
@@ -210,7 +215,9 @@ class _LeObject(object):
210 215
     # @param filters_l list : This list can contain str "FIELDNAME OP VALUE" and tuples (FIELDNAME, OP, VALUE)
211 216
     # @param letype LeType|None : needed to check filters
212 217
     # @param leclass LeClass|None : needed to check filters
213
-    # @return a tuple(FILTERS, RELATIONNAL_FILTERS°
218
+    # @return a tuple(FILTERS, RELATIONNAL_FILTERS
219
+    #
220
+    # @see @ref datasource_side
214 221
     @staticmethod
215 222
     def _prepare_filters(filters_l, letype = None, leclass = None):
216 223
         filters = list()
@@ -285,3 +292,46 @@ class LeObjectError(Exception):
285 292
 
286 293
 class LeObjectQueryError(LeObjectError):
287 294
     pass
295
+
296
+## @page leobject_filters LeObject query filters
297
+# The LeObject API provide methods that accept filters allowing the user
298
+# to query the database and fetch LodelEditorialObjects.
299
+#
300
+# The LeObject API translate those filters for the datasource. 
301
+# 
302
+# @section api_user_side API user side filters
303
+# Filters are string expressing a condition. The string composition
304
+# is as follow : "<FIELD> <OPERATOR> <VALUE>"
305
+# @subsection fpart FIELD
306
+# @subsubsection standart fields
307
+# Standart fields, represents a value of the LeObject for example "title", "lodel_id" etc.
308
+# @subsubsection rfields relationnal fields
309
+# relationnal fields, represents a relation with the object hierarchy. Those fields are composed as follow :
310
+# "<RELATION>.<NATURE>".
311
+#
312
+# - Relation can takes two values : superiors or subordinates
313
+# - Nature is a relation nature ( see EditorialModel.classtypes )
314
+# Examples : "superiors.parent", "subordinates.translation" etc.
315
+# @note The field_list arguement of leobject.leobject._LeObject.get() use the same syntax than the FIELD filter part 
316
+# @subsection oppart OPERATOR
317
+# The OPERATOR part of a filter is a comparison operator. There is
318
+# - standart comparison operators : = , <, > , <=, >=, !=
319
+# - list operators : 'in' and 'not in'
320
+# The list of allowed operators is sotred at leobject.leobject._LeObject._query_operators . 
321
+# @subsection valpart VALUE
322
+# The VALUE part of a filter is... just a value...
323
+#
324
+# @section datasource_side Datasource side filters
325
+# As said above the API "translate" filters before forwarding them to the datasource. 
326
+#
327
+# The translation process transform filters in tuple composed of 3 elements
328
+# ( @ref fpart , @ref oppart , @ref valpart ). Each element is a string.
329
+#
330
+# There is a special case for @ref rfields : the field element is a tuple composed with two elements
331
+# ( RELATION, NATURE ) where NATURE is a string ( see EditorialModel.classtypes ) and RELATION is one of
332
+# the defined constant : 
333
+#
334
+# - leobject.leobject.REL_SUB for "subordinates"
335
+# - leobject.leobject.REL_SUP for "superiors"
336
+#
337
+# @note The filters translation process also check if given field are valids compared to the concerned letype and/or the leclass

Loading…
Cancel
Save