source: trunk/LeMillReference.py @ 1986

Revision 1833, 5.9 KB checked in by jukka, 12 years ago (diff)

Closed #1423, spent 5h. Adds field 'score' to every resource type. If you have lemill.net's Data.fs it is better to do archetype's update schema on resource type at a time. Didn't work for me if tried to do all at once. After archetype update it is better to reindex catalog and restart zope, as it has probably reserved huge amounts of memory.

  • Property svn:keywords set to Id Revision
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-1
18
19from AccessControl import ClassSecurityInfo
20from Products.Archetypes.public import *
21from Products.CMFCore.utils import getToolByName
22
23from SharedMetadata import *
24from FieldsWidgets import TwoColumnMultiSelectionWidget, HTMLLinkWidget
25from config import PROJECTNAME, MODIFY_CONTENT, VIEW
26from Material import Material
27
28no_coverImage = Schema((
29    ComputedField('coverImage',
30        accessor = 'getCoverImage',
31        expression = 'False',
32        widget = ComputedWidget(
33            visible = {'edit': 'invisible', 'view':'invisible'},
34        ),
35    ),
36    ComputedField('hasCoverImage',
37        default=False,
38        accessor='getHasCoverImage',
39        expression = 'False',
40        widget = ComputedWidget(
41            visible = {'edit': 'invisible', 'view':'invisible'},
42        ),
43    ),
44))
45
46lrt = Schema((
47    LinesField('learningResourceType',
48        vocabulary = DisplayList((
49            ("assessment", "Assessment"),
50            ("broadcast", "Broadcast"),
51            ("course", "Course"),
52            ("drill", "Drill and practice"),
53            ("educational game", "Educational game"),
54            ("demonstration", "Demonstration"),
55            ("experiment", "Experiment"),
56            ("exploration", "Exploration"),
57            ("glossary", "Glossary"),
58            ("guide", "Guide"),
59            #("learning asset", "Learning asset"),
60            ("lesson plan", "Lesson plan"),
61            ("open activity", "Open activity"),
62            ("reference", "Reference"),
63            ("simulation", "Simulation"),
64            ("tool", "Tool"),
65            ("weblog", "Weblog"),
66            ("website", "Web Site"),
67            ("wiki", "Wiki"),
68            )),
69       index = "KeywordIndex:schema",
70        multivalued=True,
71        widget=TwoColumnMultiSelectionWidget(
72            format="checkbox",
73            label="Learning resource type",
74            label_msgid="label_learning_resource_type",
75            description="Choose suitable resource type categories",
76            description_msgid="desc_learning_resource_type",
77            i18n_domain="lemill",
78        ),
79    ),
80))
81
82location = Schema((
83    TextField('location',
84        default = 'http://',
85        accessor = 'getTechnicalLocation',
86        required = True,
87        widget = HTMLLinkWidget(
88            label="Location",
89            label_msgid='label_location_url',
90            description='URL to the resource.',
91            description_msgid='description_location_url',
92            i18n_domain="lemill",
93        ),
94    ),
95))
96
97author = Schema((
98    TextField('author',
99        widget = StringWidget(
100            label = 'Author',
101            label_msgid = 'label_author',
102            description = 'Author of this resource',
103            description_msgid = 'description_author',
104            i18n_domain = 'lemill',
105        ),
106    ),
107))
108
109LICENSE_TYPES = (
110    ('None', 'None - All Rights Reserved',),
111    ('CCAL', 'Creative Commons Attribution License',),
112    ('CCAND', 'Creative Commons Attribution-NoDerivs',),
113    ('CCANCND', 'Creative Commons Attribution-NonCommercial-NoDerivs',),
114    ('CCANC', 'Creative Commons Attribution-NonCommercial',),
115    ('CCANCSA', 'Creative Commons Attribution-NonCommercial-ShareAlike',),
116    ('CCAS', 'Creative Commons Attribution-ShareAlike',),
117    ('GNUFDL', 'GNU Free Documentation License',),
118    ('PD', 'Public Domain',),
119)
120licenses = Schema((
121    TextField('license',
122        vocabulary = DisplayList((LICENSE_TYPES)),
123        widget = SelectionWidget(
124            label = 'License',
125            label_msgid = 'label_license',
126            description = 'Choose appropriate license',
127            description_msgid = 'description_license',
128            i18n_domain = 'lemill',
129        ),
130    ),
131))
132
133# removed target_group_schema and lrt for LeMill 1.1. They're still up there if needed.
134schema = BaseSchema + author + language_schema + location + tags + bodytext + coverImage + subject_area_schema + target_group_schema + licenses + latest_edit_schema + deletionReason + score
135
136schema = schema.copy()
137# These widgets should be hidden
138toBeHidden = ['bodyText', 'allowDiscussion', 'contributors', 'creators', 'rights', 'subject']
139for x in schema.keys():
140    schema[x].schemata = 'default'
141    schema[x].isMetadata = False
142    if x in toBeHidden:
143        schema[x].widget.visible = {'view': 'invisible', 'edit':'invisible'}
144    if x == 'description':
145        schema[x].widget.visible = {'view': 'visible', 'edit':'visible'}
146schema.moveField('location', pos='top')
147schema.moveField('author', after='title')
148schema.moveField('description', after='author')
149schema.moveField('tags', after='description')
150
151class LeMillReference(Material):
152    """ Reference to external resource """
153
154    schema = schema
155   
156    meta_type = 'LeMillReference'
157    archetype_name = 'LeMillReference'
158
159    security = ClassSecurityInfo()
160    security.declareObjectPublic()
161
162    aliases = {
163        '(Default)' : 'base_view',
164        'view'      : 'base_view',
165        'edit'      : 'base_edit'
166    }
167
168    def amIMaterial(self):
169        """ references are not proper material"""
170        return False
171
172    def manage_afterAdd(self, item, container):
173        Material.manage_afterAdd(self, item, container)
174
175registerType(LeMillReference, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.