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_simple.py 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. #!/usr/bin/python3
  2. import sys
  3. # A voir si utile dans un lodel installé
  4. sys.path.insert(0,'lodel/editorial_model')
  5. from model import EditorialModel
  6. xml_file = '../examples/em_simple.xml'
  7. pickle_file = '../examples/em_simple.pickle'
  8. em = EditorialModel('simpleem', 'Simple editorial model')
  9. base_group = em.new_group( 'base_group',
  10. display_name = 'Base group',
  11. help_text = 'Base group that implements base EM features (like classtype)'
  12. )
  13. ####################
  14. # Lodel Object #
  15. ####################
  16. em_abstract = em.new_class( 'abstract_object',
  17. display_name = 'Abstract lodel object',
  18. help_text = 'For testing purpose',
  19. group = base_group,
  20. abstract = True)
  21. em_object = em.new_class( 'object',
  22. display_name = 'Object',
  23. help_text = 'Main class for all Em objects',
  24. group = base_group,
  25. abstract = True,
  26. parents = em_abstract,
  27. )
  28. em_object.new_field( 'lodel_id',
  29. display_name = 'Lodel identifier',
  30. help_text = 'Uniq ID that identify every lodel object',
  31. group = base_group,
  32. data_handler = 'uniqid',
  33. internal = True,
  34. )
  35. em_object.new_field( 'date_create',
  36. display_name = 'Creation date',
  37. group = base_group,
  38. data_handler = 'datetime',
  39. now_on_create = True,
  40. internal = True,
  41. )
  42. em_object.new_field( 'date_update',
  43. display_name = 'Last update',
  44. group = base_group,
  45. data_handler = 'datetime',
  46. now_on_update = True,
  47. internal = True,
  48. )
  49. entitie = em.new_class( 'entitie',
  50. display_name = 'entitie',
  51. help_text = 'Replace old entity classtype',
  52. abstract = True,
  53. group = base_group,
  54. parents = em_object,
  55. )
  56. ########################
  57. # Base group
  58. ########################
  59. person = em.new_class( 'person',
  60. display_name = 'Person',
  61. help_text = 'Person type',
  62. abstract = False,
  63. group = base_group,
  64. parents = em_object,
  65. )
  66. person.new_field( 'firstname',
  67. display_name = {
  68. 'eng': 'Firstname',
  69. 'fre': 'Prénom',
  70. },
  71. data_handler = 'varchar',
  72. group = base_group,
  73. )
  74. person.new_field( 'lastname',
  75. display_name = {
  76. 'eng': 'Lastname',
  77. 'fre': 'Nom de famille',
  78. },
  79. data_handler = 'varchar',
  80. group = base_group,
  81. )
  82. # person.new_field( 'role',
  83. # display_name = {
  84. # 'eng': 'Role',
  85. # 'fre': 'Rôle',
  86. # },
  87. # data_handler = 'varchar',
  88. # group = base_group,
  89. # )
  90. entry = em.new_class( 'entry',
  91. display_name = 'Entry',
  92. help_text = 'Entry type',
  93. abstract = False,
  94. group = base_group,
  95. parents = em_object,
  96. )
  97. entry.new_field( 'name',
  98. display_name = {
  99. 'eng': 'Name',
  100. 'fre': 'Nom',
  101. },
  102. data_handler = 'varchar',
  103. group = base_group,
  104. )
  105. entry.new_field( 'description',
  106. display_name = {
  107. 'eng': 'Description',
  108. 'fre': 'Description',
  109. },
  110. data_handler = 'text',
  111. group = base_group,
  112. )
  113. entry.new_field( 'role',
  114. display_name = {
  115. 'eng': 'Role',
  116. 'fre': 'Rôle',
  117. },
  118. data_handler = 'varchar',
  119. group = base_group,
  120. )
  121. #####################
  122. # Editorial classes #
  123. #####################
  124. editorial_group = em.new_group( 'editorial_abstract',
  125. display_name = 'Editorial base',
  126. help_text = {
  127. 'eng': 'Contains abstract class to handler editorial contents',
  128. 'fre': 'Contient les classes abstraites permetant la gestion de contenu éditorial'
  129. },
  130. depends = (base_group,)
  131. )
  132. ################################ Texts #############################
  133. # Classe texte
  134. text = em.new_class( 'text',
  135. display_name = 'Text',
  136. help_text = 'Abstract class that represent texts',
  137. group = editorial_group,
  138. abstract = True,
  139. parents = entitie,
  140. )
  141. text.new_field( 'title',
  142. display_name = {'eng': 'Title', 'fre': 'Titre'},
  143. group = editorial_group,
  144. data_handler = 'text',
  145. nullable = True,)
  146. text.new_field( 'subtitle',
  147. display_name = {
  148. 'eng': 'Subtitle',
  149. 'fre': 'Sous-titre',
  150. },
  151. group = editorial_group,
  152. data_handler = 'text',
  153. nullable = True,
  154. default = None)
  155. text.new_field( 'language',
  156. display_name = {
  157. 'eng': 'Language',
  158. 'fre': 'Langue',
  159. },
  160. group = editorial_group,
  161. data_handler = 'varchar',
  162. nullable = True,
  163. default = None)
  164. text.new_field( 'text',
  165. display_name = {
  166. 'eng': 'Text',
  167. 'fre': 'Texte',
  168. },
  169. group = editorial_group,
  170. data_handler = 'text',
  171. nullable = True,
  172. default = None)
  173. text.new_field( 'pub_date',
  174. display_name = {
  175. 'eng': 'Publication date',
  176. 'fre': 'Date de publication',
  177. },
  178. group = editorial_group,
  179. data_handler = 'datetime',
  180. nullable = True,
  181. default = None)
  182. text.new_field( 'footnotes',
  183. display_name = {
  184. 'eng': 'Footnotes',
  185. 'fre': 'Notes de bas de page',
  186. },
  187. group = editorial_group,
  188. data_handler = 'text',
  189. nullable = True,
  190. default = None)
  191. text.new_field( 'linked_entries',
  192. display_name = {
  193. 'eng': 'Related entries',
  194. 'fre': 'Indices liés',
  195. },
  196. group = editorial_group,
  197. data_handler = 'list',
  198. nullable = True,
  199. allowed_classes = [entry],
  200. back_reference = ('entry', 'linked_texts'),
  201. default = None
  202. )
  203. entry.new_field( 'linked_texts',
  204. display_name = {
  205. 'eng': 'Related text',
  206. 'fre': 'Texte lié ',
  207. },
  208. data_handler = 'list',
  209. nullable = True,
  210. allowed_classes = [text],
  211. group = editorial_group,
  212. back_reference = ('text', 'linked_entries'),
  213. default = None
  214. )
  215. # Classe article
  216. article = em.new_class( 'article',
  217. display_name = 'Article',
  218. group = editorial_group,
  219. abstract = False,
  220. parents = text)
  221. article.new_field( 'abstract',
  222. display_name = {
  223. 'eng': 'Abstract',
  224. 'fre': 'Résumé',
  225. },
  226. group = editorial_group,
  227. data_handler = 'text'
  228. )
  229. article.new_field( 'appendix',
  230. display_name = {
  231. 'eng': 'Appendix',
  232. 'fre': 'Appendice',
  233. },
  234. group = editorial_group,
  235. data_handler = 'text'
  236. )
  237. article.new_field( 'bibliography',
  238. display_name = {
  239. 'eng': 'Bibliography',
  240. 'fre': 'Bibliographie',
  241. },
  242. group = editorial_group,
  243. data_handler = 'text'
  244. )
  245. article.new_field( 'author_note',
  246. display_name = {
  247. 'eng': 'Author note',
  248. 'fre': "Note de l'auteur",
  249. },
  250. group = editorial_group,
  251. data_handler = 'text'
  252. )
  253. # Classe Review
  254. review = em.new_class( 'review',
  255. display_name = 'Review',
  256. group = editorial_group,
  257. abstract = False,
  258. parents = text)
  259. review.new_field( 'reference',
  260. display_name = {
  261. 'eng': 'Reference',
  262. 'fre': "Référence",
  263. },
  264. group = editorial_group,
  265. data_handler = 'text'
  266. )
  267. ###################################### Containers ##################
  268. # Classe container
  269. container = em.new_class( 'container',
  270. display_name = 'Container',
  271. group = editorial_group,
  272. abstract = True,
  273. parents = entitie)
  274. container.new_field( 'title',
  275. display_name = 'Title',
  276. group = editorial_group,
  277. data_handler = 'text'
  278. )
  279. container.new_field( 'subtitle',
  280. display_name = 'Subtitle',
  281. group = editorial_group,
  282. data_handler = 'text'
  283. )
  284. container.new_field( 'language',
  285. display_name = {
  286. 'eng' : 'Language',
  287. 'fre' : 'Langue',
  288. },
  289. group = editorial_group,
  290. data_handler = 'varchar'
  291. )
  292. container.new_field( 'linked_directors',
  293. display_name = {
  294. 'eng': 'Directors',
  295. 'fre': 'Directeurs',
  296. },
  297. group = editorial_group,
  298. data_handler = 'list',
  299. nullable = True,
  300. allowed_classes = [person],
  301. back_reference = ('person', 'linked_containers'),
  302. default = None
  303. )
  304. person.new_field( 'linked_containers',
  305. display_name = {
  306. 'eng': 'Director of ',
  307. 'fre': 'Directeur de ',
  308. },
  309. group = editorial_group,
  310. data_handler = 'list',
  311. nullable = True,
  312. allowed_classes = [container],
  313. back_reference = ('container', 'linked_directors'),
  314. default = None
  315. )
  316. container.new_field( 'description',
  317. display_name = {
  318. 'eng': 'Description',
  319. 'fre': 'Description',
  320. },
  321. data_handler = 'text',
  322. group = editorial_group,
  323. )
  324. container.new_field( 'publisher_note',
  325. display_name = {
  326. 'eng': 'Publisher note',
  327. 'fre': "Note de l'éditeur",
  328. },
  329. data_handler = 'text',
  330. group = editorial_group,
  331. )
  332. # Classe collection
  333. collection = em.new_class( 'collection',
  334. display_name = 'Collection',
  335. group = editorial_group,
  336. abstract = False,
  337. parents = container)
  338. collection.new_field( 'issn',
  339. display_name = {
  340. 'eng': 'ISSN',
  341. 'fre': "ISSN",
  342. },
  343. data_handler = 'varchar',
  344. group = editorial_group,
  345. )
  346. # Classe Publication : Pour gérer les back_references vers issue ou part
  347. publication = em.new_class( 'publication',
  348. display_name = 'Publication',
  349. group = editorial_group,
  350. abstract = True,
  351. parents = container)
  352. publication.new_field( 'linked_texts',
  353. display_name = {
  354. 'eng': 'Text',
  355. 'fre': 'Texte',
  356. },
  357. data_handler = 'list',
  358. nullable = True,
  359. allowed_classes = [text],
  360. group = editorial_group,
  361. back_reference = ('text', 'linked_container'),
  362. default = None
  363. )
  364. text.new_field( 'linked_container',
  365. display_name = {
  366. 'eng': 'Container',
  367. 'fre': 'Conteneur',
  368. },
  369. data_handler = 'link',
  370. nullable = True,
  371. allowed_classes = [publication],
  372. group = editorial_group,
  373. back_reference = ('publication', 'linked_texts'),
  374. default = None
  375. )
  376. # Classe Issue
  377. issue = em.new_class( 'issue',
  378. display_name = 'Issue',
  379. group = editorial_group,
  380. abstract = False,
  381. parents = publication)
  382. issue.new_field( 'isbn',
  383. display_name = 'ISBN',
  384. data_handler = 'varchar',
  385. group = editorial_group,
  386. )
  387. issue.new_field( 'print_isbn',
  388. display_name = {
  389. 'eng': 'Printed ISBN',
  390. 'fre': "ISBN imprimé",
  391. },
  392. data_handler = 'varchar',
  393. group = editorial_group,
  394. )
  395. issue.new_field( 'number',
  396. display_name = {
  397. 'eng': 'Number',
  398. 'fre': 'Numéro',
  399. },
  400. data_handler = 'varchar',
  401. group = editorial_group,
  402. )
  403. issue.new_field( 'cover',
  404. display_name = {
  405. 'eng': 'Cover',
  406. 'fre': 'Couverture',
  407. },
  408. data_handler = 'varchar',
  409. group = editorial_group,
  410. )
  411. issue.new_field( 'print_pub_date',
  412. display_name = {
  413. 'eng': 'Print date',
  414. 'fre': "Date d'impression",
  415. },
  416. data_handler = 'datetime',
  417. group = editorial_group,
  418. )
  419. issue.new_field( 'e_pub_date',
  420. display_name = {
  421. 'eng': 'Electronic publication date',
  422. 'fre': 'Date de publication électronique',
  423. },
  424. data_handler = 'datetime',
  425. group = editorial_group,
  426. )
  427. issue.new_field( 'abstract',
  428. display_name = {
  429. 'eng': 'Abstract',
  430. 'fre': 'Résumé',
  431. },
  432. data_handler = 'text',
  433. group = editorial_group,
  434. )
  435. issue.new_field( 'collection',
  436. display_name = {
  437. 'eng': 'Collection',
  438. 'fre': 'Collection',
  439. },
  440. data_handler = 'link',
  441. nullable = True,
  442. allowed_classes = [collection],
  443. group = editorial_group,
  444. back_reference = ('collection', 'linked_issues'),
  445. default = None
  446. )
  447. collection.new_field( 'linked_issues',
  448. display_name = {
  449. 'eng': 'Linked issues',
  450. 'fre': 'Numéros',
  451. },
  452. data_handler = 'hierarch',
  453. back_reference = ('Issue', 'collection'),
  454. group = editorial_group,
  455. allowed_classes = [issue],
  456. default = None,
  457. nullable = True)
  458. # Classe Part
  459. part = em.new_class( 'part',
  460. display_name = 'Part',
  461. group = editorial_group,
  462. abstract = False,
  463. parents = publication,)
  464. part.new_field( 'publication',
  465. display_name = {
  466. 'eng': 'Publication',
  467. 'fre': 'Publication',
  468. },
  469. data_handler = 'link',
  470. nullable = True,
  471. allowed_classes = [publication],
  472. group = editorial_group,
  473. back_reference = ('publication', 'linked_parts'),
  474. default = None
  475. )
  476. publication.new_field( 'linked_parts',
  477. display_name = {
  478. 'eng': 'Parts',
  479. 'fre': 'Parties',
  480. },
  481. data_handler = 'hierarch',
  482. nullable = True,
  483. allowed_classes = [part],
  484. group = editorial_group,
  485. back_reference = ('part', 'publication'),
  486. default = None
  487. )
  488. #####################
  489. # Persons & authors #
  490. #####################
  491. editorial_person_group = em.new_group( 'editorial_person',
  492. display_name = 'Editorial person',
  493. help_text = {
  494. 'eng': 'Introduce the concept of editorial person (author, translator, director)',
  495. 'fre': 'Contient les classes servant à la gestion des personnes éditoriales (auteur, traducteur, directeur...)',
  496. },
  497. depends = (editorial_group,)
  498. )
  499. text_person = em.new_class( 'text_person',
  500. display_name = {
  501. 'eng': 'TextPerson',
  502. 'fre': 'TextePersonne',
  503. },
  504. help_text = {
  505. 'eng': 'Represent a link between someone and a text',
  506. 'fre': 'Représente un lien entre une personne et un texte',
  507. },
  508. group = editorial_person_group,
  509. abstract = True,
  510. parents = entitie,
  511. )
  512. bref_textperson_text = text_person.new_field( 'text',
  513. display_name = {
  514. 'eng': 'Linked text',
  515. 'fre': 'Texte lié',
  516. },
  517. data_handler = 'link',
  518. allowed_classes = [text],
  519. group = editorial_person_group
  520. )
  521. bref_textperson_person = text_person.new_field( 'person',
  522. display_name = {
  523. 'eng': 'Linked person',
  524. 'fre': 'Personne liée',
  525. },
  526. data_handler = 'link',
  527. allowed_classes = [person],
  528. group = editorial_person_group,
  529. )
  530. text_person.new_field( 'role',
  531. display_name = {
  532. 'eng': 'Person role',
  533. 'fre': 'Role de la personne',
  534. },
  535. data_handler = 'varchar',
  536. group = editorial_person_group
  537. )
  538. # simple example of linked text / person
  539. person.new_field( 'linked_texts',
  540. display_name = {
  541. 'eng': 'Linked texts',
  542. 'fre': 'Textes liés',
  543. },
  544. data_handler = 'list',
  545. back_reference = ('Text', 'linked_persons'),
  546. group = editorial_person_group,
  547. allowed_classes = [text],
  548. default = None,
  549. nullable = True)
  550. text.new_field( 'linked_persons',
  551. display_name = {
  552. 'eng': 'Linked persons',
  553. 'fre': 'Personnes liées',
  554. },
  555. data_handler = 'list',
  556. back_reference = ('Person', 'linked_texts'),
  557. group = editorial_person_group,
  558. allowed_classes = [person],
  559. default = None,
  560. nullable = True)
  561. #####################
  562. # Index classes # <--- Note : using a different datasource for testing
  563. ##################### purpose
  564. index_group = em.new_group( 'index_group',
  565. display_name = 'Indexes',
  566. help_text = {
  567. 'eng': 'EM class that represents indexes'},
  568. depends = (editorial_group,))
  569. index_abstract = em.new_class(
  570. 'indexAbs',
  571. display_name = {'eng': 'Abstract Index'},
  572. help_text = {'eng': 'Abstract class common to each Index classes'},
  573. abstract = True,
  574. group = index_group,
  575. datasources = 'dummy2',
  576. parents = em_object)
  577. index_name = index_abstract.new_field(
  578. 'name',
  579. display_name = {
  580. 'eng': 'name',
  581. 'fre': 'nom'},
  582. data_handler = 'text',
  583. group = index_group)
  584. index_value = index_abstract.new_field(
  585. 'value',
  586. display_name = {
  587. 'eng': 'value',
  588. 'fre': 'valeur'},
  589. data_handler = 'varchar',
  590. group = index_group)
  591. text.new_field( 'indexes',
  592. display_name = {
  593. 'eng': 'Indexes',
  594. 'fre': 'Indexes'},
  595. data_handler = 'list',
  596. back_reference = ('Indexabs', 'texts'),
  597. allowed_classes = [index_abstract],
  598. default = None,
  599. nullable = True,
  600. group = index_group)
  601. index_abstract.new_field( 'texts',
  602. display_name = {
  603. 'eng': 'Text referenced by this index',
  604. 'fre': 'Texte contenant cette index'},
  605. data_handler = 'list',
  606. back_reference = ('Text', 'indexes'),
  607. allowed_classes = [text],
  608. group = index_group)
  609. index_theme = em.new_class(
  610. 'indexTheme',
  611. display_name = {
  612. 'eng': 'Thematic index',
  613. 'fre': 'Index thématique'},
  614. group = index_group,
  615. datasources = 'dummy2',
  616. parents = index_abstract)
  617. index_theme_theme = index_abstract.new_field(
  618. 'theme',
  619. display_name = {
  620. 'eng': 'theme'},
  621. data_handler = 'varchar',
  622. group = index_group)
  623. #############
  624. # USERS #
  625. #############
  626. user_group = em.new_group(
  627. 'users', display_name = 'Lodel users',
  628. help_text = 'Group that handle users en perm')
  629. user = em.new_class(
  630. 'user', display_name = 'Lodel user', help_text = 'Represent a lodel user',
  631. group = user_group, abstract = False)
  632. user.new_field(
  633. 'id', display_name = 'user identifier', help_text = 'Uniq ID',
  634. group = user_group, data_handler = 'uniqid', internal = True)
  635. user.new_field(
  636. 'firstname', display_name = 'Firstname',
  637. group = user_group, data_handler = 'varchar', internal = False)
  638. user.new_field(
  639. 'lastname', display_name = 'Lastname',
  640. group = user_group, data_handler = 'varchar', internal = False)
  641. user.new_field(
  642. 'login', display_name = 'user login', help_text = 'login',
  643. group = user_group, data_handler = 'varchar', uniq = True, internal = False)
  644. user.new_field(
  645. 'password', display_name = 'Password',
  646. group = user_group, data_handler = 'password', internal = False)
  647. em.save('xmlfile', filename = xml_file)
  648. em.save('picklefile', filename = pickle_file)
  649. print("Output written in %s and %s" % (pickle_file, xml_file))