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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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. group = base_group,
  81. )
  82. person.new_field( 'lastname',
  83. display_name = {
  84. 'eng': 'Lastname',
  85. 'fre': 'Nom de famille',
  86. },
  87. data_handler = 'varchar',
  88. group = base_group,
  89. )
  90. person.new_field( 'fullname',
  91. display_name = {
  92. 'eng': 'Fullname',
  93. 'fre': 'Nom complet',
  94. },
  95. group = base_group,
  96. data_handler = 'Concat',
  97. field_list = ['firstname', 'lastname'],
  98. immutable = True,
  99. )
  100. person.new_field( 'alias',
  101. display_name = 'alias',
  102. help_text = {
  103. 'eng': 'Link to other person class instance that represent the same person',
  104. 'fre': 'Lien vers un ensemble d\'instances de la classe personne représentant le même individu',
  105. },
  106. data_handler = 'set',
  107. allowed_classes = [person],
  108. default = None,
  109. nullable = True,
  110. group = base_group,
  111. )
  112. entry = em.new_class( 'entry',
  113. display_name = 'Entry',
  114. help_text = 'Replace olf entry classtype',
  115. abstract = True,
  116. group = base_group,
  117. parents = em_object,
  118. )
  119. #####################
  120. # Editorial classes #
  121. #####################
  122. editorial_group = em.new_group( 'editorial_abstract',
  123. display_name = 'Editorial base',
  124. help_text = {
  125. 'eng': 'Contains abstract class to handler editorial contents',
  126. 'fre': 'Contient les classes abstraites permetant la gestion de contenu éditorial'
  127. },
  128. depends = (base_group,)
  129. )
  130. # Classe texte
  131. text = em.new_class( 'text',
  132. display_name = 'Text',
  133. help_text = 'Abstract class that represent texts',
  134. group = editorial_group,
  135. abstract = True,
  136. parents = entitie,
  137. )
  138. text.new_field( 'title',
  139. display_name = {'eng': 'Title', 'fre': 'Titre'},
  140. group = editorial_group,
  141. data_handler = 'varchar',
  142. nullable = True,)
  143. text.new_field( 'subtitle',
  144. display_name = {
  145. 'eng': 'Subtitle',
  146. 'fre': 'Sous-titre',
  147. },
  148. group = editorial_group,
  149. data_handler = 'varchar',
  150. nullable = True,
  151. default = None)
  152. # Classe collection
  153. collection = em.new_class( 'collection',
  154. display_name = 'Collection',
  155. group = editorial_group,
  156. abstract = False,
  157. parents = entitie)
  158. collection.new_field( 'title',
  159. display_name = 'Title',
  160. group = editorial_group,
  161. data_handler = 'varchar'
  162. )
  163. # Classe publication
  164. publication = em.new_class( 'publication',
  165. display_name = 'Publication',
  166. group = editorial_group,
  167. abstract = False,
  168. parents = entitie,)
  169. publication.new_field( 'collection',
  170. display_name = 'Collection',
  171. group = editorial_group,
  172. data_handler = 'link',
  173. allowed_classes = [collection],
  174. back_reference = ('collection', 'publications'))
  175. collection.new_field( 'publications',
  176. display_name = 'Publications',
  177. group = editorial_group,
  178. data_handler = 'list',
  179. allowed_classes = [publication],
  180. back_reference = ('publication', 'collection'))
  181. #########################
  182. # Texte definition #
  183. #########################
  184. section = em.new_class( 'section',
  185. display_name = 'Section',
  186. group = editorial_group,
  187. abstract = False,
  188. parents = text)
  189. subsection = em.new_class( 'subsection',
  190. display_name = 'Subsection',
  191. group = editorial_group,
  192. abstract = False,
  193. parents = section)
  194. section.new_field( 'childs',
  195. display_name = 'Next section',
  196. group = editorial_group,
  197. data_handler = 'hierarch',
  198. allowed_classes = [subsection],
  199. back_reference = ('subsection', 'parent'),
  200. default = None,
  201. nullable = True)
  202. subsection.new_field( 'parent',
  203. display_name = 'Parent',
  204. group = editorial_group,
  205. data_handler = 'link',
  206. allowed_classes = [section])
  207. #####################
  208. # Persons & authors #
  209. #####################
  210. editorial_person_group = em.new_group( 'editorial_person',
  211. display_name = 'Editorial person',
  212. help_text = {
  213. 'eng': 'Introduce the concept of editorial person (authors, translator etc)',
  214. 'fre': 'Contient les classes servant à la gestion des personnes editorials (auteurs, traducteur...)',
  215. },
  216. depends = (editorial_group,)
  217. )
  218. text_person = em.new_class( 'text_person',
  219. display_name = {
  220. 'eng': 'TextPerson',
  221. 'fre': 'TextePersonne',
  222. },
  223. help_text = {
  224. 'eng': 'Represent a link between someone and a text',
  225. 'fre': 'Représente un lien entre une personne et un texte',
  226. },
  227. group = editorial_person_group,
  228. abstract = True,
  229. parents = entitie,
  230. )
  231. bref_textperson_text = text_person.new_field( 'text',
  232. display_name = {
  233. 'eng': 'Linked text',
  234. 'fre': 'Texte lié',
  235. },
  236. data_handler = 'link',
  237. allowed_classes = [text],
  238. group = editorial_person_group
  239. )
  240. bref_textperson_person = text_person.new_field( 'person',
  241. display_name = {
  242. 'eng': 'Linked person',
  243. 'fre': 'Personne liée',
  244. },
  245. data_handler = 'link',
  246. allowed_classes = [person],
  247. group = editorial_person_group,
  248. )
  249. text_person.new_field( 'role',
  250. display_name = {
  251. 'eng': 'Person role',
  252. 'fre': 'Role de la personne',
  253. },
  254. data_handler = 'varchar',
  255. group = editorial_person_group
  256. )
  257. # simple example of linked text / person
  258. person.new_field( 'linked_texts',
  259. display_name = {
  260. 'eng': 'Linked texts',
  261. 'fre': 'Textes liés',
  262. },
  263. data_handler = 'list',
  264. back_reference = ('Text', 'linked_persons'),
  265. group = editorial_person_group,
  266. allowed_classes = [text],
  267. default = None,
  268. nullable = True)
  269. text.new_field( 'linked_persons',
  270. display_name = {
  271. 'eng': 'Linked persons',
  272. 'fre': 'Personnes liées',
  273. },
  274. data_handler = 'list',
  275. back_reference = ('Person', 'linked_texts'),
  276. group = editorial_person_group,
  277. allowed_classes = [person],
  278. default = None,
  279. nullable = True)
  280. #####################
  281. # Index classes # <--- Note : using a different datasource for testing
  282. ##################### purpose
  283. index_group = em.new_group( 'index_group',
  284. display_name = 'Indexes',
  285. help_text = {
  286. 'eng': 'EM class that represents indexes'},
  287. depends = (editorial_group,))
  288. index_abstract = em.new_class(
  289. 'indexAbs',
  290. display_name = {'eng': 'Abstract Index'},
  291. help_text = {'eng': 'Abstract class common to each Index classes'},
  292. abstract = True,
  293. group = index_group,
  294. datasources = 'dummy2',
  295. parents = em_object)
  296. index_name = index_abstract.new_field(
  297. 'name',
  298. display_name = {
  299. 'eng': 'name',
  300. 'fre': 'nom'},
  301. data_handler = 'varchar',
  302. group = index_group)
  303. index_value = index_abstract.new_field(
  304. 'value',
  305. display_name = {
  306. 'eng': 'value',
  307. 'fre': 'valeur'},
  308. data_handler = 'varchar',
  309. group = index_group)
  310. text.new_field( 'indexes',
  311. display_name = {
  312. 'eng': 'Indexes',
  313. 'fre': 'Indexes'},
  314. data_handler = 'list',
  315. back_reference = ('Indexabs', 'texts'),
  316. allowed_classes = [index_abstract],
  317. default = None,
  318. nullable = True,
  319. group = index_group)
  320. index_abstract.new_field( 'texts',
  321. display_name = {
  322. 'eng': 'Text referenced by this index',
  323. 'fre': 'Texte contenant cette index'},
  324. data_handler = 'list',
  325. back_reference = ('Text', 'indexes'),
  326. allowed_classes = [text],
  327. group = index_group)
  328. index_theme = em.new_class(
  329. 'indexTheme',
  330. display_name = {
  331. 'eng': 'Thematic index',
  332. 'fre': 'Index thématique'},
  333. group = index_group,
  334. datasources = 'dummy2',
  335. parents = index_abstract)
  336. index_theme_theme = index_abstract.new_field(
  337. 'theme',
  338. display_name = {
  339. 'eng': 'theme'},
  340. data_handler = 'varchar',
  341. group = index_group)
  342. #############
  343. # USERS #
  344. #############
  345. user_group = em.new_group(
  346. 'users', display_name = 'Lodel users',
  347. help_text = 'Group that handle users en perm')
  348. user = em.new_class(
  349. 'user', display_name = 'Lodel user', help_text = 'Represent a lodel user',
  350. group = user_group, abstract = False)
  351. user.new_field(
  352. 'id', display_name = 'user identifier', help_text = 'Uniq ID',
  353. group = user_group, data_handler = 'uniqid', internal = True)
  354. user.new_field(
  355. 'firstname', display_name = 'Firstname',
  356. group = user_group, data_handler = 'varchar', internal = False)
  357. user.new_field(
  358. 'lastname', display_name = 'Lastname',
  359. group = user_group, data_handler = 'varchar', internal = False)
  360. user.new_field(
  361. 'login', display_name = 'user login', help_text = 'login',
  362. group = user_group, data_handler = 'varchar', uniq = True, internal = False)
  363. user.new_field(
  364. 'password', display_name = 'Password',
  365. group = user_group, data_handler = 'password', internal = False)
  366. #em.save('xmlfile', filename = 'examples/em_test.xml')
  367. pickle_file = 'examples/em_test.pickle'
  368. em.save('picklefile', filename = pickle_file)
  369. print("Output written in %s" % pickle_file)