설명 없음
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 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 | LeRoot : superior LeType child class instance or @ref
  51. # @param lesub LeType : subordinate LeType child class instance
  52. # @param nature str : A relation nature @ref EditorialModel.classtypesa
  53. # @param rank int : The rank of this relation
  54. # @param depth None|int : The depth of the relation (used to make reccursive calls in order to link with all superiors)
  55. # @return The relation ID or False if fails
  56. def add_superior(self, lesup, lesub, nature, rank, depth = None):
  57. pass
  58. ## @brief Delete a superior to a LeObject
  59. # @param lesup LeType : superior LeType child class instance
  60. # @param lesub Letype : subordinate LeType child class instance
  61. # @param nature str : A relation nature @ref EditorialModel.classtypes
  62. # @return True if deleted
  63. def del_superior(self, lesup, lesub, nature):
  64. pass
  65. ## @brief Fetch a superiors list ordered by depth for a LeType
  66. # @param lesub LeType : subordinate LeType child class instance
  67. # @param nature str : A relation nature @ref EditorialModel.classtypes
  68. # @return A list of LeType ordered by depth (the first is the direct superior)
  69. def get_superiors(self, lesub, nature):
  70. pass
  71. ## @brief Fetch the list of the subordinates given a nature
  72. # @param lesup LeType : superior LeType child class instance
  73. # @param nature str : A relation nature @ref EditorialModel.classtypes
  74. # @return A list of LeType ordered by rank that are subordinates of lesup in a "nature" relation
  75. def get_subordinates(self, lesup, nature):
  76. pass
  77. ## @brief Make a relation between 2 LeType
  78. # @note rel2type relations. Superior is the LeType from the EmClass and subordinate the LeType for the EmType
  79. # @param lesup LeType : LeType child class instance that is from the EmClass containing the rel2type field
  80. # @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 )
  81. # @param rank int : Begin at 0 ?
  82. # @return The relation_id if success else return False
  83. def add_related(self, lesup, lesub, rank = 'last', **rel_attr):
  84. pass
  85. ## @brief Returns related LeType
  86. # @param leo LeType : The from LeType child class instance
  87. # @param letype LeType : The wanted LeType child class (not instance !)
  88. # @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
  89. # @return a list of dict { 'id_relation':.., 'rank':.., 'lesup':.., 'lesub'.., 'rel_attrs': dict() }
  90. def get_related(self, leo, letype, get_sub=True):
  91. pass
  92. ## @brief Delete a relation between 2 LeType
  93. # @param lesup LeType
  94. # @param lesub LeType
  95. # @param fields dict
  96. # @return True if success else return False
  97. def del_related(self, lesup, lesub, fields=None):
  98. pass
  99. ## @brief Fetch a relation
  100. # @param id_relation int : The relation identifier
  101. # @return a dict{'id_relation':.., 'lesup':.., 'lesub':.., < if exists 'dict_attr':..>}
  102. def get_relation(self, id_relation, no_attr = False):
  103. pass
  104. ## @brief Fetch all relations concerning an object (rel2type relations)
  105. # @param leo LeType : LeType child instance
  106. # @return a list of tuple (lesup, lesub, dict_attr)
  107. def get_relations(self, leo):
  108. pass
  109. ## @brief Set the rank of a relation identified by its ID
  110. # @param id_relation int : relation ID
  111. # @param rank int|str : 'first', 'last', or an integer value
  112. def set_relation_rank(self, id_relation, rank):
  113. pass
  114. ## @brief Delete a relation between two LeType
  115. # @note It will deleted a relation in a rel2type between lesup.Class and lesub.Type
  116. # @param id_relation int : The relation identifier
  117. # @return True if deleted
  118. def del_relation(self, id_relation):
  119. pass