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.

__init__.py 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #
  2. # This file is part of Lodel 2 (https://github.com/OpenEdition)
  3. #
  4. # Copyright (C) 2015-2017 Cléo UMS-3287
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published
  8. # by the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. ## @defgroup lodel2_leapi LeAPI
  20. # @brief Lodel2 Editorial API
  21. #
  22. # Provides access to any kind of data in Lodel2, using classes
  23. # defined by the Editorial Model
  24. ## @package lodel.leapi
  25. # @brief Lodel2 Editorial API
  26. #
  27. # Defines an API to access to objects as described by
  28. # @ref lodel.editorial_model "Editorial Model"
  29. ## @page lodel2_leapi_page LeAPI
  30. # @ingroup lodel2_leapi
  31. #
  32. # @section lodel2_leapi_base LeAPI (Lodel Editorial API)
  33. #
  34. # LeAPI is an API that provides access to data as defined in an
  35. # @ref lodel2_em "Editorial Model".
  36. #
  37. # @subsection lodel2_leapi_gen LeAPI dynamic code & LeFactory
  38. #
  39. # LeAPI's python code is programmaticaly generated by
  40. # @ref lodel.leapi.lefactory "LeFactory", who generates
  41. # @ref lodel.leapi.leobject.LeObject "LeObject" child classes.
  42. #
  43. # @par Example
  44. #
  45. #<pre>
  46. #from lodel.leapi.leobject import LeObject
  47. #from lodel.leapi.datahandlers.base_classes import DataField
  48. #from lodel.plugin.hooks import LodelHook
  49. #
  50. #class Abstract_Object(LeObject):
  51. # _abstract = True
  52. # _fields = None
  53. # _uid = []
  54. # _ro_datasource = None
  55. # _rw_datasource = None
  56. # _datasource_name = 'default'
  57. # _child_classes = None
  58. #
  59. #
  60. #class User(LeObject):
  61. # _abstract = False
  62. # _fields = None
  63. # _uid = ['id']
  64. # _ro_datasource = None
  65. # _rw_datasource = None
  66. # _datasource_name = 'default'
  67. # _child_classes = None
  68. #
  69. #
  70. #class Object(Abstract_Object):
  71. # _abstract = True
  72. # _fields = None
  73. # _uid = ['lodel_id']
  74. # _ro_datasource = None
  75. # _rw_datasource = None
  76. # _datasource_name = 'default'
  77. # _child_classes = None
  78. #
  79. #
  80. #class Entry(Object):
  81. # _abstract = True
  82. # _fields = None
  83. # _uid = ['lodel_id']
  84. # _ro_datasource = None
  85. # _rw_datasource = None
  86. # _datasource_name = 'default'
  87. # _child_classes = None
  88. #
  89. #
  90. #class Entitie(Object):
  91. # _abstract = True
  92. # _fields = None
  93. # _uid = ['lodel_id']
  94. # _ro_datasource = None
  95. # _rw_datasource = None
  96. # _datasource_name = 'default'
  97. # _child_classes = None
  98. #
  99. #
  100. #class Person(Object):
  101. # _abstract = False
  102. # _fields = None
  103. # _uid = ['lodel_id']
  104. # _ro_datasource = None
  105. # _rw_datasource = None
  106. # _datasource_name = 'default'
  107. # _child_classes = None
  108. #
  109. #class Text(Entitie):
  110. # _abstract = True
  111. # _fields = None
  112. # _uid = ['lodel_id']
  113. # _ro_datasource = None
  114. # _rw_datasource = None
  115. # _datasource_name = 'default'
  116. # _child_classes = None
  117. #
  118. #
  119. #class Publication(Entitie):
  120. # _abstract = False
  121. # _fields = None
  122. # _uid = ['lodel_id']
  123. # _ro_datasource = None
  124. # _rw_datasource = None
  125. # _datasource_name = 'default'
  126. # _child_classes = None
  127. #
  128. #Abstract_Object._set__fields({})
  129. #Abstract_Object._child_classes = (Section, Text, Object, Entry, Collection, Text_Person, Entitie, Indextheme, Person, Indexabs, Publication, Subsection,)
  130. #User._set__fields({
  131. # 'firstname': DataField.from_name('varchar')(**{ 'internal': False }),
  132. # 'lastname': DataField.from_name('varchar')(**{ 'internal': False }),
  133. # 'classname': DataField.from_name('LeobjectSubclassIdentifier')(**{ 'internal': True }),
  134. # 'login': DataField.from_name('varchar')(**{ 'internal': True, 'uniq': True }),
  135. # 'id': DataField.from_name('uniqid')(**{ 'internal': True }),
  136. # 'password': DataField.from_name('password')(**{ 'internal': False })})
  137. #User._child_classes = tuple()
  138. #Object._set__fields({
  139. # 'date_update': DataField.from_name('datetime')(**{ 'now_on_update': True, 'internal': True }),
  140. # 'lodel_id': DataField.from_name('uniqid')(**{ 'internal': True }),
  141. # 'help_text': DataField.from_name('text')(**{ 'internal': True }),
  142. # 'date_create': DataField.from_name('datetime')(**{ 'internal': True, 'now_on_create': True })})
  143. #Object._child_classes = (Section, Text, Entry, Collection, Text_Person, Entitie, Indextheme, Person, Indexabs, Publication, Subsection,)
  144. #Entry._set__fields({
  145. # 'date_update': DataField.from_name('datetime')(**{ 'now_on_update': True, 'internal': True }),
  146. # 'lodel_id': DataField.from_name('uniqid')(**{ 'internal': True }),
  147. # 'help_text': DataField.from_name('text')(**{ 'internal': True }),
  148. # 'date_create': DataField.from_name('datetime')(**{ 'internal': True, 'now_on_create': True })})
  149. #Entry._child_classes = tuple()
  150. #Entitie._set__fields({
  151. # 'date_update': DataField.from_name('datetime')(**{ 'now_on_update': True, 'internal': True }),
  152. # 'lodel_id': DataField.from_name('uniqid')(**{ 'internal': True }),
  153. # 'help_text': DataField.from_name('text')(**{ 'internal': True }),
  154. # 'date_create': DataField.from_name('datetime')(**{ 'internal': True, 'now_on_create': True })})
  155. #Entitie._child_classes = (Section, Text, Text_Person, Collection, Publication, Subsection,)
  156. #Person._set__fields({
  157. # 'date_update': DataField.from_name('datetime')(**{ 'now_on_update': True, 'internal': True }),
  158. # 'firstname': DataField.from_name('varchar')(**{ }),
  159. # 'lodel_id': DataField.from_name('uniqid')(**{ 'internal': True }),
  160. # 'linked_texts': DataField.from_name('list')(**{ 'nullable': True, 'default': None, 'allowed_classes': [Text], 'back_reference': (Text, 'linked_persons') }),
  161. # 'help_text': DataField.from_name('text')(**{ 'internal': True }),
  162. # 'lastname': DataField.from_name('varchar')(**{ }),
  163. # 'fullname': DataField.from_name('Concat')(**{ 'field_list': ['firstname', 'lastname'], 'immutable': True }),
  164. # 'classname': DataField.from_name('LeobjectSubclassIdentifier')(**{ 'internal': True }),
  165. # 'alias': DataField.from_name('set')(**{ 'nullable': True, 'default': None, 'allowed_classes': [Person] }),
  166. # 'date_create': DataField.from_name('datetime')(**{ 'internal': True, 'now_on_create': True })})
  167. #Person._child_classes = tuple()
  168. #Text._set__fields({
  169. # 'date_update': DataField.from_name('datetime')(**{ 'now_on_update': True, 'internal': True }),
  170. # 'subtitle': DataField.from_name('varchar')(**{ 'nullable': True, 'default': None }),
  171. # 'lodel_id': DataField.from_name('uniqid')(**{ 'internal': True }),
  172. # 'help_text': DataField.from_name('text')(**{ 'internal': True }),
  173. # 'linked_persons': DataField.from_name('list')(**{ 'nullable': True, 'default': None, 'allowed_classes': [Person], 'back_reference': (Person, 'linked_texts') }),
  174. # 'indexes': DataField.from_name('list')(**{ 'nullable': True, 'default': None, 'allowed_classes': [Indexabs], 'back_reference': (Indexabs, 'texts') }),
  175. # 'title': DataField.from_name('varchar')(**{ 'nullable': True }),
  176. # 'date_create': DataField.from_name('datetime')(**{ 'internal': True, 'now_on_create': True })})
  177. #Text._child_classes = (Section, Subsection,)
  178. #Publication._set__fields({
  179. # 'date_update': DataField.from_name('datetime')(**{ 'now_on_update': True, 'internal': True }),
  180. # 'classname': DataField.from_name('LeobjectSubclassIdentifier')(**{ 'internal': True }),
  181. # 'lodel_id': DataField.from_name('uniqid')(**{ 'internal': True }),
  182. # 'collection': DataField.from_name('link')(**{ 'back_reference': (Collection, 'publications') }),
  183. # 'help_text': DataField.from_name('text')(**{ 'internal': True }),
  184. # 'date_create': DataField.from_name('datetime')(**{ 'internal': True, 'now_on_create': True })})
  185. #Publication._child_classes = tuple()
  186. #
  187. #\# List of dynamically generated classes
  188. #dynclasses = [Abstract_Object, User, Object, Entry, Entitie, Person, Indexabs, Text, Publication, Collection, Indextheme, Text_Person, Section, Subsection]
  189. #\# Dict of dynamically generated classes indexed by name
  190. #dynclasses_dict = {'Abstract_Object': Abstract_Object, 'User': User, 'Object': Object, 'Entry': Entry, 'Entitie': Entitie, 'Person': Person, 'Indexabs': Indexabs, 'Text': Text, 'Publication': Publication, 'Collection': Collection, 'Indextheme': Indextheme, 'Text_Person': Text_Person, 'Section': Section, 'Subsection': Subsection}
  191. #
  192. #
  193. #\#\# \@brief Return a dynamically generated class given it's name
  194. #\# \@param name str : The dynamic class name
  195. #\# \@return False or a child class of LeObject
  196. #def name2class(name):
  197. # if name not in dynclasses_dict:
  198. # return False
  199. # return dynclasses_dict[name]
  200. #
  201. #
  202. #\#\# \@brief Return a dynamically generated class given it's name
  203. #\# \@note Case insensitive version of name2class
  204. #\# \@param name str
  205. #\# \@retrun False or a child class of LeObject
  206. #def lowername2class(name):
  207. # name = name.lower()
  208. # new_dict = {k.lower():v for k,v in dynclasses_dict.items()}
  209. # if name not in new_dict:
  210. # return False
  211. # return new_dict[name]
  212. #
  213. #
  214. #\#\# \@brief Trigger dynclasses datasources initialisation
  215. #@LodelHook("lodel2_plugins_loaded")
  216. #def lodel2_dyncode_datasources_init(self, caller, payload):
  217. # for cls in dynclasses:
  218. # cls._init_datasources()
  219. # from lodel.plugin.hooks import LodelHook
  220. # LodelHook.call_hook("lodel2_dyncode_loaded", __name__, dynclasses)
  221. #</pre>
  222. #