123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- #!/usr/bin/python3
- #-*- coding: utf-8 -*-
-
- from lodel.settings.settings import Settings as settings
- settings('globconf.d')
- from lodel.settings import Settings
-
- from lodel.editorial_model.components import *
- from lodel.editorial_model.exceptions import *
- from lodel.editorial_model.model import EditorialModel
-
- em = EditorialModel('testem', 'Test editorial model')
-
- base_group = em.new_group( 'base_group',
- display_name = 'Base group',
- help_text = 'Base group that implements base EM features (like classtype)'
- )
-
- ####################
- # Lodel Object #
- ####################
- em_abstract = em.new_class( 'abstract_object',
- display_name = 'Abstract lodel object',
- help_text = 'For testing purpose',
- group = base_group,
- abstract = True)
-
- em_object = em.new_class( 'object',
- display_name = 'Object',
- help_text = 'Main class for all Em objects',
- group = base_group,
- abstract = True,
- parents = em_abstract,
- )
- em_object.new_field( 'lodel_id',
- display_name = 'Lodel identifier',
- help_text = 'Uniq ID that identify every lodel object',
- group = base_group,
- data_handler = 'uniqid',
- internal = True,
- )
- em_object.new_field( 'help_text',
- display_name = 'Help',
- help_text = 'A short text that describe the object',
- group = base_group,
- internal = True,
- data_handler = 'text',
- )
-
- em_object.new_field( 'date_create',
- display_name = 'Creation date',
- group = base_group,
- data_handler = 'datetime',
- now_on_create = True,
- internal = True,
- )
- em_object.new_field( 'date_update',
- display_name = 'Last update',
- group = base_group,
- data_handler = 'datetime',
- now_on_update = True,
- internal = True,
- )
-
- ########################
- # Lodel old classtypes #
- ########################
- entitie = em.new_class( 'entitie',
- display_name = 'entitie',
- help_text = 'Replace old entity classtype',
- abstract = True,
- group = base_group,
- parents = em_object,
- )
-
- person = em.new_class( 'person',
- display_name = 'Person',
- help_text = 'Replace old person classtype',
- abstract = False,
- group = base_group,
- parents = em_object,
- )
-
- person.new_field( 'firstname',
- display_name = {
- 'eng': 'Firstname',
- 'fre': 'Prénom',
- },
- data_handler = 'varchar',
- )
- person.new_field( 'lastname',
- display_name = {
- 'eng': 'Lastname',
- 'fre': 'Nom de famille',
- },
- data_handler = 'varchar',
- )
- person.new_field( 'fullname',
- display_name = {
- 'eng': 'Fullname',
- 'fre': 'Nom complet',
- },
- group = base_group,
- data_handler = 'Concat',
- field_list = ['firstname', 'lastname'],
- immutable = True,
- )
- person.new_field( 'alias',
- display_name = 'alias',
- help_text = {
- 'eng': 'Link to other person class instance that represent the same person',
- 'fre': 'Lien vers un ensemble d\'instances de la classe personne représentant le même individu',
- },
- data_handler = 'set',
- allowed_classes = [person],
- default = None,
- nullable = True,
- )
-
-
- entry = em.new_class( 'entry',
- display_name = 'Entry',
- help_text = 'Replace olf entry classtype',
- abstract = True,
- group = base_group,
- parents = em_object,
- )
-
- #####################
- # Editorial classes #
- #####################
-
- editorial_group = em.new_group( 'editorial_abstract',
- display_name = 'Editorial base',
- help_text = {
- 'eng': 'Contains abstract class to handler editorial contents',
- 'fre': 'Contient les classes abstraites permetant la gestion de contenu éditorial'
- },
- depends = (base_group,)
- )
-
- # Classe texte
- text = em.new_class( 'text',
- display_name = 'Text',
- help_text = 'Abstract class that represent texts',
- group = editorial_group,
- abstract = True,
- parents = entitie,
- )
-
- text.new_field( 'title',
- display_name = {'eng': 'Title', 'fre': 'Titre'},
- group = editorial_group,
- data_handler = 'varchar',
- nullable = True,)
- text.new_field( 'subtitle',
- display_name = {
- 'eng': 'Subtitle',
- 'fre': 'Sous-titre',
- },
- group = editorial_group,
- data_handler = 'varchar',
- nullable = True,
- default = None)
-
- # Classe collection
- collection = em.new_class( 'collection',
- display_name = 'Collection',
- group = editorial_group,
- abstract = False,
- parents = entitie)
- collection.new_field( 'title',
- display_name = 'Title',
- group = editorial_group,
- data_handler = 'varchar'
- )
- collection.new_field( 'publications',
- display_name = 'Publications',
- group = editorial_group,
- data_handler = 'list',
- back_reference = ('publication', 'collection'))
-
- # Classe publication
- publication = em.new_class( 'publication',
- display_name = 'Publication',
- group = editorial_group,
- abstract = False,
- parents = entitie,)
- publication.new_field( 'collection',
- display_name = 'Collection',
- group = editorial_group,
- data_handler = 'link',
- back_reference = ('collection', 'publications'))
-
- #########################
- # Texte definition #
- #########################
-
- section = em.new_class( 'section',
- display_name = 'Section',
- group = editorial_group,
- abstract = False,
- parents = text)
-
- subsection = em.new_class( 'subsection',
- display_name = 'Subsection',
- group = editorial_group,
- abstract = False,
- parents = section)
-
- section.new_field( 'childs',
- display_name = 'Next section',
- group = editorial_group,
- data_handler = 'hierarch',
- allowed_classes = [subsection],
- back_reference = ('subsection', 'parent'),
- default = None,
- nullable = True)
-
- subsection.new_field( 'parent',
- display_name = 'Parent',
- group = editorial_group,
- data_handler = 'link',
- allowed_classes = [section])
-
- #####################
- # Persons & authors #
- #####################
-
- editorial_person_group = em.new_group( 'editorial_person',
- display_name = 'Editorial person',
- help_text = {
- 'eng': 'Introduce the concept of editorial person (authors, translator etc)',
- 'fre': 'Contient les classes servant à la gestion des personnes editorials (auteurs, traducteur...)',
- },
- depends = (editorial_group,)
- )
- text_person = em.new_class( 'text_person',
- display_name = {
- 'eng': 'TextPerson',
- 'fre': 'TextePersonne',
- },
- help_text = {
- 'eng': 'Represent a link between someone and a text',
- 'fre': 'Représente un lien entre une personne et un texte',
- },
- group = editorial_person_group,
- abstract = True,
- parents = entitie,
- )
- bref_textperson_text = text_person.new_field( 'text',
- display_name = {
- 'eng': 'Linked text',
- 'fre': 'Texte lié',
- },
- data_handler = 'link',
- allowed_classes = [text],
- group = editorial_person_group
- )
- bref_textperson_person = text_person.new_field( 'person',
- display_name = {
- 'eng': 'Linked person',
- 'fre': 'Personne liée',
- },
- data_handler = 'link',
- allowed_classes = [person],
- group = editorial_person_group,
- )
- text_person.new_field( 'role',
- display_name = {
- 'eng': 'Person role',
- 'fre': 'Role de la personne',
- },
- data_handler = 'varchar',
- group = editorial_person_group
- )
-
- # simple example of linked text / person
- person.new_field( 'linked_texts',
- display_name = {
- 'eng': 'Linked texts',
- 'fre': 'Textes liés',
- },
- data_handler = 'list',
- back_reference = ('Text', 'linked_persons'),
- group = editorial_person_group,
- allowed_classes = [text],
- default = None,
- nullable = True)
-
- text.new_field( 'linked_persons',
- display_name = {
- 'eng': 'Linked persons',
- 'fre': 'Personnes liées',
- },
- data_handler = 'list',
- back_reference = ('Person', 'linked_texts'),
- group = editorial_person_group,
- allowed_classes = [person],
- default = None,
- nullable = True)
-
- #####################
- # Index classes # <--- Note : using a different datasource for testing
- ##################### purpose
-
- index_group = em.new_group( 'index_group',
- display_name = 'Indexes',
- help_text = {
- 'eng': 'EM class that represents indexes'},
- depends = (editorial_group,))
-
- index_abstract = em.new_class(
- 'indexAbs',
- display_name = {'eng': 'Abstract Index'},
- help_text = {'eng': 'Abstract class common to each Index classes'},
- abstract = True,
- group = index_group,
- datasources = 'dummy2',
- parents = em_object)
-
- index_name = index_abstract.new_field(
- 'name',
- display_name = {
- 'eng': 'name',
- 'fre': 'nom'},
- data_handler = 'varchar',
- group = index_group)
-
- index_value = index_abstract.new_field(
- 'value',
- display_name = {
- 'eng': 'value',
- 'fre': 'valeur'},
- data_handler = 'varchar',
- group = index_group)
-
- text.new_field( 'indexes',
- display_name = {
- 'eng': 'Indexes',
- 'fre': 'Indexes'},
- data_handler = 'list',
- back_reference = ('Indexabs', 'texts'),
- allowed_classes = [index_abstract],
- default = None,
- nullable = True,
- group = index_group)
-
- index_abstract.new_field( 'texts',
- display_name = {
- 'eng': 'Text referenced by this index',
- 'fre': 'Texte contenant cette index'},
- data_handler = 'list',
- back_reference = ('Text', 'indexes'),
- allowed_classes = [text],
- group = index_group)
-
- index_theme = em.new_class(
- 'indexTheme',
- display_name = {
- 'eng': 'Thematic index',
- 'fre': 'Index thématique'},
- group = index_group,
- datasources = 'dummy2',
- parents = index_abstract)
-
- index_theme_theme = index_abstract.new_field(
- 'theme',
- display_name = {
- 'eng': 'theme'},
- data_handler = 'varchar',
- group = index_group)
-
- #em.save('xmlfile', filename = 'examples/em_test.xml')
- pickle_file = 'examples/em_test.pickle'
- em.save('picklefile', filename = pickle_file)
- print("Output written in %s" % pickle_file)
|