source: trunk/Schemata.py @ 3130

Revision 3130, 14.2 KB checked in by jukka, 9 years ago (diff)

Working on simpler, more robust translations. Prepared things for upgrade.

Line 
1# Copyright 2006 by the LeMill Team (see AUTHORS)
2#
3# This file is part of LeMill.
4#
5# LeMill is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# LeMill is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with LeMill; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19
20#These are common pieces of schema for content types
21from Products.Archetypes.public import *
22from FieldsWidgets import *
23from config import LICENSES, ALL_LICENSES, SUBJECT_AREAS, TARGET_GROUPS
24
25
26# Modifications that need to affect globally
27BaseSchema['effectiveDate'].widget.visible = {'edit':'invisible', 'view':'invisible'}
28BaseSchema['expirationDate'].widget.visible = {'edit':'invisible', 'view':'invisible'}
29
30
31
32state = Schema((
33    StringField('state',
34              searchable=False,
35              index='FieldIndex:schema',
36              widget = StringWidget(
37                  visible = {'view':'invisible', 'edit':'invisible'},
38                  ),
39              )
40))
41
42editing_settings = Schema((
43    StringField('editingMode', # Disabled for 3.1, (made invisible), to be removed in 3.2.
44              vocabulary = DisplayList((
45                  ("anybody_can_edit", "Anybody can edit this learning resource"),
46                  ("other_users_can_edit_a_copy", "Other users can only edit a copy of this resource"),
47              )),
48              schemata='metadata',
49              accessor='getEditingMode',
50              mutator='setEditingMode',
51              searchable=False,
52              default='anybody_can_edit',
53              widget = SelectionWidget(
54                  condition='object/allowSettingOfEditingPermissions',# Condition to show widget or not
55                  format = 'radio',
56                  visible = {'view':'invisible', 'edit':'invisible'},
57                  ),
58              ),
59    BooleanField('hideDrafts',
60              default=True,
61              schemata='metadata',
62              accessor='getHideDrafts',
63              mutator='setHideDrafts',
64              searchable=False,
65              widget = BooleanWidget(
66                  condition='object/allowSettingOfEditingPermissions',
67                  visible = {'view':'invisible', 'edit':'visible'},
68                  label = 'Draft version is hidden from other users',
69                  label_msgid = 'label_hide_drafts',
70                  i18n_domain = 'lemill',
71                  ),
72              ),
73))
74
75bodytext = Schema((
76    WYSIWYMField('bodyText',
77                 accessor="getBodyText",
78                 mutator = "setBodyText",
79                 edit_accessor = 'getRawBodyText',
80                 index='ZCTextIndex',
81                 copied_in_translation=True,
82                 searchable = True,
83                 widget=LeVisualWidget(label = "Body text",
84                                      label_msgid = "label_wysiwym_body_text",
85                                      i18n_domain = "lemill",
86                                      ),
87                ),
88))
89
90
91description = Schema((
92    StringField('description',
93        index=None,
94        searchable=True,
95        schemata="metadata",
96        widget=LeTextAreaWidget(
97            rows = 4,
98            label="Description",
99            label_msgid="label_description",
100            i18n_domain="lemill"),
101    )
102))
103
104no_description = Schema((
105    StringField('description',
106        searchable=False,
107        schemata = "metadata",
108        widget = LeTextAreaWidget(
109            visible={'view':'invisible','edit':'invisible'}
110        ),
111    ),
112))
113
114language_schema = Schema((
115    StringField(
116            'language',
117            index='FieldIndex:schema',
118            schemata="metadata",
119            accessor="Language",
120            default_method ='defaultLanguage',
121            vocabulary='getLanguagelist',
122            widget=SelectionWidget(
123                label='Language',
124                label_msgid="label_language",
125                i18n_domain="lemill"
126                ),
127        ),
128))
129
130license_schema = Schema((
131   StringField('rights',
132       schemata="metadata",
133       default = "CreativeCommons",
134       copied_in_translation=True,
135       vocabulary=DisplayList((LICENSES)),
136       widget=CopyrightWidget(
137           visible={'edit':'visible'},
138                label='Rights',
139                label_msgid='label_rights',
140                i18n_domain="lemill",
141                use_label=0
142           ),
143       ),
144))
145
146
147latest_edit_schema = Schema((
148   ComputedField('latestEdit',
149        index = 'DateIndex:schema',
150        copied_in_translation=True,
151        expression = 'here.getLatestEditDate()',
152        widget=ComputedWidget(
153            visible={'edit':'invisible', 'view':'invisible'}
154            ),
155        ),
156))
157
158# Overwrite some Archetypes ExtensibleMetadata.py field definitions to make them go away.
159lemill_metadata_mods = Schema((
160    StringField(
161        name='title',
162        required=1,
163        searchable=1,
164        default='',
165        accessor='Title',
166        copied_in_translation=True,
167        widget=LeStringWidget(
168            label_msgid='label_title',
169            visible={'view' : 'invisible'},
170            i18n_domain='plone',
171        ),
172    ),
173   StringField('allowDiscussion',
174       default='0',
175       widget=SelectionWidget(
176           visible={'view':'invisible','edit':'invisible'}
177           ),
178       ),
179   LinesField('subject',
180       searchable=False,
181       index=None,
182       widget=KeywordWidget(
183           visible={'view':'invisible','edit':'invisible'}
184           ),
185       ),
186   LinesField('contributors',
187       widget=LinesWidget(
188           visible={'view':'invisible','edit':'invisible'}
189           ),
190       ),
191   LinesField('relatedItems',
192       searchable=False,
193       index=None,
194       widget=KeywordWidget(
195           visible={'view':'invisible','edit':'invisible'}
196           ),
197       ),
198   
199))
200
201
202tags = Schema((
203   TagsField('tags',
204        index="KeywordIndex:schema",
205        accessor="getTags",
206        searchable=True,
207        widget=TagsWidget(
208            label="Tags",
209            label_msgid="label_tags",
210            description="Enter descriptive tags for this resource, separated by commas.",
211            description_msgid="help_tags",
212            i18n_domain="lemill"
213        ),
214        schemata="metadata",
215    ),
216))
217
218coverImage = Schema((
219    ImageField('coverImage',
220               schemata="metadata",
221               required=False,
222               accessor='getCoverImage',
223               mutator='setCoverImage',
224               swallowResizeExceptions=True,
225               copied_in_translation=True,
226               original_size=(120,120),
227               widget = ImageWidget(
228                   visible={'view':'invisible','edit':'invisible'},
229                   ),
230               ),
231    BooleanField('hasCoverImage',
232                default=False,
233                index="FieldIndex:schema",
234                accessor='getHasCoverImage',
235                mutator='setHasCoverImage',
236                copied_in_translation=True,
237                widget = BooleanWidget(
238                    visible = {'view':'invisible', 'edit':'invisible'},
239                    ),
240                ),
241))
242
243author_schema = Schema((
244    LinesField('creators',
245              schemata="metadata",
246              searchable=True,
247              accessor='getAuthorsNames',
248              widget = StringWidget(
249                  visible = {'view':'invisible', 'edit':'invisible'},
250                  ),
251              )
252))
253
254
255
256
257translation_schema = Schema((
258    ReferenceField('translation_of', # to be removed in 3.2
259        relationship = 'translates',
260        widget = ReferenceWidget(
261            label="Translation of",
262            label_msgid="label_translation_of",           
263            visible = { 'view': 'visible', 'edit': 'invisible' },
264            i18n_domain="lemill"
265        ),
266    ),
267    ReferenceField('translations', # to be removed in 3.2
268        relationship = 'has translations',
269        multiValued = True,
270        widget = ReferenceWidget(
271            label="Translations",
272            label_msgid="label_translations",           
273            visible = { 'view': 'visible', 'edit': 'invisible' },
274            i18n_domain="lemill"
275        ),
276    ),
277    TranslationField('other_languages',
278        index = "KeywordIndex:schema",
279        multivalued=True,
280        schemata="metadata",
281        widget=TranslationWidget(
282            format="checkbox",
283            label="Versions in other languages",
284            label_msgid="label_versions_in_other_languages",
285            visible = { 'view': 'invisible', 'edit': 'visible' },
286            i18n_domain="lemill",
287        ),
288    ),   
289))
290
291# to be removed in 3.2
292branching_schema = Schema((
293    ReferenceField('branch_of',
294        relationship = 'branches',
295        widget = ReferenceWidget(
296            label = "Branch of",
297            visible = { 'view': 'visible', 'edit': 'invisible' },
298            i18n_domain = "lemill"
299        ),
300    ),
301    ReferenceField('branches',
302        relationship = 'has branches',
303        multiValued = True,
304        widget = ReferenceWidget(
305            label = "Branches",
306            visible = { 'view': 'visible', 'edit': 'invisible' },
307            i18n_domain = "lemill"
308        ),
309    ),
310))
311
312group_sharing = Schema((
313    ReferenceField('groupEditing',
314        relationship = "is_edited_by",
315        schemata = 'metadata',
316        index="KeywordIndex:schema",
317        vocabulary = 'getUserGroups',
318        enforceVocabulary = False,
319        multiValued = True,
320        copied_in_translation=False,
321        copied_in_branching=False,
322        widget=GroupWidget(
323            label="Assigned group",
324            label_msgid="label_assigned_group",
325            description="Assign one of your groups to work with this resource.",
326            description_msgid="help_resource_group",
327            i18n_domain="lemill",
328            visible={'edit': 'visible', 'view': 'invisible'},
329            ),
330        ),
331
332
333    ))
334
335target_group_schema = Schema((
336    LinesField('target_group',
337        vocabulary = DisplayList(zip(TARGET_GROUPS,TARGET_GROUPS)),
338        index = "KeywordIndex:schema",
339        multivalued=True,
340        copied_in_translation=True,
341        schemata="metadata",
342        widget=TwoColumnMultiSelectionWidget(
343            format="checkbox",
344            label="Target group",
345            label_msgid="label_target_group",
346            i18n_domain="lemill",
347        ),
348    ),
349))
350
351subject_area_schema = Schema((
352    LinesField('subject_area',
353        vocabulary = DisplayList(zip(SUBJECT_AREAS,SUBJECT_AREAS)),
354        index = "KeywordIndex:schema",
355        multivalued=True,
356        copied_in_translation=True,
357        schemata="metadata",
358        widget=TwoColumnMultiSelectionWidget(
359            format="checkbox",
360            label="Subject area",
361            label_msgid="label_subject_area",
362            i18n_domain="lemill",
363        ),
364    ),
365))
366
367deletionReason = Schema((
368    StringField('deletionReason',
369        searchable=False,
370        schemata = "metadata",
371        widget = TextAreaWidget(
372            visible={'view':'invisible','edit':'invisible'}
373        ),
374    ),
375))
376
377# Jukka 11.4: Removed ieee_lom_lre_ap. These shouldn't be handled with separate fields, write adapters instead.
378
379
380score = Schema((
381    IntegerField('score',
382        index = 'FieldIndex:schema',
383        default = 1,
384        widget = IntegerWidget(
385                 visible = {'view':'invisible', 'edit':'invisible'},
386             ),
387        ),
388))
389
390links_schema=Schema((
391   LeMillLinksField('contentLinks',
392        accessor="getContentLinks",
393        mutator = "setContentLinks",
394        copied_in_translation=True,
395        index=None,
396        widget=LeMillLinksWidget(label = "Content",
397            label_msgid = "label_content",
398            description = "Learning resources that are used in the project. You can write here information about printed resources or copy addresses of web resources and LeMill content.",
399            description_msgid = "help_project_content",
400            rows = 6,
401            i18n_domain = "lemill",
402            visible ={'edit':'visible', 'view':'visible'}
403            ),
404    ),
405   LeMillLinksField('methodsLinks',
406        accessor="getMethodsLinks",
407        mutator = "setMethodsLinks",
408        copied_in_translation=True,
409        index=None,
410        widget=LeMillLinksWidget(label = "Methods",
411            label_msgid = "label_methods",
412            description = "Instructional methods that are used in the project. You can copy here web addresses of LeMill methods.",
413            description_msgid = "help_project_methods",
414            rows = 6,
415            i18n_domain = "lemill",
416            visible ={'edit':'visible', 'view':'visible'}
417            ),
418    ),
419   LeMillLinksField('toolsLinks',
420        accessor="getToolsLinks",
421        mutator = "setToolsLinks",
422        copied_in_translation=True,
423        index=None,
424        widget=LeMillLinksWidget(label = "Tools",
425            label_msgid = "label_tools",
426            description = "Tools that are used in the project. You can copy here web addresses of LeMill tools.",
427            description_msgid = "help_project_tools",
428            rows = 6,
429            i18n_domain = "lemill",
430            visible ={'edit':'visible', 'view':'visible'}
431            ),
432    ),
433))
434
435site_address = Schema((
436    StringField('address',
437        default= "http://",
438        index=None,
439        copied_in_translation=True,
440        searchable=True,
441        widget = HTMLLinkWidget(
442            label="Homepage URL",
443            label_msgid="label_homepage_url",
444            i18n_domain="lemill"
445        ),
446    ),
447))
448
449# Base schemas for LeMill archetype definitions
450
451resource_schema = BaseSchema + score + state + lemill_metadata_mods + deletionReason + latest_edit_schema + tags
452
453learning_resource_schema = resource_schema + language_schema + coverImage
454
455material_schema = learning_resource_schema + subject_area_schema + target_group_schema
456
457community_editing_schema = group_sharing + license_schema + author_schema + translation_schema
458
459draft_schema = editing_settings + branching_schema
460
Note: See TracBrowser for help on using the repository browser.