Sin descripción
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

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