-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added read_by index. Use ZCatalog > 3.0.
- Loading branch information
Showing
12 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[buildout] | ||
extends = | ||
https://raw.github.com/collective/buildout.plonetest/master/plone-4.3.x.cfg | ||
# https://raw.github.com/collective/buildout.plonetest/master/plone-5.x.cfg | ||
# https://raw.github.com/collective/buildout.plonetest/master/plone-5.0.x.cfg | ||
# https://raw.github.com/collective/buildout.plonetest/master/plone-5.1.x.cfg | ||
buildout.d/development.cfg | ||
buildout.d/versions-plone-4.3.x.cfg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[versions] | ||
Products.ZCatalog = 3.0.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[versions] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[versions] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from collective.readunread.utils import ANNOT_KEY | ||
from plone.indexer import indexer | ||
from Products.CMFCore.interfaces import IContentish | ||
from imio.helpers.content import get_from_annotation | ||
|
||
|
||
@indexer(IContentish) | ||
def read_by_index(obj): | ||
""" Index method escaping acquisition """ | ||
userids = list(get_from_annotation(ANNOT_KEY, obj=obj, default=[])) | ||
# we need to put a default value not empty, because an empty list is not searched with 'not' query | ||
if not userids: | ||
userids = [0] | ||
return userids |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0"?> | ||
<object name="portal_catalog" meta_type="Plone Catalog Tool"> | ||
<index name="read_by" meta_type="KeywordIndex"> | ||
<indexed_attr value="read_by"/> | ||
</index> | ||
<column value="read_by"/> | ||
</object> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Setup tests for this package.""" | ||
from collective.readunread.utils import get_ru_status | ||
from collective.readunread.utils import set_ru_status | ||
from collective.readunread.testing import COLLECTIVE_READUNREAD_INTEGRATION_TESTING # noqa | ||
from plone.app.testing import TEST_USER_ID | ||
|
||
import unittest | ||
|
||
|
||
class TestAdapters(unittest.TestCase): | ||
"""Test collective.readunread adapters.py.""" | ||
|
||
layer = COLLECTIVE_READUNREAD_INTEGRATION_TESTING | ||
|
||
def setUp(self): | ||
"""Custom shared utility setup for tests.""" | ||
self.portal = self.layer['portal'] | ||
self.tt1 = self.portal['tt1'] | ||
self.pc = self.portal.portal_catalog | ||
|
||
def test_read_by_index(self): | ||
# test catalog search, also with 'not' query to find 'unread' items | ||
self.assertEqual(get_ru_status(self.tt1), 'unread') | ||
self.assertEqual(len(self.pc(portal_type='testtype', read_by=0)), 1) | ||
self.assertEqual(len(self.pc(portal_type='testtype', read_by=TEST_USER_ID)), 0) | ||
self.assertEqual(len(self.pc(portal_type='testtype', read_by={'not': TEST_USER_ID})), 1) | ||
# change read status for current user id | ||
set_ru_status(self.tt1, status='read') | ||
self.assertEqual(len(self.pc(portal_type='testtype', read_by=0)), 0) | ||
self.assertEqual(len(self.pc(read_by=TEST_USER_ID)), 1) | ||
self.assertEqual(len(self.pc(portal_type='testtype', read_by={'not': TEST_USER_ID})), 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters