Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install collective.readunread

How to install collective.readunread

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install collective.readunread
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.0b6 Available View build log
1.0b5 Available View build log
1.0b3 Available View build log
Windows (64-bit)
1.0b6 Available View build log
1.0b5 Available View build log
1.0b3 Available View build log
Mac OS X (10.5+)
1.0b6 Available View build log
1.0b5 Available View build log
1.0b3 Available View build log
Linux (32-bit)
1.0b6 Available View build log
1.0b5 Available View build log
1.0b3 Available View build log
Linux (64-bit)
1.0b6 Available View build log
1.0b5 Available View build log
1.0b3 Available View build log
 
Author
License
GPL
Lastest release
version 1.0b6 on Jan 28th, 2012

collective.readunread

Introduction

This package provides read/unread status for Plone objects.

It adds a "readBy" field and a proper index to any object marked with IReadByProvider interface.

How to use it

In order to activate read/unread feature the target object must implement:

collective.readunread.interfaces.IReadByProvider

You can add a ZCML slug in your package like:

<five:implements
  class="Products.ATContentTypes.content.document.ATDocument"
  interface="collective.readunread.interfaces.IReadByProvider"
  />

How it works

For testing purpose we'll assign it to the Document content type

>>> from zope import interface
>>> from Products.ATContentTypes.content.document import ATDocument
>>> from collective.readunread.interfaces import IReadByProvider
>>> interface.classImplements(ATDocument,IReadByProvider)

and create a Document

>>> self.setRoles(('Manager',))
>>> docid = self.folder.invokeFactory('Document', 'document')
>>> doc = self.folder[docid]

We must trigger IObjectInitializedEvent on it since we have a subcriber that will take care of pushing the userid of the creator into 'readBy' field

>>> from Products.Archetypes.event import ObjectInitializedEvent
>>> from zope.event import notify
>>> notify(ObjectInitializedEvent(doc))

We can use the manager adapter for handling readby status

>>> from collective.readunread.interfaces import IReadByManager
>>> manager = IReadByManager(doc)

Since the doc is new we should get only creator's ID

>>> len(manager.get_readby()) == 1
True
>>> manager.get_readby()
('test_user_1_',)

Let's read the doc as other users. The following will create 3 new users

>>> from collective.readunread.tests.tests import setupMembers
>>> setupMembers(self.portal, n=3)

We have two ways for setting the doc as 'read' by a user. First, we can trigger the PostValidationHook event with the user (that simulates viewing the doc)

>>> from collective.readunread.tests.tests import fireViewEvent
>>> fireViewEvent(doc,'user1')
>>> fireViewEvent(doc,'user2')

Let's see who read the doc

>>> 'user1' in manager.get_readby()
True
>>> 'user2' in manager.get_readby()
True
>>> 'user3' in manager.get_readby()
False

The second way is to set it trough the manager

>>> manager.set_readby(['user3',])
>>> 'user3' in manager.get_readby()
True

We can check the status of a user

>>> manager.get_status('user3')
'read'

We can also set a user as unread

>>> manager.set_unreadby(['user3',])
>>> 'user3' not in manager.get_readby()
True
>>> manager.get_status('user3')
'unread'

TODO

  • document & test buttons macro
  • document & test helper views

Changelog

1.0b6
  • fix missing import browser package
1.0b5
  • update docs
  • added doctest for manager
  • fixed adapter
  • improved utils
1.0b4
  • fix profile name
  • add .gitignore
1.0b3
  • missing HISTORY update (experimenting w/ jarn.mkrelease)
1.0b2
  • updated docs
1.0b1dev (unreleased)
  • Initial release

Credits

Developed with the support of International Traning Center of the ILO.

ITCILO - Logo

Authors

This product was developed by Domsense.

Domsense Website

Subscribe to package updates

Last updated Jan 28th, 2012

Download Stats

Last month:3

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.