diff --git a/setup.py b/setup.py
index 06589e3..ba81f4b 100644
--- a/setup.py
+++ b/setup.py
@@ -33,5 +33,4 @@ setup(name='themis.utils',
[z3c.autoinclude.plugin]
target = plone
""",
- paster_plugins=["ZopeSkel"],
)
diff --git a/themis.utils.egg-info/SOURCES.txt b/themis.utils.egg-info/SOURCES.txt
index 1aa37ec..574b862 100644
--- a/themis.utils.egg-info/SOURCES.txt
+++ b/themis.utils.egg-info/SOURCES.txt
@@ -12,4 +12,6 @@ themis.utils.egg-info/paster_plugins.txt
themis.utils.egg-info/requires.txt
themis.utils.egg-info/top_level.txt
themis/utils/__init__.py
+themis/utils/config.py
+themis/utils/criteria.py
themis/utils/tests.py
\ No newline at end of file
diff --git a/themis/utils/__init__.py b/themis/utils/__init__.py
index 51e7de6..9e197aa 100644
--- a/themis/utils/__init__.py
+++ b/themis/utils/__init__.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):
- """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)
+
diff --git a/themis/utils/config.py b/themis/utils/config.py
new file mode 100644
index 0000000..dd66d2d
--- /dev/null
+++ b/themis/utils/config.py
@@ -0,0 +1,7 @@
+import pkg_resources
+
+try:
+ ZOPE2_VERSION = pkg_resources.get_distribution('Zope2').version
+except pkg_resources.DistributionNotFound:
+ ZOPE2_VERSION = 0.0
+
diff --git a/themis/utils/configure.zcml b/themis/utils/configure.zcml
index f44fd58..e79dfdf 100644
--- a/themis/utils/configure.zcml
+++ b/themis/utils/configure.zcml
@@ -14,6 +14,5 @@
description="Installs the themis.utils package"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
-
-
+
diff --git a/themis/utils/criteria.py b/themis/utils/criteria.py
new file mode 100644
index 0000000..cd16fbd
--- /dev/null
+++ b/themis/utils/criteria.py
@@ -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)
diff --git a/themis/utils/profiles/default/portal_atct.xml b/themis/utils/profiles/default/portal_atct.xml
new file mode 100644
index 0000000..ba28a09
--- /dev/null
+++ b/themis/utils/profiles/default/portal_atct.xml
@@ -0,0 +1,13 @@
+
+
+
+
+ ATSelectionCriterion
+ ATSimpleStringCriterion
+ ATListCriterion
+ CatalogCriterion
+
+
+
diff --git a/themis/utils/profiles/default/types.xml b/themis/utils/profiles/default/types.xml
new file mode 100644
index 0000000..bd72e31
--- /dev/null
+++ b/themis/utils/profiles/default/types.xml
@@ -0,0 +1,4 @@
+
+
diff --git a/themis/utils/profiles/default/types/CatalogCriterion.xml b/themis/utils/profiles/default/types/CatalogCriterion.xml
new file mode 100644
index 0000000..a059f27
--- /dev/null
+++ b/themis/utils/profiles/default/types/CatalogCriterion.xml
@@ -0,0 +1,26 @@
+
+
+ Member Data Criterion
+ A catalog criterion
+ document_icon.gif
+ CatalogCriterion
+ themis.utils
+ addCatalogCriterion
+ base_edit
+ False
+ False
+
+ False
+
+
+
+
+
+
+
+