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.

em_test.py 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. #!/usr/bin/python3
  2. #
  3. # This file is part of Lodel 2 (https://github.com/OpenEdition)
  4. #
  5. # Copyright (C) 2015-2017 Cléo UMS-3287
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published
  9. # by the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. from lodel.context import LodelContext
  21. LodelContext.init()
  22. from lodel.settings.settings import Settings as settings
  23. settings('globconf.d')
  24. from lodel.settings import Settings
  25. from lodel.editorial_model.components import *
  26. from lodel.editorial_model.exceptions import *
  27. from lodel.editorial_model.model import EditorialModel
  28. em = EditorialModel('testem', 'Test editorial model')
  29. base_group = em.new_group( 'base_group',
  30. display_name = 'Base group',
  31. help_text = 'Base group that implements base EM features (like classtype)'
  32. )
  33. ####################
  34. # Lodel Object #
  35. ####################
  36. em_abstract = em.new_class( 'abstract_object',
  37. display_name = 'Abstract lodel object',
  38. help_text = 'For testing purpose',
  39. group = base_group,
  40. abstract = True)
  41. em_object = em.new_class( 'object',
  42. display_name = 'Object',
  43. help_text = 'Main class for all Em objects',
  44. group = base_group,
  45. abstract = True,
  46. parents = em_abstract,
  47. )
  48. em_object.new_field( 'lodel_id',
  49. display_name = 'Lodel identifier',
  50. help_text = 'Uniq ID that identify every lodel object',
  51. group = base_group,
  52. data_handler = 'uniqid',
  53. internal = True,
  54. )
  55. em_object.new_field( 'help_text',
  56. display_name = 'Help',
  57. help_text = 'A short text that describe the object',
  58. group = base_group,
  59. internal = True,
  60. data_handler = 'text',
  61. )
  62. em_object.new_field( 'date_create',
  63. display_name = 'Creation date',
  64. group = base_group,
  65. data_handler = 'datetime',
  66. now_on_create = True,
  67. internal = True,
  68. )
  69. em_object.new_field( 'date_update',
  70. display_name = 'Last update',
  71. group = base_group,
  72. data_handler = 'datetime',
  73. now_on_update = True,
  74. internal = True,
  75. )
  76. ########################
  77. # Lodel old classtypes #
  78. ########################
  79. entitie = em.new_class( 'entitie',
  80. display_name = 'entitie',
  81. help_text = 'Replace old entity classtype',
  82. abstract = True,
  83. group = base_group,
  84. parents = em_object,
  85. )
  86. person = em.new_class( 'person',
  87. display_name = 'Person',
  88. help_text = 'Replace old person classtype',
  89. abstract = False,
  90. group = base_group,
  91. parents = em_object,
  92. )
  93. person.new_field( 'firstname',
  94. display_name = {
  95. 'eng': 'Firstname',
  96. 'fre': 'Prénom',
  97. },
  98. data_handler = 'varchar',
  99. group = base_group,
  100. )
  101. person.new_field( 'lastname',
  102. display_name = {
  103. 'eng': 'Lastname',
  104. 'fre': 'Nom de famille',
  105. },
  106. data_handler = 'varchar',
  107. group = base_group,
  108. )
  109. person.new_field( 'fullname',
  110. display_name = {
  111. 'eng': 'Fullname',
  112. 'fre': 'Nom complet',
  113. },
  114. group = base_group,
  115. data_handler = 'Concat',
  116. field_list = ['firstname', 'lastname'],
  117. immutable = True,
  118. )
  119. person.new_field( 'alias',
  120. display_name = 'alias',
  121. help_text = {
  122. 'eng': 'Link to other person class instance that represent the same person',
  123. 'fre': 'Lien vers un ensemble d\'instances de la classe personne représentant le même individu',
  124. },
  125. data_handler = 'set',
  126. allowed_classes = [person],
  127. default = None,
  128. nullable = True,
  129. group = base_group,
  130. )
  131. entry = em.new_class( 'entry',
  132. display_name = 'Entry',
  133. help_text = 'Replace olf entry classtype',
  134. abstract = True,
  135. group = base_group,
  136. parents = em_object,
  137. )
  138. #####################
  139. # Editorial classes #
  140. #####################
  141. editorial_group = em.new_group( 'editorial_abstract',
  142. display_name = 'Editorial base',
  143. help_text = {
  144. 'eng': 'Contains abstract class to handler editorial contents',
  145. 'fre': 'Contient les classes abstraites permetant la gestion de contenu éditorial'
  146. },
  147. depends = (base_group,)
  148. )
  149. # Classe texte
  150. text = em.new_class( 'text',
  151. display_name = 'Text',
  152. help_text = 'Abstract class that represent texts',
  153. group = editorial_group,
  154. abstract = True,
  155. parents = entitie,
  156. )
  157. text.new_field( 'title',
  158. display_name = {'eng': 'Title', 'fre': 'Titre'},
  159. group = editorial_group,
  160. data_handler = 'varchar',
  161. nullable = True,)
  162. text.new_field( 'subtitle',
  163. display_name = {
  164. 'eng': 'Subtitle',
  165. 'fre': 'Sous-titre',
  166. },
  167. group = editorial_group,
  168. data_handler = 'varchar',
  169. nullable = True,
  170. default = None)
  171. # Classe collection
  172. collection = em.new_class( 'collection',
  173. display_name = 'Collection',
  174. group = editorial_group,
  175. abstract = False,
  176. parents = entitie)
  177. collection.new_field( 'title',
  178. display_name = 'Title',
  179. group = editorial_group,
  180. data_handler = 'varchar'
  181. )
  182. # Classe publication
  183. publication = em.new_class( 'publication',
  184. display_name = 'Publication',
  185. group = editorial_group,
  186. abstract = False,
  187. parents = entitie,)
  188. publication.new_field( 'collection',
  189. display_name = 'Collection',
  190. group = editorial_group,
  191. data_handler = 'link',
  192. default = None,
  193. nullable = True,
  194. allowed_classes = [collection],
  195. back_reference = ('collection', 'publications'))
  196. collection.new_field( 'publications',
  197. display_name = 'Publications',
  198. group = editorial_group,
  199. data_handler = 'list',
  200. allowed_classes = [publication],
  201. back_reference = ('publication', 'collection'))
  202. #########################
  203. # Texte definition #
  204. #########################
  205. section = em.new_class( 'section',
  206. display_name = 'Section',
  207. group = editorial_group,
  208. abstract = False,
  209. parents = text)
  210. subsection = em.new_class( 'subsection',
  211. display_name = 'Subsection',
  212. group = editorial_group,
  213. abstract = False,
  214. parents = section)
  215. section.new_field( 'childs',
  216. display_name = 'Next section',
  217. group = editorial_group,
  218. data_handler = 'hierarch',
  219. allowed_classes = [subsection],
  220. back_reference = ('subsection', 'parent'),
  221. default = None,
  222. nullable = True)
  223. subsection.new_field( 'parent',
  224. display_name = 'Parent',
  225. group = editorial_group,
  226. data_handler = 'link',
  227. default = None,
  228. nullable = True,
  229. allowed_classes = [section],
  230. back_reference = ('section', 'childs'))
  231. #####################
  232. # Persons & authors #
  233. #####################
  234. editorial_person_group = em.new_group( 'editorial_person',
  235. display_name = 'Editorial person',
  236. help_text = {
  237. 'eng': 'Introduce the concept of editorial person (authors, translator etc)',
  238. 'fre': 'Contient les classes servant à la gestion des personnes editorials (auteurs, traducteur...)',
  239. },
  240. depends = (editorial_group,)
  241. )
  242. text_person = em.new_class( 'text_person',
  243. display_name = {
  244. 'eng': 'TextPerson',
  245. 'fre': 'TextePersonne',
  246. },
  247. help_text = {
  248. 'eng': 'Represent a link between someone and a text',
  249. 'fre': 'Représente un lien entre une personne et un texte',
  250. },
  251. group = editorial_person_group,
  252. abstract = True,
  253. parents = entitie,
  254. )
  255. bref_textperson_text = text_person.new_field( 'text',
  256. display_name = {
  257. 'eng': 'Linked text',
  258. 'fre': 'Texte lié',
  259. },
  260. data_handler = 'link',
  261. allowed_classes = [text],
  262. group = editorial_person_group
  263. )
  264. bref_textperson_person = text_person.new_field( 'person',
  265. display_name = {
  266. 'eng': 'Linked person',
  267. 'fre': 'Personne liée',
  268. },
  269. data_handler = 'link',
  270. allowed_classes = [person],
  271. group = editorial_person_group,
  272. )
  273. text_person.new_field( 'role',
  274. display_name = {
  275. 'eng': 'Person role',
  276. 'fre': 'Role de la personne',
  277. },
  278. data_handler = 'varchar',
  279. group = editorial_person_group
  280. )
  281. # simple example of linked text / person
  282. person.new_field( 'linked_texts',
  283. display_name = {
  284. 'eng': 'Linked texts',
  285. 'fre': 'Textes liés',
  286. },
  287. data_handler = 'list',
  288. back_reference = ('Text', 'linked_persons'),
  289. group = editorial_person_group,
  290. allowed_classes = [text],
  291. default = None,
  292. nullable = True)
  293. text.new_field( 'linked_persons',
  294. display_name = {
  295. 'eng': 'Linked persons',
  296. 'fre': 'Personnes liées',
  297. },
  298. data_handler = 'list',
  299. back_reference = ('Person', 'linked_texts'),
  300. group = editorial_person_group,
  301. allowed_classes = [person],
  302. default = None,
  303. nullable = True)
  304. #####################
  305. # Index classes # <--- Note : using a different datasource for testing
  306. ##################### purpose
  307. index_group = em.new_group( 'index_group',
  308. display_name = 'Indexes',
  309. help_text = {
  310. 'eng': 'EM class that represents indexes'},
  311. depends = (editorial_group,))
  312. index_abstract = em.new_class(
  313. 'indexAbs',
  314. display_name = {'eng': 'Abstract Index'},
  315. help_text = {'eng': 'Abstract class common to each Index classes'},
  316. abstract = True,
  317. group = index_group,
  318. datasources = 'dummy2',
  319. parents = em_object)
  320. index_name = index_abstract.new_field(
  321. 'name',
  322. display_name = {
  323. 'eng': 'name',
  324. 'fre': 'nom'},
  325. data_handler = 'varchar',
  326. group = index_group)
  327. index_value = index_abstract.new_field(
  328. 'value',
  329. display_name = {
  330. 'eng': 'value',
  331. 'fre': 'valeur'},
  332. data_handler = 'varchar',
  333. group = index_group)
  334. text.new_field( 'indexes',
  335. display_name = {
  336. 'eng': 'Indexes',
  337. 'fre': 'Indexes'},
  338. data_handler = 'list',
  339. back_reference = ('Indexabs', 'texts'),
  340. allowed_classes = [index_abstract],
  341. default = None,
  342. nullable = True,
  343. group = index_group)
  344. index_abstract.new_field( 'texts',
  345. display_name = {
  346. 'eng': 'Text referenced by this index',
  347. 'fre': 'Texte contenant cette index'},
  348. data_handler = 'list',
  349. back_reference = ('Text', 'indexes'),
  350. allowed_classes = [text],
  351. group = index_group)
  352. index_theme = em.new_class(
  353. 'indexTheme',
  354. display_name = {
  355. 'eng': 'Thematic index',
  356. 'fre': 'Index thématique'},
  357. group = index_group,
  358. datasources = 'dummy2',
  359. parents = index_abstract)
  360. index_theme_theme = index_abstract.new_field(
  361. 'theme',
  362. display_name = {
  363. 'eng': 'theme'},
  364. data_handler = 'varchar',
  365. group = index_group)
  366. #############
  367. # USERS #
  368. #############
  369. user_group = em.new_group(
  370. 'users', display_name = 'Lodel users',
  371. help_text = 'Group that handle users en perm')
  372. user = em.new_class(
  373. 'user', display_name = 'Lodel user', help_text = 'Represent a lodel user',
  374. group = user_group, abstract = False)
  375. user.new_field(
  376. 'id', display_name = 'user identifier', help_text = 'Uniq ID',
  377. group = user_group, data_handler = 'uniqid', internal = True)
  378. user.new_field(
  379. 'firstname', display_name = 'Firstname',
  380. group = user_group, data_handler = 'varchar', internal = False)
  381. user.new_field(
  382. 'lastname', display_name = 'Lastname',
  383. group = user_group, data_handler = 'varchar', internal = False)
  384. user.new_field(
  385. 'login', display_name = 'user login', help_text = 'login',
  386. group = user_group, data_handler = 'varchar', uniq = True, internal = False)
  387. user.new_field(
  388. 'password', display_name = 'Password',
  389. group = user_group, data_handler = 'password', internal = False)
  390. #em.save('xmlfile', filename = 'examples/em_test.xml')
  391. pickle_file = 'examples/em_test.pickle'
  392. em.save('picklefile', filename = pickle_file)
  393. print("Output written in %s" % pickle_file)