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.

test_em.py 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 = 'integer',
  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. )
  126. text.new_field( 'title',
  127. display_name = {'eng': 'Title', 'fre': 'Titre'},
  128. group = editorial_group,
  129. data_handler = 'varchar',
  130. )
  131. text.new_field( 'subtitle',
  132. display_name = {
  133. 'eng': 'Subtitle',
  134. 'fre': 'Sous-titre',
  135. },
  136. group = editorial_group,
  137. data_handler = 'varchar',
  138. )
  139. # Classe collection
  140. collection = em.new_class( 'collection',
  141. display_name = 'Collection',
  142. group = editorial_group,
  143. abstract = True,
  144. )
  145. collection.new_field( 'title',
  146. display_name = 'Title',
  147. group = editorial_group,
  148. abstract = True,
  149. data_handler = 'varchar'
  150. )
  151. #####################
  152. # Persons & authors #
  153. #####################
  154. editorial_person_group = em.new_group( 'editorial_person',
  155. display_name = 'Editorial person',
  156. help_text = {
  157. 'eng': 'Introduce the concept of editorial person (authors, translator etc)',
  158. 'fre': 'Contient les classes servant à la gestion des personnes editorials (auteurs, traducteur...)',
  159. },
  160. depends = (editorial_group,)
  161. )
  162. text_person = em.new_class( 'text_person',
  163. display_name = {
  164. 'eng': 'TextPerson',
  165. 'fre': 'TextePersonne',
  166. },
  167. help_text = {
  168. 'eng': 'Represent a link between someone and a text',
  169. 'fre': 'Représente un lien entre une personne et un texte',
  170. },
  171. group = editorial_person_group,
  172. abstract = True,
  173. )
  174. bref_textperson_text = text_person.new_field( 'text',
  175. display_name = {
  176. 'eng': 'Linked text',
  177. 'fre': 'Texte lié',
  178. },
  179. data_handler = 'link',
  180. allowed_classes = [text],
  181. group = editorial_person_group
  182. )
  183. bref_textperson_person = text_person.new_field( 'person',
  184. display_name = {
  185. 'eng': 'Linked person',
  186. 'fre': 'Personne liée',
  187. },
  188. data_handler = 'link',
  189. allowed_classes = [person],
  190. group = editorial_person_group,
  191. )
  192. text_person.new_field( 'role',
  193. display_name = {
  194. 'eng': 'Person role',
  195. 'fre': 'Role de la personne',
  196. },
  197. data_handler = 'varchar',
  198. group = editorial_person_group
  199. )
  200. person.new_field( 'linked_texts',
  201. display_name = {
  202. 'eng': 'Linked texts',
  203. 'fre': 'Textes liés',
  204. },
  205. data_handler = 'relation',
  206. data_handler_kwargs = {
  207. 'data_handler': 'list',
  208. 'allowed_class': text_person,
  209. 'backreference': bref_textperson_text,
  210. },
  211. group = editorial_person_group,
  212. )
  213. text.new_field( 'linked_persons',
  214. display_name = {
  215. 'eng': 'Linked persons',
  216. 'fre': 'Personnes liées',
  217. },
  218. data_handler = 'relation',
  219. data_handler_kwargs = {
  220. 'data_handler': 'list',
  221. 'allowed_class': text_person,
  222. 'backreference': bref_textperson_person,
  223. },
  224. group = editorial_person_group,
  225. )
  226. em.save('picklefile', filename = '/tmp/em_test.pickle')