Add a "Catalog" criteria for collections
This commit is contained in:
parent
86ad2536dc
commit
2d8bda45fb
1
setup.py
1
setup.py
|
@ -33,5 +33,4 @@ setup(name='themis.utils',
|
||||||
[z3c.autoinclude.plugin]
|
[z3c.autoinclude.plugin]
|
||||||
target = plone
|
target = plone
|
||||||
""",
|
""",
|
||||||
paster_plugins=["ZopeSkel"],
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,4 +12,6 @@ themis.utils.egg-info/paster_plugins.txt
|
||||||
themis.utils.egg-info/requires.txt
|
themis.utils.egg-info/requires.txt
|
||||||
themis.utils.egg-info/top_level.txt
|
themis.utils.egg-info/top_level.txt
|
||||||
themis/utils/__init__.py
|
themis/utils/__init__.py
|
||||||
|
themis/utils/config.py
|
||||||
|
themis/utils/criteria.py
|
||||||
themis/utils/tests.py
|
themis/utils/tests.py
|
|
@ -1,4 +1,29 @@
|
||||||
# -*- extra stuff goes here -*-
|
from Products.CMFCore.utils import ContentInit
|
||||||
|
from Products.Archetypes.atapi import process_types
|
||||||
|
from Products.Archetypes.atapi import listTypes
|
||||||
|
|
||||||
|
PROJECTNAME = 'themis.utils'
|
||||||
|
|
||||||
|
# poke registration
|
||||||
|
|
||||||
|
from themis.utils import criteria
|
||||||
|
|
||||||
def initialize(context):
|
def initialize(context):
|
||||||
"""Initializer called when used as a Zope 2 product."""
|
# process our custom types
|
||||||
|
|
||||||
|
listOfTypes = listTypes(PROJECTNAME)
|
||||||
|
|
||||||
|
content_types, constructors, ftis = process_types(
|
||||||
|
listOfTypes,
|
||||||
|
PROJECTNAME)
|
||||||
|
|
||||||
|
allTypes = zip(content_types, constructors)
|
||||||
|
for atype, constructor in allTypes:
|
||||||
|
kind = "%s: %s" % (PROJECTNAME, atype.archetype_name)
|
||||||
|
ContentInit(
|
||||||
|
kind,
|
||||||
|
content_types = (atype,),
|
||||||
|
permission = 'themis.utils: Add criteria',
|
||||||
|
extra_constructors = (constructor,),
|
||||||
|
).initialize(context)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
|
try:
|
||||||
|
ZOPE2_VERSION = pkg_resources.get_distribution('Zope2').version
|
||||||
|
except pkg_resources.DistributionNotFound:
|
||||||
|
ZOPE2_VERSION = 0.0
|
||||||
|
|
|
@ -14,6 +14,5 @@
|
||||||
description="Installs the themis.utils package"
|
description="Installs the themis.utils package"
|
||||||
provides="Products.GenericSetup.interfaces.EXTENSION"
|
provides="Products.GenericSetup.interfaces.EXTENSION"
|
||||||
/>
|
/>
|
||||||
<!-- -*- extra stuff goes here -*- -->
|
|
||||||
|
|
||||||
</configure>
|
</configure>
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
from zope.interface import implements
|
||||||
|
from Products.CMFCore.permissions import View
|
||||||
|
from Products.CMFCore.utils import getToolByName
|
||||||
|
from AccessControl import ClassSecurityInfo
|
||||||
|
|
||||||
|
from Products.Archetypes.atapi import Schema
|
||||||
|
from Products.Archetypes.atapi import StringField
|
||||||
|
from Products.Archetypes.atapi import StringWidget
|
||||||
|
from Products.Archetypes.atapi import registerType
|
||||||
|
|
||||||
|
from Products.ATContentTypes.criteria import _criterionRegistry
|
||||||
|
|
||||||
|
from Products.ATContentTypes.criteria import ALL_INDICES
|
||||||
|
from Products.ATContentTypes.permission import ChangeTopics
|
||||||
|
from Products.ATContentTypes.criteria.base import ATBaseCriterion
|
||||||
|
from Products.ATContentTypes.criteria.schemata import ATBaseCriterionSchema
|
||||||
|
from Products.ATContentTypes.interfaces import IATTopicSearchCriterion
|
||||||
|
|
||||||
|
from zope.i18nmessageid import MessageFactory
|
||||||
|
|
||||||
|
from themis.utils import PROJECTNAME
|
||||||
|
|
||||||
|
from themis.utils.config import ZOPE2_VERSION
|
||||||
|
|
||||||
|
_ = MessageFactory('themis.utils')
|
||||||
|
|
||||||
|
CatalogCriterionSchema = ATBaseCriterionSchema + Schema((
|
||||||
|
|
||||||
|
StringField('key',
|
||||||
|
required=1,
|
||||||
|
mode="rw",
|
||||||
|
write_permission=ChangeTopics,
|
||||||
|
accessor="Key",
|
||||||
|
mutator="setKey",
|
||||||
|
default="",
|
||||||
|
widget=StringWidget(
|
||||||
|
label=_(u'label_criteria_key', default=u'Catalog Key'),
|
||||||
|
description=_(u'help_criteria_key', default=u'Catalog Key to match to content')
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
StringField('value',
|
||||||
|
required=1,
|
||||||
|
mode="rw",
|
||||||
|
write_permission=ChangeTopics,
|
||||||
|
accessor="Value",
|
||||||
|
mutator="setValue",
|
||||||
|
default="",
|
||||||
|
widget=StringWidget(
|
||||||
|
label=_(u'label_criteria_value', default=u'Catalog Value'),
|
||||||
|
description=_(u'help_criteria_value', default=u'Catalog Value to match to content')
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
))
|
||||||
|
|
||||||
|
class CatalogCriterion(ATBaseCriterion):
|
||||||
|
if ZOPE2_VERSION >= 2.12:
|
||||||
|
implements(IATTopicSearchCriterion)
|
||||||
|
else:
|
||||||
|
__implements__ = ATBaseCriterion.__implements__ + (IATTopicSearchCriterion, )
|
||||||
|
|
||||||
|
security = ClassSecurityInfo()
|
||||||
|
schema = CatalogCriterionSchema
|
||||||
|
meta_type = 'CatalogCriterion'
|
||||||
|
archetype_name = 'Catalog criterion'
|
||||||
|
shortDesc = 'Catalog property'
|
||||||
|
|
||||||
|
security.declareProtected(View, 'getCriteriaItems')
|
||||||
|
def getCriteriaItems(self):
|
||||||
|
field = self.Field()
|
||||||
|
key_name = self.Key()
|
||||||
|
value_name = self.Value()
|
||||||
|
if value_name == 'True':
|
||||||
|
value_name = True
|
||||||
|
elif value_name == 'False':
|
||||||
|
value_name = False
|
||||||
|
return ((key_name, value_name),)
|
||||||
|
|
||||||
|
|
||||||
|
def register(criterion, indices):
|
||||||
|
if isinstance(indices, basestring):
|
||||||
|
indices = (indices,)
|
||||||
|
indices = tuple(indices)
|
||||||
|
|
||||||
|
if indices == ():
|
||||||
|
indices = ALL_INDICES
|
||||||
|
|
||||||
|
registerType(criterion, PROJECTNAME)
|
||||||
|
|
||||||
|
crit_id = criterion.meta_type
|
||||||
|
_criterionRegistry[crit_id] = criterion
|
||||||
|
_criterionRegistry.portaltypes[criterion.portal_type] = criterion
|
||||||
|
|
||||||
|
_criterionRegistry.criterion2index[crit_id] = indices
|
||||||
|
for index in indices:
|
||||||
|
value = _criterionRegistry.index2criterion.get(index, ())
|
||||||
|
_criterionRegistry.index2criterion[index] = value + (crit_id,)
|
||||||
|
|
||||||
|
register(CatalogCriterion, ALL_INDICES)
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<atcttool xmlns:i18n="http://xml.zope.org/namespaces/i18n">
|
||||||
|
<topic_indexes i18n:domain="collective.membercriterion">
|
||||||
|
<index name="Catalog" description="The catalog bla bla bla"
|
||||||
|
enabled="True" friendlyName="Friendly Catalog"
|
||||||
|
i18n:attributes="description; friendlyName">
|
||||||
|
<criteria>ATSelectionCriterion</criteria>
|
||||||
|
<criteria>ATSimpleStringCriterion</criteria>
|
||||||
|
<criteria>ATListCriterion</criteria>
|
||||||
|
<criteria>CatalogCriterion</criteria>
|
||||||
|
</index>
|
||||||
|
</topic_indexes>
|
||||||
|
</atcttool>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<object name="portal_types" meta_type="Plone Types Tool">
|
||||||
|
<object name="CatalogCriterion" meta_type="Factory-based Type Information"/>
|
||||||
|
</object>
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<object name="CatalogCriterion" meta_type="Factory-based Type Information"
|
||||||
|
i18n:domain="plone" xmlns:i18n="http://xml.zope.org/namespaces/i18n">
|
||||||
|
<property name="title" i18n:translate="">Member Data Criterion</property>
|
||||||
|
<property name="description" i18n:translate="">A catalog criterion</property>
|
||||||
|
<property name="content_icon">document_icon.gif</property>
|
||||||
|
<property name="content_meta_type">CatalogCriterion</property>
|
||||||
|
<property name="product">themis.utils</property>
|
||||||
|
<property name="factory">addCatalogCriterion</property>
|
||||||
|
<property name="immediate_view">base_edit</property>
|
||||||
|
<property name="global_allow">False</property>
|
||||||
|
<property name="filter_content_types">False</property>
|
||||||
|
<property name="allowed_content_types"/>
|
||||||
|
<property name="allow_discussion">False</property>
|
||||||
|
<alias from="edit" to="base_edit"/>
|
||||||
|
<action title="View" action_id="view" category="object" condition_expr=""
|
||||||
|
url_expr="string:${object_url}/base_view" visible="True"
|
||||||
|
i18n:attributes="title">
|
||||||
|
<permission value="View"/>
|
||||||
|
</action>
|
||||||
|
<action title="Edit" action_id="edit" category="object" condition_expr=""
|
||||||
|
url_expr="string:${object_url}/base_edit" visible="True"
|
||||||
|
i18n:attributes="title">
|
||||||
|
<permission value="Modify portal content"/>
|
||||||
|
</action>
|
||||||
|
</object>
|
Reference in New Issue