Pārlūkot izejas kodu

Added new comands

Roland Haroutiounian 7 gadus atpakaļ
vecāks
revīzija
71cf7c52f6

+ 397
- 0
management/commands/em_test.py Parādīt failu

@@ -0,0 +1,397 @@
1
+from flask_script import Command
2
+from lodel.editorial_model.model import EditorialModel
3
+
4
+class LodelCommand(Command):
5
+    
6
+    def run(self):
7
+        em = EditorialModel('testem', 'Test editorial model')
8
+        base_group = em.new_group(
9
+            'base_group', 
10
+            display_name='Base group',
11
+            help_text = 'Base group that implements base EM features (like classtype)')
12
+        
13
+        ################
14
+        # Lodel object #
15
+        ################
16
+        em_abstract = em.new_class(
17
+            'abstract_object', 
18
+            display_name='Abstract lodel object',
19
+            help_text = 'For testing purpose', 
20
+            group=base_group,
21
+            abstract=True)
22
+        em_object = em.new_class(
23
+            'object', 
24
+            display_name='Object',
25
+            help_text='Main class for all Em objects', 
26
+            group=base_group,
27
+            abstract=True, 
28
+            parents=em_abstract,)
29
+        em_object.new_field(
30
+            'lodel_id', 
31
+            display_name='Lodel identifier',
32
+            help_text='Uniq ID that identify every lodel object',
33
+            group=base_group, 
34
+            data_handler='uniqid', 
35
+            internal=True,)
36
+        em_object.new_field(
37
+            'help_text', 
38
+            display_name='Help',
39
+            help_text='A short text that describe the object', 
40
+            group=base_group,
41
+            internal=True, 
42
+            data_handler='text',)
43
+        em_object.new_field(
44
+            'date_create', 
45
+            display_name='Creation date', 
46
+            group=base_group,
47
+            data_handler='datetime', 
48
+            now_on_create=True, 
49
+            internal=True,)
50
+        em_object.new_field(
51
+            'date_update', 
52
+            display_name='Last update', 
53
+            group=base_group,
54
+            data_handler='datetime', 
55
+            now_on_update=True, 
56
+            internal=True,)
57
+
58
+        ########################
59
+        # Lodel old classtypes #
60
+        ########################
61
+        entitie = em.new_class(
62
+            'entitie', 
63
+            display_name='entitie',
64
+            help_text='Replace old entity classtype', 
65
+            abstract=True, 
66
+            group=base_group, 
67
+            parents=em_object,)
68
+        person = em.new_class(
69
+            'person', 
70
+            display_name='Person',
71
+            help_text='Replace old person classtype', 
72
+            abstract=False,
73
+            group=base_group,
74
+            parents=em_object,)
75
+        person.new_field(
76
+            'firstname', 
77
+            display_name = {
78
+                'eng': 'Firstname', 
79
+                'fre': 'Prénom',
80
+            },
81
+            data_handler = 'varchar', 
82
+            group = base_group,)
83
+        person.new_field(
84
+            'lastname', 
85
+            display_name = {
86
+                'eng': 'Lastname', 
87
+                'fre': 'Nom de famille',
88
+            },
89
+            data_handler = 'varchar',
90
+            group = base_group,)
91
+        person.new_field(
92
+            'fullname', 
93
+            display_name = {
94
+                'eng': 'Fullname', 
95
+                'fre': 'Nom complet',
96
+            },
97
+            group = base_group, 
98
+            data_handler = 'Concat',
99
+            field_list = ['firstname', 'lastname'], 
100
+            immutable = True,)
101
+        person.new_field(
102
+            'alias', 
103
+            display_name = 'alias',
104
+            help_text = {
105
+                'eng': 'Link to other person class instance that represent the same person',
106
+                'fre': 'Lien vers un ensemble d\'instances de la classe personne représentant le même individu',
107
+            },
108
+            data_handler = 'set', 
109
+            allowed_classes = [person], 
110
+            default = None,
111
+            nullable = True, 
112
+            group = base_group,)
113
+        entry = em.new_class(
114
+            'entry', 
115
+            display_name = 'Entry',
116
+            help_text = 'Replace olf entry classtype', 
117
+            abstract = True,
118
+            group = base_group, 
119
+            parents = em_object,)
120
+        
121
+        #####################
122
+        # Editorial classes #
123
+        #####################
124
+        editorial_group = em.new_group(
125
+            'editorial_abstract', 
126
+            display_name = 'Editorial base',
127
+            help_text = {
128
+                'eng': 'Contains abstract class to handler editorial contents',
129
+                'fre': 'Contient les classes abstraites permetant la gestion de contenu éditorial'
130
+            },
131
+            depends = (base_group,))
132
+        
133
+        # Classe texte
134
+        text = em.new_class(
135
+            'text', 
136
+            display_name = 'Text',
137
+            help_text = 'Abstract class that represent texts',
138
+            group = editorial_group, 
139
+            abstract = True, 
140
+            parents = entitie,)
141
+        text.new_field(
142
+            'title', 
143
+            display_name = {'eng': 'Title', 'fre': 'Titre'},
144
+            group = editorial_group, 
145
+            data_handler = 'varchar', 
146
+            nullable = True,)
147
+        text.new_field(
148
+            'subtitle', 
149
+            display_name = { 'eng': 'Subtitle', 'fre': 'Sous-titre',},
150
+            group = editorial_group, 
151
+            data_handler = 'varchar', 
152
+            nullable = True,
153
+            default = None)
154
+        
155
+        # Classe collection
156
+        collection = em.new_class(
157
+            'collection', 
158
+            display_name = 'Collection',
159
+            group = editorial_group, 
160
+            abstract = False, 
161
+            parents = entitie)
162
+        collection.new_field(
163
+            'title', 
164
+            display_name = 'Title', 
165
+            group = editorial_group,
166
+            data_handler = 'varchar')
167
+        
168
+        # Classe publication
169
+        publication = em.new_class(  'publication',
170
+                            display_name = 'Publication',
171
+                            group = editorial_group,
172
+                            abstract = False,
173
+                            parents = entitie,)
174
+        publication.new_field(  'collection',
175
+                        display_name = 'Collection',
176
+                        group = editorial_group,
177
+                        data_handler = 'link',
178
+                        default = None,
179
+                        nullable = True,
180
+                        allowed_classes = [collection],
181
+                        back_reference = ('collection', 'publications'))
182
+        collection.new_field(   'publications',
183
+                        display_name = 'Publications',
184
+                        group = editorial_group,
185
+                        data_handler = 'list',
186
+                        allowed_classes = [publication],
187
+                        back_reference = ('publication', 'collection'))
188
+
189
+        #########################
190
+        #   Texte definition    #
191
+        #########################
192
+
193
+        section = em.new_class('section',
194
+                            display_name = 'Section',
195
+                            group = editorial_group,
196
+                            abstract = False,
197
+                            parents = text)
198
+        subsection = em.new_class(  'subsection',
199
+                            display_name = 'Subsection',
200
+                            group = editorial_group,
201
+                            abstract = False,
202
+                            parents = section)
203
+        section.new_field(  'childs',
204
+                    display_name = 'Next section',
205
+                    group = editorial_group,
206
+                    data_handler = 'hierarch',
207
+                    allowed_classes = [subsection],
208
+                    back_reference = ('subsection', 'parent'),
209
+                    default = None,
210
+                    nullable = True)
211
+        subsection.new_field(   'parent',
212
+                        display_name = 'Parent',
213
+                        group = editorial_group,
214
+                        data_handler = 'link',
215
+                        default = None,
216
+                        nullable = True,
217
+                        allowed_classes = [section],
218
+                        back_reference = ('section', 'childs'))
219
+
220
+        #####################
221
+        # Persons & authors #
222
+        #####################
223
+        editorial_person_group = em.new_group(  'editorial_person',
224
+                                        display_name = 'Editorial person',
225
+                                        help_text = {
226
+                                            'eng': 'Introduce the concept of editorial person (authors, translator etc)',
227
+                                            'fre': 'Contient les classes servant à la gestion des personnes editorials (auteurs, traducteur...)',
228
+                                        },
229
+                                        depends = (editorial_group,))
230
+        text_person = em.new_class( 'text_person',
231
+                            display_name = {
232
+                                'eng': 'TextPerson',
233
+                                'fre': 'TextePersonne',
234
+                            },
235
+                            help_text = {
236
+                                'eng': 'Represent a link between someone and a text',
237
+                                'fre': 'Représente un lien entre une personne et un texte',
238
+                            },
239
+                            group = editorial_person_group,
240
+                            abstract = True,
241
+                            parents = entitie,)
242
+        bref_textperson_text = text_person.new_field(  'text',
243
+                                                display_name = {
244
+                                                    'eng': 'Linked text',
245
+                                                    'fre': 'Texte lié',
246
+                                                },
247
+                                                data_handler = 'link',
248
+                                                allowed_classes = [text],
249
+                                                group = editorial_person_group)
250
+        bref_textperson_person = text_person.new_field( 'person',
251
+                                                display_name = {
252
+                                                    'eng': 'Linked person',
253
+                                                    'fre': 'Personne liée',
254
+                                                },
255
+                                                data_handler = 'link',
256
+                                                allowed_classes = [person],
257
+                                                group = editorial_person_group,)
258
+        text_person.new_field(  'role',
259
+                        display_name = {
260
+                            'eng': 'Person role',
261
+                            'fre': 'Role de la personne',
262
+                        },
263
+                        data_handler = 'varchar',
264
+                        group = editorial_person_group)
265
+
266
+        # simple example of linked text / person
267
+        person.new_field(   'linked_texts',
268
+                            display_name = {
269
+                                'eng': 'Linked texts',
270
+                                'fre': 'Textes liés',
271
+                                },
272
+                         data_handler = 'list',
273
+                         back_reference = ('Text', 'linked_persons'),
274
+                         group = editorial_person_group,
275
+                         allowed_classes = [text],
276
+                         default = None,
277
+                         nullable = True)
278
+
279
+        text.new_field( 'linked_persons',
280
+                display_name = {
281
+                    'eng': 'Linked persons',
282
+                    'fre': 'Personnes liées',
283
+                },
284
+                data_handler = 'list',
285
+                back_reference = ('Person', 'linked_texts'),
286
+                group = editorial_person_group,
287
+                allowed_classes = [person],
288
+                default = None,
289
+                nullable = True)
290
+
291
+        #####################
292
+        # Index classes     # <--- Note :   using a different datasource for testing
293
+        #####################               purpose
294
+
295
+        index_group = em.new_group( 'index_group',
296
+                            display_name = 'Indexes',
297
+                            help_text = {
298
+                                'eng': 'EM class that represents indexes'},
299
+                            depends = (editorial_group,))
300
+
301
+        index_abstract = em.new_class(
302
+            'indexAbs',
303
+            display_name = {'eng': 'Abstract Index'},
304
+            help_text = {'eng': 'Abstract class common to each Index classes'},
305
+            abstract = True,
306
+            group = index_group,
307
+            datasources = 'dummy2',
308
+            parents = em_object)
309
+
310
+        index_name = index_abstract.new_field(
311
+            'name',
312
+            display_name = {
313
+                'eng': 'name',
314
+                'fre': 'nom'},
315
+            data_handler = 'varchar',
316
+            group = index_group)
317
+
318
+        index_value = index_abstract.new_field(
319
+            'value',
320
+            display_name = {
321
+                'eng': 'value',
322
+                'fre': 'valeur'},
323
+            data_handler = 'varchar',
324
+            group = index_group)
325
+
326
+        text.new_field( 'indexes',
327
+                        display_name = {'eng': 'Indexes', 'fre': 'Indexes'},
328
+                        data_handler = 'list',
329
+                        back_reference = ('Indexabs', 'texts'),
330
+                        allowed_classes = [index_abstract],
331
+                        default = None,
332
+                        nullable = True,
333
+                        group = index_group)
334
+
335
+        index_abstract.new_field( 'texts',
336
+                                  display_name = {
337
+                                      'eng': 'Text referenced by this index',
338
+                                      'fre': 'Texte contenant cette index'},
339
+                                 data_handler = 'list',
340
+                                 back_reference = ('Text', 'indexes'),
341
+                                 allowed_classes = [text],
342
+                                 group = index_group)
343
+
344
+        index_theme = em.new_class(
345
+                                    'indexTheme',
346
+                                    display_name = {
347
+                                        'eng': 'Thematic index',
348
+                                        'fre': 'Index thématique'},
349
+                                   group = index_group,
350
+                                   datasources = 'dummy2',
351
+                                   parents = index_abstract)
352
+
353
+        index_theme_theme = index_abstract.new_field(
354
+            'theme',
355
+            display_name = {
356
+                'eng': 'theme'},
357
+            data_handler = 'varchar',
358
+            group = index_group)
359
+
360
+        #############
361
+        #   USERS   #
362
+        #############
363
+
364
+        user_group = em.new_group(
365
+            'users', display_name = 'Lodel users',
366
+            help_text = 'Group that handle users en perm')
367
+
368
+        user = em.new_class(
369
+            'user', display_name = 'Lodel user', help_text = 'Represent a lodel user',
370
+            group = user_group, abstract = False)
371
+
372
+        user.new_field(
373
+            'id', display_name = 'user identifier', help_text = 'Uniq ID',
374
+            group = user_group, data_handler = 'uniqid', internal = True)
375
+
376
+        user.new_field(
377
+            'firstname', display_name = 'Firstname',
378
+            group = user_group, data_handler = 'varchar', internal = False)
379
+
380
+        user.new_field(
381
+            'lastname', display_name = 'Lastname',
382
+            group = user_group, data_handler = 'varchar', internal = False)
383
+
384
+        user.new_field(
385
+            'login', display_name = 'user login', help_text = 'login',
386
+            group = user_group, data_handler = 'varchar', uniq = True, internal = False)
387
+
388
+        user.new_field(
389
+            'password', display_name = 'Password',
390
+            group = user_group, data_handler = 'password', internal = False)
391
+
392
+
393
+        #em.save('xmlfile', filename = 'examples/em_test.xml')
394
+        pickle_file = 'examples/em_test.pickle'
395
+        em.save('picklefile', filename = pickle_file)
396
+        print("Output written in %s" % pickle_file)
397
+

+ 1
- 3
management/commands/generate_dyncode.py Parādīt failu

@@ -1,8 +1,6 @@
1 1
 from flask_script import Command, Option
2 2
 
3
-from lodel.editorial_model.model import EditorialModel
4
-from lodel.leapi import lefactory
5
-from lodel.management.utils import generate_dyncode
3
+from management.utils import generate_dyncode
6 4
 
7 5
 class LodelCommand(Command):
8 6
 

+ 22
- 0
management/commands/lodelsites_em.py Parādīt failu

@@ -0,0 +1,22 @@
1
+from flask_script import Command
2
+from lodel.editorial_model.model import EditorialModel
3
+
4
+class LodelCommand(Command):
5
+
6
+    def run(self, model_file, translator):
7
+        em = EditorialModel('LodelSites', 'LodelSites editorial model')
8
+        
9
+        base_group = em.new_group('base_group', display_name='Base group', help_text='Base group that implements base EM features (like classtype)')
10
+        
11
+        em_lodel_site = em.new_class('LodelSite', group=base_group)
12
+        em_lodel_site.new_field('name', display_name='lodelSiteName', help_text='Lodel site full name', group=base_group, data_handler='varchar')
13
+        em_lodel_site.new_field('shortname', display_name='lodelSiteShortName', help_text='Lodel site short string identifier', group=base_group, data_handler='varchar', max_length=5, uniq=True)
14
+        em_lodel_site.new_field('extensions', display_text='lodeSiteExtensions', help_text='Lodel site extensions', group=base_group, data_handler='varcharlist', delimiter=' ')
15
+        em_lodel_site.new_field('em_groups', display_text = 'lodelSiteEmGroups', help_text = 'Lodel site EM groups', group = base_group, data_handler = 'text',)
16
+        
17
+        pickle_file_path = 'examples/lodelsites_em.pickle'
18
+        xml_file_path = 'examples/lodelsites_em.xml'
19
+
20
+        em.save('xmlfile', filename=xml_file_path)
21
+        em.save('picklefile', filename=pickle_file_path)
22
+        print('The %s (XML) and %s (Pickle) files are created' % (xml_file_path, pickle_file_path))

Notiek ielāde…
Atcelt
Saglabāt