--- a/src/pyams_catalog.egg-info/SOURCES.txt Wed May 20 12:21:20 2015 +0200
+++ b/src/pyams_catalog.egg-info/SOURCES.txt Wed Jun 17 09:55:43 2015 +0200
@@ -3,11 +3,12 @@
docs/HISTORY.txt
docs/README.txt
src/pyams_catalog/__init__.py
-src/pyams_catalog/configure.zcml
src/pyams_catalog/include.py
src/pyams_catalog/index.py
src/pyams_catalog/nltk.py
+src/pyams_catalog/query.py
src/pyams_catalog/site.py
+src/pyams_catalog/utils.py
src/pyams_catalog.egg-info/PKG-INFO
src/pyams_catalog.egg-info/SOURCES.txt
src/pyams_catalog.egg-info/dependency_links.txt
--- a/src/pyams_catalog/include.py Wed May 20 12:21:20 2015 +0200
+++ b/src/pyams_catalog/include.py Wed Jun 17 09:55:43 2015 +0200
@@ -23,8 +23,5 @@
def include_package(config):
"""Pyramid include"""
- # add translations
- config.add_translation_dirs('pyams_catalog:locales')
-
# load registry components
config.scan()
--- a/src/pyams_catalog/index.py Wed May 20 12:21:20 2015 +0200
+++ b/src/pyams_catalog/index.py Wed Jun 17 09:55:43 2015 +0200
@@ -14,8 +14,10 @@
# import standard library
+from datetime import date, datetime
# import interfaces
+from pyams_catalog.interfaces import NO_RESOLUTION, DATE_RESOLUTION
# import packages
from hypatia.facet import FacetIndex
@@ -52,7 +54,7 @@
if callable(value):
value = value(obj)
- if value is _marker:
+ if (value is None) or (value is _marker):
return default
if isinstance(value, Persistent):
@@ -72,6 +74,37 @@
FieldIndex.__init__(self, discriminator, family)
+def get_resolution(value, resolution):
+ """Set resolution of given date or datetime"""
+ if not value:
+ return value
+ if resolution < NO_RESOLUTION:
+ args = []
+ if isinstance(value, date):
+ resolution = max(resolution, DATE_RESOLUTION)
+ args.extend(value.timetuple()[:resolution+1])
+ if isinstance(value, date):
+ args.extend([0] * (2 - resolution))
+ value = date(*args)
+ else:
+ args.extend([0] * (5 - resolution))
+ args.append(value.tzinfo)
+ value = datetime(*args)
+ return value
+
+
+class DatetimeIndexWithInterface(FieldIndexWithInterface):
+ """Normalized datetime index with interface support"""
+
+ def __init__(self, interface, discriminator, resolution=DATE_RESOLUTION, family=None):
+ FieldIndexWithInterface.__init__(self, interface, discriminator, family)
+ self.resolution = resolution
+
+ def discriminate(self, obj, default):
+ value = super(DatetimeIndexWithInterface, self).discriminate(obj, default)
+ return get_resolution(value, self.resolution)
+
+
class KeywordIndexWithInterface(InterfaceSupportIndexMixin, KeywordIndex):
"""Keyword index with interface support"""
--- a/src/pyams_catalog/interfaces/__init__.py Wed May 20 12:21:20 2015 +0200
+++ b/src/pyams_catalog/interfaces/__init__.py Wed Jun 17 09:55:43 2015 +0200
@@ -18,6 +18,7 @@
# import interfaces
# import packages
+from zope.interface import Interface
NLTK_LANGUAGES = {'da': 'danish',
@@ -35,3 +36,16 @@
'ru': 'russian',
'es': 'spanish',
'sv': 'swedish'}
+
+
+NO_RESOLUTION = 6
+SECOND_RESOLUTION = 5
+MINUTE_RESOLUTION = 4
+HOUR_RESOLUTION = 3
+DATE_RESOLUTION = 2
+MONTH_RESOLUTION = 1
+YEAR_RESOLUTION = 0
+
+
+class INoAutoIndex(Interface):
+ """Marker interface for objects which shouldn't be automatically indexed"""
--- a/src/pyams_catalog/query.py Wed May 20 12:21:20 2015 +0200
+++ b/src/pyams_catalog/query.py Wed Jun 17 09:55:43 2015 +0200
@@ -32,12 +32,13 @@
def __iter__(self):
query = self.query
+ intids = self.intids
if isinstance(query, Query):
query = query.execute()
if isinstance(query, tuple):
query = query[1]
for oid in query:
- yield self.intids.queryObject(oid)
+ yield intids.queryObject(oid)
def or_(source, added):
--- a/src/pyams_catalog/site.py Wed May 20 12:21:20 2015 +0200
+++ b/src/pyams_catalog/site.py Wed Jun 17 09:55:43 2015 +0200
@@ -15,7 +15,7 @@
# import standard library
import logging
-logger = logging.getLogger('PyAMS (utils)')
+logger = logging.getLogger('PyAMS (catalog)')
# import interfaces
from hypatia.interfaces import ICatalog
--- a/src/pyams_catalog/utils.py Wed May 20 12:21:20 2015 +0200
+++ b/src/pyams_catalog/utils.py Wed Jun 17 09:55:43 2015 +0200
@@ -14,6 +14,8 @@
# import standard library
+import logging
+logger = logging.getLogger('PyAMS (catalog)')
# import interfaces
from hypatia.interfaces import ICatalog
@@ -26,6 +28,7 @@
def index_object(obj, catalog, ignore_notyet=False):
"""Index given object into catalog"""
+ logger.debug("Indexing object {0!r}".format(obj))
intids = query_utility(IIntIds)
if intids is not None:
try:
@@ -42,6 +45,7 @@
def reindex_object(obj, catalog):
"""Reindex given object into catalog"""
+ logger.debug("Re-indexing object {0!r}".format(obj))
intids = query_utility(IIntIds)
if intids is not None:
object_id = intids.queryId(obj)
@@ -54,6 +58,7 @@
def unindex_object(obj, catalog):
"""Unindex given object from catalog"""
+ logger.debug("Un-indexing object {0!r}".format(obj))
intids = query_utility(IIntIds)
if intids is not None:
object_id = intids.queryId(obj)