Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

em_simple.py 25KB

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