Bez popisu
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

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