source: trunk/MultimediaMaterial.py @ 3002

Revision 3002, 4.0 KB checked in by jukka, 10 years ago (diff)

Removed two very useless metadata indexes, fixed one bug from yesterdays history cleanup.

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
25from Schemata import no_description, material_schema, community_editing_schema, draft_schema
26from Material import Material
27from Branchable import Branchable
28from permissions import MODIFY_CONTENT
29import re
30
31multimediamaterial_schema = Schema((
32   ChapterField('bodyText',
33        accessor="getBodyText",
34        edit_accessor = 'getRawBodyText',
35        mutator = "setBodyText",
36        index='ZCTextIndex',
37        index_method = 'getOnlyText',
38        copied_in_translation=True,
39        searchable = True,
40        allowable_content_types = ['text/html',],
41        allow_file_upload = False,
42        default_output_type = 'text/x-html-captioned',
43        default_content_type = 'text/html',
44        default=[('','text_block'),],
45        widget=ChapterWidget(label = "Body text",
46            label_msgid = "label_bodytext",
47            i18n_domain = "lemill",
48            ),
49    ),
50))
51
52schema = material_schema + community_editing_schema + no_description + draft_schema + multimediamaterial_schema
53
54schema = schema.copy()
55schema.moveField('rights', pos='bottom')
56schema.moveField('language', after='bodyText')
57schema['title'].required = True
58schema.moveField('hideDrafts', before='rights')
59schema.moveField('editingMode', before='hideDrafts')
60
61
62class MultimediaMaterial(Branchable, Material):
63    """Web page"""
64
65    schema = schema
66
67    meta_type = "MultimediaMaterial"
68    archetype_name = "MultimediaMaterial"
69    default_location = 'content/webpages'
70    portlet = 'here/portlet_material_actions/macros/portlet'
71    security = ClassSecurityInfo()
72    security.declareObjectPublic()
73
74    security.declarePrivate('manage_afterAdd')
75    def manage_afterAdd(self, item, container):
76        Material.manage_afterAdd(self, item, container)
77
78    def getOnlyText(self):
79        field=self.getField('bodyText')
80        values = field.get(self)
81        if not values:
82            return ''
83        if type(values[0])==tuple:
84            dump= '\n'.join([x[0] for x in values if x[1]=='text_block'])
85        else:
86            dump= '\n'.join([x for x in values])
87        return dump
88
89    def getOnlyRawText(self):
90        field=self.getField('bodyText')
91        values = field.getRaw(self)
92        if values:
93            return '\n'.join([x[0] for x in values if x[1]=='text_block'])
94        return ''
95
96    security.declareProtected(MODIFY_CONTENT,'delChapter')
97    def delChapter(self, REQUEST):
98        """ delete chapter """
99        field = self.getField('bodyText')
100        field.delChapter(self, int(REQUEST.get('delete')))
101        return REQUEST.RESPONSE.redirect(self.absolute_url()+'/edit')
102
103    ############ Clean content view #########################
104    def clean_view(self):
105        """ This will return clean content html """
106        page = self.base_view()
107        data_pattern = re.compile('(<h1>.*?)<div class="visualNoPrint">', re.DOTALL | re.IGNORECASE | re.MULTILINE)
108        html = re.search(data_pattern, page)
109        try:
110            html = html.group(1)
111            return html
112        except AttributeError:
113            pass
114        return ''
115
116registerType(MultimediaMaterial, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.