No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dummy.py 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #-*- coding: utf-8 -*-
  2. ## @brief Dummy datasource for LeObject
  3. #
  4. # This class has to be extended to apply to a real datasource
  5. # But it can be used as an empty and debug datasource
  6. class DummyDatasource(object):
  7. def __init__(self, module=None, *conn_args, **conn_kargs):
  8. self.module = module
  9. self.conn_args = conn_args
  10. self.conn_kargs = conn_kargs
  11. ## @brief update an existing LeObject
  12. # @param letype LeType : LeType child class
  13. # @param leclass LeClass : LeClass child class
  14. # @param filters list : List of filters (see @ref leobject_filters )
  15. # @param rel_filters list : List of relationnal filters (see @ref leobject_filters )
  16. # @param data dict : Dict representing fields and there values
  17. # @return True if success
  18. def update(self, letype, leclass, filters, rel_filters, data):
  19. print ("DummyDatasource.update: ", letype, leclass, filters, rel_filters, data)
  20. return True
  21. ## @brief create a new LeObject
  22. # @param letype LeType : LeType child class
  23. # @param leclass LeClass : LeClass child class
  24. # @param data list: a lis of dictionnary of field:value to save
  25. # @return lodel_id int: new lodel_id of the newly created LeObject
  26. def insert(self, letype, leclass, datas):
  27. print("DummyDatasource.insert: ", letype, leclass, datas)
  28. return 42
  29. ## @brief delete an existing LeObject
  30. # @param letype LeType : LeType child class
  31. # @param leclass LeClass : LeClass child class
  32. # @param filters list : list of tuples formatted as (FIELD, OPERATOR, VALUE) (see @ref leobject_filters )
  33. # @param relational_filters list : relationnal filters list (see @ref leobject_filters )
  34. # @return okay bool: True on success, it will raise on failure
  35. def delete(self, letype, leclass, filters, relational_filters):
  36. print("DummyDatasource.delete: ", letype, leclass, filters, relational_filters)
  37. return True
  38. ## @brief search for a collection of objects
  39. # @param leclass LeClass : LeClass instance
  40. # @param letype LeType : LeType instance
  41. # @param field_list list : list of fields to get from the datasource
  42. # @param filters list : list of tuples formatted as (FIELD, OPERATOR, VALUE) (see @ref leobject_filters )
  43. # @param relational_filters list : relationnal filters list (see @ref leobject_filters )
  44. # @return responses ({string:*}): a list of dict with field:value
  45. def get(self, leclass, letype, field_list, filters, relational_filters):
  46. print("DummyDatasource.get: ", leclass, letype, field_list, filters, relational_filters)
  47. return []
  48. ## @brief Add a superior to a LeObject
  49. # @note in the MySQL version the method will have a depth=None argument to allow reccursive calls to add all the path to the root with corresponding depth
  50. # @param lesup LeType : superior LeType child class instance
  51. # @param lesub LeType : subordinate LeType child class instance
  52. # @param nature str : A relation nature @ref EditorialModel.classtypes
  53. # @return True if added with no problems
  54. def add_superior(self, lesup, lesub, nature):
  55. pass
  56. ## @brief Delete a superior to a LeObject
  57. # @param lesup LeType : superior LeType child class instance
  58. # @param lesub Letype : subordinate LeType child class instance
  59. # @param nature str : A relation nature @ref EditorialModel.classtypes
  60. # @return True if deleted
  61. def del_superior(self, lesup, lesub, nature):
  62. pass
  63. ## @brief Fetch a superiors list ordered by depth for a LeType
  64. # @param lesub LeType : subordinate LeType child class instance
  65. # @param nature str : A relation nature @ref EditorialModel.classtypes
  66. # @return A list of LeType ordered by depth
  67. def get_superiors(self, lesub, nature):
  68. pass
  69. ## @brief Fetch the list of the subordinates given a nature
  70. # @param lesup LeType : superior LeType child class instance
  71. # @param nature str : A relation nature @ref EditorialModel.classtypes
  72. # @return A list of LeType that are subordinates of lesup in a "nature" relation
  73. def get_subordinates(self, lesup, nature):
  74. pass
  75. ## @brief Make a relation between 2 LeType
  76. # @note rel2type relations. Superior is the LeType from the EmClass and subordinate the LeType for the EmType
  77. # @param lesup LeType : LeType child class instance that is from the EmClass containing the rel2type field
  78. # @param lesub LeType : LeType child class instance that is from the EmType linked by the rel2type field ( @ref EditorialModel.fieldtypes.rel2type.EmFieldType.rel_to_type_id )
  79. # @return True if added with no problem
  80. def add_related(self, lesup, lesub, **rel_attr):
  81. pass
  82. ## @brief Returns related LeType
  83. # @param leo LeType : The from LeType child class instance
  84. # @param letype LeType : The wanted LeType child class (not instance !)
  85. # @param get_sub bool : If True, leo will be the superior and we wants all subordinates of Type letype, else its the oposite, leo is the subordinates and we want superiors with Type letype
  86. # @return A dict with LeType instance as key and dict(attr_name:attr_val, ...) as value
  87. def get_related(self, leo, letype, get_sub=True):
  88. pass
  89. ## @brief Delete a relation between two LeType
  90. # @note It will deleted a relation in a rel2type between lesup.Class and lesub.Type
  91. # @param lesub LeType : The superior
  92. # @param lesup LeType : The subordinate
  93. # @return True if deleted
  94. def del_related(self, lesup, lesub):
  95. pass