1 #######################################################################################
2 # Plinn - http://plinn.org #
3 # Copyright © 2005-2009 Benoît PIN <benoit.pin@ensmp.fr> #
5 # This program is free software; you can redistribute it and/or #
6 # modify it under the terms of the GNU General Public License #
7 # as published by the Free Software Foundation; either version 2 #
8 # of the License, or (at your option) any later version. #
10 # This program 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. #
15 # You should have received a copy of the GNU General Public License #
16 # along with this program; if not, write to the Free Software #
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
18 #######################################################################################
21 $Id: Topic.py 1518 2009-07-01 14:55:37Z pin $
22 $URL: http://svn.cri.ensmp.fr/svn/Plinn/branches/CMF-2.1/Topic.py $
25 from Globals
import InitializeClass
26 from zope
.component
.factory
import Factory
27 from AccessControl
.SecurityInfo
import ClassSecurityInfo
28 from Products
.CMFCore
.permissions
import View
, ListFolderContents
29 from Products
.CMFTopic
.permissions
import AddTopics
, ChangeTopics
30 from Products
.CMFTopic
.Topic
import Topic
as BaseTopic
31 from Products
.CMFDefault
.DublinCore
import DefaultDublinCoreImpl
32 from Products
.CMFCore
.utils
import getToolByName
33 from Folder
import PlinnFolder
34 from types
import ListType
, TupleType
, StringTypes
39 class Topic(BaseTopic
, PlinnFolder
):
40 """ CMF Topic with Dublin core metadata support """
42 security
= ClassSecurityInfo()
44 security
.declareProtected(ChangeTopics
, 'listAvailableFields')
45 def listAvailableFields( self
):
46 """ Return a list of available fields for new criteria.
48 fields
= Set(BaseTopic
.listAvailableFields(self
))
49 utool
= getToolByName(self
, "portal_url")
50 portal
= utool
.getPortalObject()
51 unusedTopicFields
= Set(portal
.getProperty("unused_topic_fields", []))
52 return fields
- unusedTopicFields
54 security
.declareProtected(View
, 'queryCatalog')
55 def queryCatalog(self
, REQUEST
=None, **kw
) :
56 """ Invoke the catalog using our criteria.
57 remove Member Data results
59 kw
.update( self
.buildQuery() )
61 ttool
= getToolByName(self
, 'portal_types')
62 if not kw
.has_key('portal_type') :
63 kw
['portal_type'] = ttool
.objectIds()
65 if type(kw
['portal_type']) == ListType
:
66 try : kw
['portal_type'].remove('Member Data')
68 if type(kw
['portal_type']) == TupleType
:
69 ptypes
= list(kw
['portal_type'])
71 ptypes
.remove('Member Data')
72 kw
['portal_type'] = tuple(ptypes
)
74 elif kw
['portal_type'] == 'Member Data' :
75 kw
['portal_type'] = ttool
.objectIds()
77 portal_catalog
= getToolByName( self
, 'portal_catalog' )
78 return portal_catalog
.searchResults(REQUEST
, **kw
)
81 security
.declareProtected(ChangeTopics
, 'loadSearchQuery')
82 def loadSearchQuery(self
, query
):
83 sort_on
= query
.pop('sort_on')
84 sort_order
= query
.pop('sort_order')
85 ctool
= getToolByName(self
, 'portal_catalog')
86 hasindex
= ctool
._catalog
.indexes
.has_key
88 for k
, v
in query
.items() :
89 if not hasindex(k
) : continue
90 if isinstance(v
, StringTypes
) :
91 self
.addCriterion(k
, 'String Criterion')
92 crit
= self
.getCriterion(k
)
94 elif isinstance(v
, (ListType
, TupleType
)) :
96 self
.addCriterion(k
, 'String Criterion')
97 crit
= self
.getCriterion(k
)
100 self
.addCriterion(k
, 'List Criterion')
101 crit
= self
.getCriterion(k
)
102 crit
.edit(value
=v
, operator
='or')
103 elif isinstance(v
, dict) :
104 self
.addCriterion(k
, v
.pop('critType'))
105 crit
= self
.getCriterion(k
)
108 self
.addCriterion(sort_on
, 'Sort Criterion')
109 sort_crit
= self
.getCriterion(sort_on
)
110 if sort_order
== 'reverse' :
113 sort_crit
.edit(False)
115 security
.declareProtected(ChangeTopics
, 'getCompatibleCriteriaFor')
116 def getCompatibleCriteriaFor(self
, fieldName
) :
117 """ Return a list of criteria which belong to the field """
120 InitializeClass(Topic
)
121 TopicFactory
= Factory(Topic
)
124 def addTopic(dispatcher
, id, title
='', REQUEST
=None):
125 """ Create an empty topic.
130 dest
= dispatcher
.Destination()
131 dest
._setObject
( id, topic
)
133 if REQUEST
is not None:
134 REQUEST
['RESPONSE'].redirect( 'manage_main' )