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

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