Skip to content

Commit

Permalink
Update votable.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ksuess committed Aug 18, 2023
1 parent c430ec9 commit 7366f68
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/training/votable/behaviors/votable.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# -*- coding: utf-8 -*-

from hashlib import md5

from persistent.dict import PersistentDict
from persistent.list import PersistentList
from plone import api, schema
from plone.autoform import directives as form
from plone.autoform.interfaces import IFormFieldProvider
from plone.supermodel import directives, model
from Products.CMFPlone.utils import safe_bytes
from zope.annotation.interfaces import IAnnotations
from zope.component import adapter
from zope.interface import Interface, implementer, provider
Expand Down Expand Up @@ -62,29 +59,28 @@ class IVotable(model.Schema):

def vote(request):
"""
Store the vote information, store the request hash to ensure
that the user does not vote twice
Store the vote information and store the user(name)
to ensure that the user does not vote twice.
"""

def average_vote():
"""
Return the average voting for an item
Return the average voting for an item.
"""

def has_votes():
"""
Return whether anybody ever voted for this item
Return whether anybody ever voted for this item.
"""

def already_voted(request):
"""
Return the information wether a person already voted.
This is not very high level and can be tricked out easily
"""

def clear():
"""
Clear the votes. Should only be called by admins
Clear the votes. Should only be called by admins.
"""


Expand All @@ -103,26 +99,30 @@ def __init__(self, context):
)
self.annotations = annotations[KEY]

# getter
@property
def votes(self):
return self.annotations["votes"]

# @votes.setter
# setter
# def votes(self, value):
# print("votes behaviors. votes", self)
# """We do not define a setter.
# Function 'vote' is the only one that shall set attributes
# of the context object."""
# self.annotations["votes"] = value

# getter
@property
def voted(self):
return self.annotations["voted"]

# @voted.setter
# setter
# def voted(self, value):
# self.annotations["voted"] = value

def vote(self, vote, request):
if self.already_voted(request):
raise KeyError("You may not vote twice")
raise KeyError("You may not vote twice.")
vote = int(vote)
current_user = api.user.get_current()
self.annotations["voted"].append(current_user.id)
Expand Down

0 comments on commit 7366f68

Please sign in to comment.