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 14KB

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