Açıklama Yok
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 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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_object = em.new_class( 'object',
  18. display_name = 'Object',
  19. help_text = 'Main class for all Em objects',
  20. group = base_group,
  21. abstract = True,
  22. )
  23. em_object.new_field( 'lodel_id',
  24. display_name = 'Lodel identifier',
  25. help_text = 'Uniq ID that identify every lodel object',
  26. group = base_group,
  27. data_handler = 'uniqid',
  28. internal = True,
  29. )
  30. em_object.new_field( 'help_text',
  31. display_name = 'Help',
  32. help_text = 'A short text that describe the object',
  33. group = base_group,
  34. internal = True,
  35. data_handler = 'text',
  36. )
  37. em_object.new_field( 'date_create',
  38. display_name = 'Creation date',
  39. group = base_group,
  40. data_handler = 'datetime',
  41. now_on_create = True,
  42. )
  43. em_object.new_field( 'date_update',
  44. display_name = 'Last update',
  45. group = base_group,
  46. data_handler = 'datetime',
  47. now_on_update = True,
  48. )
  49. em_object.new_field( 'classname',
  50. display_name = 'Class name',
  51. group = base_group,
  52. data_handler = 'varchar',
  53. immutable = True
  54. )
  55. ########################
  56. # Lodel old classtypes #
  57. ########################
  58. entitie = em.new_class( 'entitie',
  59. display_name = 'entitie',
  60. help_text = 'Replace old entity classtype',
  61. abstract = True,
  62. group = base_group,
  63. parents = em_object,
  64. )
  65. person = em.new_class( 'person',
  66. display_name = 'Person',
  67. help_text = 'Replace old person classtype',
  68. abstract = True,
  69. group = base_group,
  70. parents = em_object,
  71. )
  72. person.new_field( 'firstname',
  73. display_name = {
  74. 'eng': 'Firstname',
  75. 'fre': 'Prénom',
  76. },
  77. data_handler = 'varchar',
  78. )
  79. person.new_field( 'lastname',
  80. display_name = {
  81. 'eng': 'Lastname',
  82. 'fre': 'Nom de famille',
  83. },
  84. data_handler = 'varchar',
  85. )
  86. person.new_field( 'fullname',
  87. display_name = {
  88. 'eng': 'Fullname',
  89. 'fre': 'Nom complet',
  90. },
  91. group = base_group,
  92. data_handler = 'varchar', # <-- should be concat type
  93. internal = True,
  94. immutable = True,
  95. )
  96. person.new_field( 'alias',
  97. display_name = 'alias',
  98. help_text = {
  99. 'eng': 'Link to other person class instance that represent the same person',
  100. 'fre': 'Lien vers un ensemble d\'instances de la classe personne représentant le même individu',
  101. },
  102. data_handler = 'set',
  103. allowed_classes = [person],
  104. )
  105. entry = em.new_class( 'entry',
  106. display_name = 'Entry',
  107. help_text = 'Replace olf entry classtype',
  108. abstract = True,
  109. group = base_group,
  110. parents = em_object,
  111. )
  112. #####################
  113. # Editorial classes #
  114. #####################
  115. editorial_group = em.new_group( 'editorial_abstract',
  116. display_name = 'Editorial base',
  117. help_text = {
  118. 'eng': 'Contains abstract class to handler editorial contents',
  119. 'fre': 'Contient les classes abstraites permetant la gestion de contenu éditorial'
  120. },
  121. depends = (base_group,)
  122. )
  123. # Classe texte
  124. text = em.new_class( 'text',
  125. display_name = 'Text',
  126. help_text = 'Abstract class that represent texts',
  127. group = editorial_group,
  128. abstract = True,
  129. parents = entitie,
  130. )
  131. text.new_field( 'title',
  132. display_name = {'eng': 'Title', 'fre': 'Titre'},
  133. group = editorial_group,
  134. data_handler = 'varchar',
  135. nullable = True,)
  136. text.new_field( 'subtitle',
  137. display_name = {
  138. 'eng': 'Subtitle',
  139. 'fre': 'Sous-titre',
  140. },
  141. group = editorial_group,
  142. data_handler = 'varchar',
  143. nullable = True)
  144. # Classe collection
  145. collection = em.new_class( 'collection',
  146. display_name = 'Collection',
  147. group = editorial_group,
  148. abstract = False,
  149. parents = entitie)
  150. collection.new_field( 'title',
  151. display_name = 'Title',
  152. group = editorial_group,
  153. data_handler = 'varchar'
  154. )
  155. collection.new_field( 'publications',
  156. display_name = 'Publications',
  157. group = editorial_group,
  158. data_handler = 'list',
  159. back_reference = ('publication', 'collection'))
  160. # Classe publication
  161. publication = em.new_class( 'publication',
  162. display_name = 'Publication',
  163. group = editorial_group,
  164. abstract = False,
  165. parents = entitie,)
  166. publication.new_field( 'collection',
  167. display_name = 'Collection',
  168. group = editorial_group,
  169. data_handler = 'link',
  170. back_reference = ('collection', 'publications'))
  171. #########################
  172. # Texte definition #
  173. #########################
  174. section = em.new_class( 'section',
  175. display_name = 'Section',
  176. group = editorial_group,
  177. abstract = False,
  178. parents = text)
  179. subsection = em.new_class( 'subsection',
  180. display_name = 'Subsection',
  181. group = editorial_group,
  182. abstract = False,
  183. parents = section)
  184. section.new_field( 'childs',
  185. display_name = 'Next section',
  186. group = editorial_group,
  187. data_handler = 'hierarch',
  188. allowed_classes = [subsection],
  189. back_reference = ('subsection', 'parent'))
  190. subsection.new_field( 'parent',
  191. display_name = 'Parent',
  192. group = editorial_group,
  193. data_handler = 'link',
  194. allowed_classes = [section])
  195. #####################
  196. # Persons & authors #
  197. #####################
  198. editorial_person_group = em.new_group( 'editorial_person',
  199. display_name = 'Editorial person',
  200. help_text = {
  201. 'eng': 'Introduce the concept of editorial person (authors, translator etc)',
  202. 'fre': 'Contient les classes servant à la gestion des personnes editorials (auteurs, traducteur...)',
  203. },
  204. depends = (editorial_group,)
  205. )
  206. text_person = em.new_class( 'text_person',
  207. display_name = {
  208. 'eng': 'TextPerson',
  209. 'fre': 'TextePersonne',
  210. },
  211. help_text = {
  212. 'eng': 'Represent a link between someone and a text',
  213. 'fre': 'Représente un lien entre une personne et un texte',
  214. },
  215. group = editorial_person_group,
  216. abstract = True,
  217. parents = entitie,
  218. )
  219. bref_textperson_text = text_person.new_field( 'text',
  220. display_name = {
  221. 'eng': 'Linked text',
  222. 'fre': 'Texte lié',
  223. },
  224. data_handler = 'link',
  225. allowed_classes = [text],
  226. group = editorial_person_group
  227. )
  228. bref_textperson_person = text_person.new_field( 'person',
  229. display_name = {
  230. 'eng': 'Linked person',
  231. 'fre': 'Personne liée',
  232. },
  233. data_handler = 'link',
  234. allowed_classes = [person],
  235. group = editorial_person_group,
  236. )
  237. text_person.new_field( 'role',
  238. display_name = {
  239. 'eng': 'Person role',
  240. 'fre': 'Role de la personne',
  241. },
  242. data_handler = 'varchar',
  243. group = editorial_person_group
  244. )
  245. # simple example of linked text / person
  246. person.new_field( 'linked_texts',
  247. display_name = {
  248. 'eng': 'Linked texts',
  249. 'fre': 'Textes liés',
  250. },
  251. data_handler = 'list',
  252. back_reference = ('Text', 'linked_persons'),
  253. group = editorial_person_group,
  254. )
  255. text.new_field( 'linked_persons',
  256. display_name = {
  257. 'eng': 'Linked persons',
  258. 'fre': 'Personnes liées',
  259. },
  260. data_handler = 'list',
  261. back_reference = ('Person', 'linked_texts'),
  262. group = editorial_person_group,
  263. )
  264. #em.save('xmlfile', filename = 'examples/em_test.xml')
  265. em.save('picklefile', filename = 'examples/em_test.pickle')