source: trunk/ExerciseMaterial.py @ 2018

Revision 2018, 3.5 KB checked in by jukka, 13 years ago (diff)

Exercise...

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, getSecurityManager
20from Products.Archetypes.public import *
21from Products.CMFCore.utils import getToolByName
22
23from config import PROJECTNAME, MODIFY_CONTENT, VIEW
24from FieldsWidgets import ChapterField, ChapterWidget, StringWidget
25from SharedMetadata import *
26from Material import Material
27from permissions import MODIFY_CONTENT
28import re
29
30schema = BaseSchema + Schema((
31   ChapterField('bodyText',
32        accessor="getBodyText",
33        edit_accessor = 'getRawBodyText',
34        mutator = "setBodyText",
35        index='ZCTextIndex:schema',
36        index_method = 'getOnlyText',
37        searchable = True,
38        allowable_content_types = ['text/html',],
39        allow_file_upload = False,
40        default_output_type = 'text/x-html-captioned',
41        default_content_type = 'text/html',
42        default=[('','guidelines'),],
43        widget=ExerciseWidget(label = "Body text",
44            label_msgid = "label_bodytext",
45            i18n_domain = "lemill",
46            ),
47    ),
48))
49
50schema = schema + tags + language_schema + group_sharing + subject_area_schema + target_group_schema + license_schema + coverImage + lemill_metadata_mods + no_description + author_schema + deletionReason + version_schema + translation_schema + ieee_lom_lre_ap + latest_edit_schema + score
51
52schema = schema.copy()
53schema.moveField('rights', pos='bottom')
54schema.moveField('language', after='bodyText')
55schema['title'].required = True
56
57
58class ExerciseMaterial(Material):
59    """Exercise page"""
60
61    schema = schema
62
63    meta_type = "ExerciseMaterial"
64    archetype_name = "ExerciseMaterial"
65
66    security = ClassSecurityInfo()
67    security.declareObjectPublic()
68
69    security.declarePrivate('manage_afterAdd')
70    def manage_afterAdd(self, item, container):
71        Material.manage_afterAdd(self, item, container)
72
73        if not hasattr(item.aq_base, 'left_slots'):
74            self._setProperty('left_slots', ['here/portlet_material_actions/macros/portlet',], 'lines')
75        else:
76            self._updateProperty('left_slots', ['here/portlet_material_actions/macros/portlet',])
77
78    def getOnlyText(self):
79        field=self.getField('bodyText')
80        values = field.get(self)
81        dump= '\n'.join([x[0] for x in values if not x[1]!='piece'])
82        return dump
83
84    def isCorrectAnswer(self, chapter, answer_index):
85        """ given a chapter having a multiple choice question, is this answer in correct answers? """
86        return answer_index < len(chapter[1])
87       
88
89    security.declareProtected(MODIFY_CONTENT,'delChapter')
90    def delChapter(self, REQUEST):
91        """ delete chapter """
92        field = self.getField('bodyText')
93        field.delChapter(self, int(REQUEST.get('delete')))
94        return REQUEST.RESPONSE.redirect(self.absolute_url()+'/edit')
95
96registerType(ExerciseMaterial, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.