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

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