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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. )
  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. )
  140. # Classe collection
  141. collection = em.new_class( 'collection',
  142. display_name = 'Collection',
  143. group = editorial_group,
  144. abstract = True,
  145. parents = entitie,
  146. )
  147. collection.new_field( 'title',
  148. display_name = 'Title',
  149. group = editorial_group,
  150. abstract = True,
  151. data_handler = 'varchar'
  152. )
  153. #####################
  154. # Persons & authors #
  155. #####################
  156. editorial_person_group = em.new_group( 'editorial_person',
  157. display_name = 'Editorial person',
  158. help_text = {
  159. 'eng': 'Introduce the concept of editorial person (authors, translator etc)',
  160. 'fre': 'Contient les classes servant à la gestion des personnes editorials (auteurs, traducteur...)',
  161. },
  162. depends = (editorial_group,)
  163. )
  164. text_person = em.new_class( 'text_person',
  165. display_name = {
  166. 'eng': 'TextPerson',
  167. 'fre': 'TextePersonne',
  168. },
  169. help_text = {
  170. 'eng': 'Represent a link between someone and a text',
  171. 'fre': 'Représente un lien entre une personne et un texte',
  172. },
  173. group = editorial_person_group,
  174. abstract = True,
  175. parents = entitie,
  176. )
  177. bref_textperson_text = text_person.new_field( 'text',
  178. display_name = {
  179. 'eng': 'Linked text',
  180. 'fre': 'Texte lié',
  181. },
  182. data_handler = 'link',
  183. allowed_classes = [text],
  184. group = editorial_person_group
  185. )
  186. bref_textperson_person = text_person.new_field( 'person',
  187. display_name = {
  188. 'eng': 'Linked person',
  189. 'fre': 'Personne liée',
  190. },
  191. data_handler = 'link',
  192. allowed_classes = [person],
  193. group = editorial_person_group,
  194. )
  195. text_person.new_field( 'role',
  196. display_name = {
  197. 'eng': 'Person role',
  198. 'fre': 'Role de la personne',
  199. },
  200. data_handler = 'varchar',
  201. group = editorial_person_group
  202. )
  203. # simple example of linked text / person
  204. person.new_field( 'linked_texts',
  205. display_name = {
  206. 'eng': 'Linked texts',
  207. 'fre': 'Textes liés',
  208. },
  209. data_handler = 'list',
  210. back_reference = ('Text', 'linked_persons'),
  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 = 'list',
  219. back_reference = ('Person', 'linked_texts'),
  220. group = editorial_person_group,
  221. )
  222. em.save('picklefile', filename = 'examples/em_test.pickle')