Python API#
The IPolls utility#
A named utility, collective.polls, to find polls and ask permission questions about them.
from collective.polls.utility import IPolls
from zope.component import getUtility
polls = getUtility(IPolls, name="collective.polls")
Method |
Returns |
|---|---|
|
Catalog brains of the newest polls, below |
|
The poll with that UID, or the latest open poll below |
|
Whether the current user voted. Anonymous users are recognized by their cookie, so they need the request. |
|
Whether the current user holds |
|
Whether the current user holds |
|
|
|
A new random id for an anonymous vote. |
The IPollVotes adapter#
Adapt a poll to read or change its votes. Reading never writes to the database.
from collective.polls.interfaces import IPollVotes
votes = IPollVotes(poll)
votes.counts() # {0: 2, 1: 1}
Method |
Description |
|---|---|
|
Votes per option id, for every current option, zero included. |
|
Votes recorded for option ids the poll no longer has. |
|
Number of votes for the current options. |
|
Ids of everyone who voted, sorted. Anonymous voters are |
|
Whether a voter id already voted. |
|
Number of people who voted. |
|
Records one voter's vote, for one option id or a list of them. Raises |
|
Removes the votes of the current options, and every voter. |
|
Every vote recorded, for current and removed options, without zeros. |
|
Drops every vote and stores these ones, without validating them. |
|
Adds votes in bulk to what is stored, without validating them. |
register checks only the ids and the voter.
To vote as the current user, with the permission checks and the anonymous cookie, call Poll.setVote instead.
The Poll class#
Member |
Description |
|---|---|
|
The options, as |
|
|
|
Votes as the current user, for one option id or a list of them. Returns |
|
Same as |
|
Whether a voter can pick more than one option. |
|
Votes so far: one per voter. |
Exceptions#
Exception |
Module |
Raised |
|---|---|---|
|
|
For a second vote by the same voter. A subclass of |