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

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