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

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