[Zope] zope product problem
Dominique Lederer
lederer at dmc01.at
Wed May 5 09:40:41 EDT 2004
that's also not the solution, but thanks anyway.
i will post the whole source, maybe you can find the problem.
On Wed, 5 May 2004 08:30:43 -0500, <zope at netchan.cotse.net> wrote:
> You have to change the attribute names in the __init__ method, not in
> the _properties construct:
>
> def __init__(self, id, question, responses):
> self.id=id
> self.question = question
> self.responses = responses
from AccessControl import ClassSecurityInfo
from Globals import InitializeClass
from OFS.SimpleItem import SimpleItem
from OFS.PropertyManager import PropertyManager
def manage_addPoll_form(self):
"""
Returns an HTML form.
"""
return """<html>
<head><title>Add Poll</title></head>
<body>
<form action="manage_addPoll_function">
id <input type="type" name="id"><br>
question <input type="type" name="question"><br>
responses (one per line)
<textarea name="responses:lines"></textarea>
<input type="submit">
</form>
</body>
</html>"""
def manage_addPoll_function(self,id,question,responses,REQUEST=None):
"""
Create a new poll and add it to myself
"""
self._setObject(id, PollProduct(id, question, responses))
if REQUEST is not None:
return self.manage_main(self, REQUEST)
class PollProduct(SimpleItem, PropertyManager):
"""
Poll product class, implements Poll interface.
The poll has a question and a sequence of responses. Votes
are stored in a dictionary which maps response indexes to a
number of votes.
"""
meta_type='Poll'
security=ClassSecurityInfo()
manage_options=(
#{'label' : 'Edit', 'action' : 'manage_propertiesForm'},
) + SimpleItem.manage_options + PropertyManager.manage_options
_properties=(
#{'id':'id','type':'string','mode':'r'},
#{'id':'title','type':'string','mode':'w'},
{'id':'question','type':'string','mode':'w'},
{'id':'responses','type':'lines','mode':'w'},
)
def __init__(self, id, question, responses):
self.id=id
self.question = question
self.responses = responses
self.votes = {}
for i in range(len(responses)):
self.votes[i] = 0
security.declareProtected('Use Poll', 'castVote')
def castVote(self, index):
"Votes for a choice"
self.votes[index] = self.votes[index] + 1
self.votes = self.votes
security.declareProtected('View Poll Results', 'getTotalVotes')
def getTotalVotes(self):
"Returns total number of votes cast"
total = 0
for v in self.votes.values():
total = total + v
return total
security.declareProtected('View Poll Results', 'getVotesFor')
def getVotesFor(self, index):
"Returns number of votes cast for a given response"
return self.votes[index]
security.declarePublic('getResponses')
def getResponses(self):
"Returns the sequence of responses"
return tuple(self.responses)
security.declarePublic('getQuestion')
def getQuestion(self):
"Returns the question"
return self.question
InitializeClass(PollProduct)
More information about the Zope
mailing list