1 # -*- coding: utf-8 -*-
2 #######################################################################################
3 # Plinn - http://plinn.org #
4 # Copyright © 2005-2009 Benoît PIN <benoit.pin@ensmp.fr> #
6 # This program is free software; you can redistribute it and/or #
7 # modify it under the terms of the GNU General Public License #
8 # as published by the Free Software Foundation; either version 2 #
9 # of the License, or (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program; if not, write to the Free Software #
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
19 #######################################################################################
26 from Globals
import InitializeClass
27 from zope
.component
.factory
import Factory
28 from AccessControl
.SecurityInfo
import ClassSecurityInfo
29 from Products
.CMFCore
.permissions
import View
, ListFolderContents
30 from Products
.CMFTopic
.permissions
import AddTopics
, ChangeTopics
31 from Products
.CMFTopic
.Topic
import Topic
as BaseTopic
32 from Products
.CMFDefault
.DublinCore
import DefaultDublinCoreImpl
33 from Products
.CMFCore
.utils
import getToolByName
34 from Folder
import PlinnFolder
35 from types
import ListType
, TupleType
, StringTypes
40 class Topic(BaseTopic
, PlinnFolder
):
41 """ CMF Topic with Dublin core metadata support """
43 security
= ClassSecurityInfo()
45 security
.declareProtected(ChangeTopics
, 'listAvailableFields')
46 def listAvailableFields( self
):
47 """ Return a list of available fields for new criteria.
49 fields
= Set(BaseTopic
.listAvailableFields(self
))
50 utool
= getToolByName(self
, "portal_url")
51 portal
= utool
.getPortalObject()
52 unusedTopicFields
= Set(portal
.getProperty("unused_topic_fields", []))
53 return fields
- unusedTopicFields
55 security
.declareProtected(View
, 'queryCatalog')
56 def queryCatalog(self
, REQUEST
=None, **kw
) :
57 """ Invoke the catalog using our criteria.
58 remove Member Data results
60 kw
.update( self
.buildQuery() )
62 ttool
= getToolByName(self
, 'portal_types')
63 if not kw
.has_key('portal_type') :
64 kw
['portal_type'] = ttool
.objectIds()
66 if type(kw
['portal_type']) == ListType
:
67 try : kw
['portal_type'].remove('Member Data')
69 if type(kw
['portal_type']) == TupleType
:
70 ptypes
= list(kw
['portal_type'])
72 ptypes
.remove('Member Data')
73 kw
['portal_type'] = tuple(ptypes
)
75 elif kw
['portal_type'] == 'Member Data' :
76 kw
['portal_type'] = ttool
.objectIds()
78 portal_catalog
= getToolByName( self
, 'portal_catalog' )
79 return portal_catalog
.searchResults(REQUEST
, **kw
)
82 security
.declareProtected(ChangeTopics
, 'loadSearchQuery')
83 def loadSearchQuery(self
, query
):
84 sort_on
= query
.pop('sort_on')
85 sort_order
= query
.pop('sort_order')
86 ctool
= getToolByName(self
, 'portal_catalog')
87 hasindex
= ctool
._catalog
.indexes
.has_key
89 for k
, v
in query
.items() :
90 if not hasindex(k
) : continue
91 if isinstance(v
, StringTypes
) :
92 self
.addCriterion(k
, 'String Criterion')
93 crit
= self
.getCriterion(k
)
95 elif isinstance(v
, (ListType
, TupleType
)) :
97 self
.addCriterion(k
, 'String Criterion')
98 crit
= self
.getCriterion(k
)
101 self
.addCriterion(k
, 'List Criterion')
102 crit
= self
.getCriterion(k
)
103 crit
.edit(value
=v
, operator
='or')
104 elif isinstance(v
, dict) :
105 self
.addCriterion(k
, v
.pop('critType'))
106 crit
= self
.getCriterion(k
)
109 self
.addCriterion(sort_on
, 'Sort Criterion')
110 sort_crit
= self
.getCriterion(sort_on
)
111 if sort_order
== 'reverse' :
114 sort_crit
.edit(False)
116 security
.declareProtected(ChangeTopics
, 'getCompatibleCriteriaFor')
117 def getCompatibleCriteriaFor(self
, fieldName
) :
118 """ Return a list of criteria which belong to the field """
121 InitializeClass(Topic
)
122 TopicFactory
= Factory(Topic
)
125 def addTopic(dispatcher
, id, title
='', REQUEST
=None):
126 """ Create an empty topic.
131 dest
= dispatcher
.Destination()
132 dest
._setObject
( id, topic
)
134 if REQUEST
is not None:
135 REQUEST
['RESPONSE'].redirect( 'manage_main' )