source: trunk/PresentationMaterial.py @ 526

Revision 526, 5.3 KB checked in by vahur, 13 years ago (diff)

migrating content to 0.5.1

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 WYSIWYMWidget, WYSIWYMField, ImageSelectorWidget, TagsField, TagsWidget
25from SharedMetadata import coverImage, audioFile, lemill_metadata_mods, no_description, language_schema, license_schema, author_schema, tags, learning_metadata, age_group
26from Material import Material
27from Resources import LearningResource
28from types import ListType
29
30bodyText = Schema((
31   TextField('bodyText',
32        accessor="getBodyText",
33        mutator = "setBodyText",
34        index='ZCTextIndex:schema',
35        searchable = True,
36        widget=TextAreaWidget(label = "About the presentation",
37            label_msgid = "label_presentation_about",
38            description = "Write here general information about the presentation such as the data, event and location.",
39            description_msgid = "help_presentation_about",
40            rows = 3,
41            i18n_domain = "lemill",
42            ),
43    ),
44))
45refsToImages = Schema((
46    ReferenceField('refsToImages',
47        accessor = 'getRefsToSlides',
48        mutator = 'addRefToSlides',
49        relationship = 'displays',
50        multiValued = True,
51        widget = ImageSelectorWidget(
52            label = ' ',
53        ),
54    ),                                     
55))
56
57schema = BaseSchema + tags + bodyText + audioFile + refsToImages + coverImage + lemill_metadata_mods + no_description + language_schema + license_schema + author_schema + learning_metadata + age_group
58
59schema.moveField('rights', pos='bottom')
60schema['effectiveDate'].widget.visible = {'edit':'invisible', 'view':'invisible'}
61schema['expirationDate'].widget.visible = {'edit':'invisible', 'view':'invisible'}
62
63
64class PresentationMaterial(Material):
65    """ Presentation """
66
67    schema = schema
68
69    meta_type = "PresentationMaterial"
70    archetype_name = "PresentationMaterial"
71
72    security = ClassSecurityInfo()
73    security.declareObjectPublic()
74
75    def manage_afterAdd(self, item, container):
76        """ manage after add """
77        Material.manage_afterAdd(self, item, container)
78        if not hasattr(item.aq_base, 'left_slots'):
79            self._setProperty('left_slots', ['here/portlet_material_actions/macros/portlet',], 'lines')
80        else:
81            self._updateProperty('left_slots', ['here/portlet_material_actions/macros/portlet',])
82           
83    def addRefToSlides(self, ref):
84        """ add a reference to slide """
85        if type(ref) == ListType:
86            for x in ref:
87                self.addFieldReferences(x, 'refsToImages')
88        else:
89            self.addFieldReferences(ref, 'refsToImages')
90
91    def getRefsToSlides(self):
92        """ get references to images. accessor method """
93        unsorted = []
94        sorted = []
95        refsim = self.getReferenceImpl()
96        for ref in refsim:
97            orderNr = 1101
98            if hasattr(ref, 'image_order'): orderNr = ref.image_order
99            #XXX: this piece of code should be in migration
100            #if not hasattr(ref, 'image_order'):
101            #    ref.orderNr = orderNr
102            #    orderNr += 9
103            unsorted.append([orderNr, ref.getTargetObject()])
104        unsorted.sort()
105        [ sorted.append(x[1]) for x in unsorted ]
106        return sorted
107
108    def processForm(self, data=1, metadata=0, REQUEST=None, values=None):
109        """ process form. does the normal saving + saves references to images i
110            TODO: upload protection - anything can be uploaded...
111        """
112        BaseObject.processForm(self, data, metadata, REQUEST, values)
113        req = self.REQUEST
114        title = self.Title()
115        ref_tool = getToolByName(self, 'reference_catalog')
116        for i in range(0, 99):
117            pfile = req.get('presentation-file-'+str(i), None)
118            ppiece = req.get('presentation-piece-'+str(i), None)
119            pcaption = req.get('presentation-caption-'+str(i), None)
120            uid = ppiece
121            if pfile:
122                id = self.generateUniqueId('Piece')
123                new_id = self.content.invokeFactory('Piece', id, title=title+'-slide-'+str(i+1))
124                new_piece = getattr(self.content, new_id)
125                uid = new_piece.UID()
126                new_piece.edit(description=pcaption, image=pfile, file=pfile, language='')
127            if uid and str(uid) != '0':
128                obj = ref_tool.lookupObject(uid)
129                obj.edit(description=pcaption)
130                self.addRefToSlides(uid)
131
132registerType(PresentationMaterial, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.