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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. import sys
  2. sys.path.insert(0,'lodel/editorial_model')
  3. from model import EditorialModel
  4. xml_file = 'examples/em_test.xml'
  5. pickle_file = 'examples/em_simple.pickle'
  6. em = EditorialModel('testem', 'Test editorial model')
  7. base_group = em.new_group(
  8. 'base_group',
  9. display_name='Base group',
  10. help_text = 'Base group that implements base EM features (like classtype)')
  11. ################
  12. # Lodel object #
  13. ################
  14. em_abstract = em.new_class(
  15. 'abstract_object',
  16. display_name='Abstract lodel object',
  17. help_text = 'For testing purpose',
  18. group=base_group,
  19. abstract=True)
  20. em_object = em.new_class(
  21. '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. em_object.new_field(
  28. '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. em_object.new_field(
  35. '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. em_object.new_field(
  42. 'date_create',
  43. display_name='Creation date',
  44. group=base_group,
  45. data_handler='datetime',
  46. now_on_create=True,
  47. internal=True,)
  48. em_object.new_field(
  49. '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. # Lodel old classtypes #
  57. ########################
  58. entitie = em.new_class(
  59. 'entitie',
  60. display_name='entitie',
  61. help_text='Replace old entity classtype',
  62. abstract=True,
  63. group=base_group,
  64. parents=em_object,)
  65. person = em.new_class(
  66. 'person',
  67. display_name='Person',
  68. help_text='Replace old person classtype',
  69. abstract=False,
  70. group=base_group,
  71. parents=em_object,)
  72. person.new_field(
  73. 'firstname',
  74. display_name = {
  75. 'eng': 'Firstname',
  76. 'fre': 'Prénom',
  77. },
  78. data_handler = 'varchar',
  79. group = base_group,)
  80. person.new_field(
  81. 'lastname',
  82. display_name = {
  83. 'eng': 'Lastname',
  84. 'fre': 'Nom de famille',
  85. },
  86. data_handler = 'varchar',
  87. group = base_group,)
  88. person.new_field(
  89. '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. person.new_field(
  99. '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. entry = em.new_class(
  111. '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. # Editorial classes #
  119. #####################
  120. editorial_group = em.new_group(
  121. '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. # Classe texte
  129. text = em.new_class(
  130. 'text',
  131. display_name = 'Text',
  132. help_text = 'Abstract class that represent texts',
  133. group = editorial_group,
  134. abstract = True,
  135. parents = entitie,)
  136. text.new_field(
  137. 'title',
  138. display_name = {'eng': 'Title', 'fre': 'Titre'},
  139. group = editorial_group,
  140. data_handler = 'varchar',
  141. nullable = True,)
  142. text.new_field(
  143. 'subtitle',
  144. display_name = { 'eng': 'Subtitle', 'fre': 'Sous-titre',},
  145. group = editorial_group,
  146. data_handler = 'varchar',
  147. nullable = True,
  148. default = None)
  149. # Classe collection
  150. collection = em.new_class(
  151. 'collection',
  152. display_name = 'Collection',
  153. group = editorial_group,
  154. abstract = False,
  155. parents = entitie)
  156. collection.new_field(
  157. 'title',
  158. display_name = 'Title',
  159. group = editorial_group,
  160. data_handler = 'varchar')
  161. # Classe publication
  162. publication = em.new_class( 'publication',
  163. display_name = 'Publication',
  164. group = editorial_group,
  165. abstract = False,
  166. parents = entitie,)
  167. publication.new_field( 'collection',
  168. display_name = 'Collection',
  169. group = editorial_group,
  170. data_handler = 'link',
  171. default = None,
  172. nullable = True,
  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. default = None,
  207. nullable = True,
  208. allowed_classes = [section],
  209. back_reference = ('section', 'childs'))
  210. #####################
  211. # Persons & authors #
  212. #####################
  213. editorial_person_group = em.new_group( 'editorial_person',
  214. display_name = 'Editorial person',
  215. help_text = {
  216. 'eng': 'Introduce the concept of editorial person (authors, translator etc)',
  217. 'fre': 'Contient les classes servant à la gestion des personnes editorials (auteurs, traducteur...)',
  218. },
  219. depends = (editorial_group,))
  220. text_person = em.new_class( 'text_person',
  221. display_name = {
  222. 'eng': 'TextPerson',
  223. 'fre': 'TextePersonne',
  224. },
  225. help_text = {
  226. 'eng': 'Represent a link between someone and a text',
  227. 'fre': 'Représente un lien entre une personne et un texte',
  228. },
  229. group = editorial_person_group,
  230. abstract = True,
  231. parents = entitie,)
  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. 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. text_person.new_field( 'role',
  249. display_name = {
  250. 'eng': 'Person role',
  251. 'fre': 'Role de la personne',
  252. },
  253. data_handler = 'varchar',
  254. group = editorial_person_group)
  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 = {'eng': 'Indexes', 'fre': 'Indexes'},
  310. data_handler = 'list',
  311. back_reference = ('Indexabs', 'texts'),
  312. allowed_classes = [index_abstract],
  313. default = None,
  314. nullable = True,
  315. group = index_group)
  316. index_abstract.new_field( 'texts',
  317. display_name = {
  318. 'eng': 'Text referenced by this index',
  319. 'fre': 'Texte contenant cette index'},
  320. data_handler = 'list',
  321. back_reference = ('Text', 'indexes'),
  322. allowed_classes = [text],
  323. group = index_group)
  324. index_theme = em.new_class(
  325. 'indexTheme',
  326. display_name = {
  327. 'eng': 'Thematic index',
  328. 'fre': 'Index thématique'},
  329. group = index_group,
  330. datasources = 'dummy2',
  331. parents = index_abstract)
  332. index_theme_theme = index_abstract.new_field(
  333. 'theme',
  334. display_name = {
  335. 'eng': 'theme'},
  336. data_handler = 'varchar',
  337. group = index_group)
  338. #############
  339. # USERS #
  340. #############
  341. user_group = em.new_group(
  342. 'users', display_name = 'Lodel users',
  343. help_text = 'Group that handle users en perm')
  344. user = em.new_class(
  345. 'user', display_name = 'Lodel user', help_text = 'Represent a lodel user',
  346. group = user_group, abstract = False)
  347. user.new_field(
  348. 'id', display_name = 'user identifier', help_text = 'Uniq ID',
  349. group = user_group, data_handler = 'uniqid', internal = True)
  350. user.new_field(
  351. 'firstname', display_name = 'Firstname',
  352. group = user_group, data_handler = 'varchar', internal = False)
  353. user.new_field(
  354. 'lastname', display_name = 'Lastname',
  355. group = user_group, data_handler = 'varchar', internal = False)
  356. user.new_field(
  357. 'login', display_name = 'user login', help_text = 'login',
  358. group = user_group, data_handler = 'varchar', uniq = True, internal = False)
  359. user.new_field(
  360. 'password', display_name = 'Password',
  361. group = user_group, data_handler = 'password', internal = False)
  362. em.save('xmlfile', filename = xml_file)
  363. em.save('picklefile', filename = pickle_file)
  364. print("Output written in %s and %s" % (pickle_file, xml_file))