Nessuna descrizione
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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. back_reference = ('section', 'childs'))
  208. #####################
  209. # Persons & authors #
  210. #####################
  211. editorial_person_group = em.new_group( 'editorial_person',
  212. display_name = 'Editorial person',
  213. help_text = {
  214. 'eng': 'Introduce the concept of editorial person (authors, translator etc)',
  215. 'fre': 'Contient les classes servant à la gestion des personnes editorials (auteurs, traducteur...)',
  216. },
  217. depends = (editorial_group,)
  218. )
  219. text_person = em.new_class( 'text_person',
  220. display_name = {
  221. 'eng': 'TextPerson',
  222. 'fre': 'TextePersonne',
  223. },
  224. help_text = {
  225. 'eng': 'Represent a link between someone and a text',
  226. 'fre': 'Représente un lien entre une personne et un texte',
  227. },
  228. group = editorial_person_group,
  229. abstract = True,
  230. parents = entitie,
  231. )
  232. bref_textperson_text = text_person.new_field( 'text',
  233. display_name = {
  234. 'eng': 'Linked text',
  235. 'fre': 'Texte lié',
  236. },
  237. data_handler = 'link',
  238. allowed_classes = [text],
  239. group = editorial_person_group
  240. )
  241. bref_textperson_person = text_person.new_field( 'person',
  242. display_name = {
  243. 'eng': 'Linked person',
  244. 'fre': 'Personne liée',
  245. },
  246. data_handler = 'link',
  247. allowed_classes = [person],
  248. group = editorial_person_group,
  249. )
  250. text_person.new_field( 'role',
  251. display_name = {
  252. 'eng': 'Person role',
  253. 'fre': 'Role de la personne',
  254. },
  255. data_handler = 'varchar',
  256. group = editorial_person_group
  257. )
  258. # simple example of linked text / person
  259. person.new_field( 'linked_texts',
  260. display_name = {
  261. 'eng': 'Linked texts',
  262. 'fre': 'Textes liés',
  263. },
  264. data_handler = 'list',
  265. back_reference = ('Text', 'linked_persons'),
  266. group = editorial_person_group,
  267. allowed_classes = [text],
  268. default = None,
  269. nullable = True)
  270. text.new_field( 'linked_persons',
  271. display_name = {
  272. 'eng': 'Linked persons',
  273. 'fre': 'Personnes liées',
  274. },
  275. data_handler = 'list',
  276. back_reference = ('Person', 'linked_texts'),
  277. group = editorial_person_group,
  278. allowed_classes = [person],
  279. default = None,
  280. nullable = True)
  281. #####################
  282. # Index classes # <--- Note : using a different datasource for testing
  283. ##################### purpose
  284. index_group = em.new_group( 'index_group',
  285. display_name = 'Indexes',
  286. help_text = {
  287. 'eng': 'EM class that represents indexes'},
  288. depends = (editorial_group,))
  289. index_abstract = em.new_class(
  290. 'indexAbs',
  291. display_name = {'eng': 'Abstract Index'},
  292. help_text = {'eng': 'Abstract class common to each Index classes'},
  293. abstract = True,
  294. group = index_group,
  295. datasources = 'dummy2',
  296. parents = em_object)
  297. index_name = index_abstract.new_field(
  298. 'name',
  299. display_name = {
  300. 'eng': 'name',
  301. 'fre': 'nom'},
  302. data_handler = 'varchar',
  303. group = index_group)
  304. index_value = index_abstract.new_field(
  305. 'value',
  306. display_name = {
  307. 'eng': 'value',
  308. 'fre': 'valeur'},
  309. data_handler = 'varchar',
  310. group = index_group)
  311. text.new_field( 'indexes',
  312. display_name = {
  313. 'eng': 'Indexes',
  314. 'fre': 'Indexes'},
  315. data_handler = 'list',
  316. back_reference = ('Indexabs', 'texts'),
  317. allowed_classes = [index_abstract],
  318. default = None,
  319. nullable = True,
  320. group = index_group)
  321. index_abstract.new_field( 'texts',
  322. display_name = {
  323. 'eng': 'Text referenced by this index',
  324. 'fre': 'Texte contenant cette index'},
  325. data_handler = 'list',
  326. back_reference = ('Text', 'indexes'),
  327. allowed_classes = [text],
  328. group = index_group)
  329. index_theme = em.new_class(
  330. 'indexTheme',
  331. display_name = {
  332. 'eng': 'Thematic index',
  333. 'fre': 'Index thématique'},
  334. group = index_group,
  335. datasources = 'dummy2',
  336. parents = index_abstract)
  337. index_theme_theme = index_abstract.new_field(
  338. 'theme',
  339. display_name = {
  340. 'eng': 'theme'},
  341. data_handler = 'varchar',
  342. group = index_group)
  343. #############
  344. # USERS #
  345. #############
  346. user_group = em.new_group(
  347. 'users', display_name = 'Lodel users',
  348. help_text = 'Group that handle users en perm')
  349. user = em.new_class(
  350. 'user', display_name = 'Lodel user', help_text = 'Represent a lodel user',
  351. group = user_group, abstract = False)
  352. user.new_field(
  353. 'id', display_name = 'user identifier', help_text = 'Uniq ID',
  354. group = user_group, data_handler = 'uniqid', internal = True)
  355. user.new_field(
  356. 'firstname', display_name = 'Firstname',
  357. group = user_group, data_handler = 'varchar', internal = False)
  358. user.new_field(
  359. 'lastname', display_name = 'Lastname',
  360. group = user_group, data_handler = 'varchar', internal = False)
  361. user.new_field(
  362. 'login', display_name = 'user login', help_text = 'login',
  363. group = user_group, data_handler = 'varchar', uniq = True, internal = False)
  364. user.new_field(
  365. 'password', display_name = 'Password',
  366. group = user_group, data_handler = 'password', internal = False)
  367. #em.save('xmlfile', filename = 'examples/em_test.xml')
  368. pickle_file = 'examples/em_test.pickle'
  369. em.save('picklefile', filename = pickle_file)
  370. print("Output written in %s" % pickle_file)