Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

em_test.py 11KB

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