root/trunk/LeMillReference.py

Revision 2998, 5.5 kB (checked in by jukka, 8 months ago)

Fixed #1958, made References to be proper materials and also changed branching to be an ability that materials don't have unless explicitly added.

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