Volto Voting Behavior Question

I am in the process of modeling a voting behavior for my addon in Volto using the example in chapter 47 for the Plone 6 training. However, I am unable to display the component correctly.

It does display feedback in the traceback error in Plone classic as displayed below:

2021-07-07 09:47:46,064 INFO    [plone.protect:289][waitress-0]   File "/usr/local/Cellar/python@3.7/3.7.10_3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 890, in _bootstrap
    self._bootstrap_inner()

  File "/usr/local/Cellar/python@3.7/3.7.10_3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()

  File "/usr/local/Cellar/python@3.7/3.7.10_3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/waitress-1.4.4-py3.7.egg/waitress/task.py", line 86, in handler_thread
    task.service()

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/waitress-1.4.4-py3.7.egg/waitress/channel.py", line 350, in service
    task.service()

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/waitress-1.4.4-py3.7.egg/waitress/task.py", line 171, in service
    self.execute()

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/waitress-1.4.4-py3.7.egg/waitress/task.py", line 441, in execute
    app_iter = self.channel.server.application(environ, start_response)

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/Paste-3.5.0-py3.7.egg/paste/translogger.py", line 69, in __call__
    return self.application(environ, replacement_start_response)

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/Zope-4.5.5-py3.7.egg/ZPublisher/httpexceptions.py", line 30, in __call__
    return self.application(environ, start_response)

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/Zope-4.5.5-py3.7.egg/ZPublisher/WSGIPublisher.py", line 376, in publish_module
    environ['REMOTE_USER'] = user.getUserName()

  File "/usr/local/Cellar/python@3.7/3.7.10_3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 119, in __exit__
    next(self.gen)

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/Zope-4.5.5-py3.7.egg/ZPublisher/WSGIPublisher.py", line 164, in transaction_pubevents
    notify(pubevents.PubBeforeCommit(request))

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/zope.event-4.5.0-py3.7.egg/zope/event/__init__.py", line 32, in notify
    subscriber(event)

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/zope.component-4.6.2-py3.7.egg/zope/component/event.py", line 27, in dispatch
    component_subscribers(event, None)

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/zope.component-4.6.2-py3.7.egg/zope/component/_api.py", line 134, in subscribers
    return sitemanager.subscribers(objects, interface)

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/zope.interface-5.2.0-py3.7-macosx-10.9-x86_64.egg/zope/interface/registry.py", line 448, in subscribers
    return self.adapters.subscribers(objects, provided)

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/zope.interface-5.2.0-py3.7-macosx-10.9-x86_64.egg/zope/interface/adapter.py", line 619, in subscribers
    subscription(*objects)

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/plone.transformchain-2.0.2-py3.7.egg/plone/transformchain/zpublisher.py", line 86, in applyTransformOnSuccess
    transformed = applyTransform(event.request)

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/plone.transformchain-2.0.2-py3.7.egg/plone/transformchain/zpublisher.py", line 75, in applyTransform
    transformed = transformer(request, result, encoding)

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/plone.transformchain-2.0.2-py3.7.egg/plone/transformchain/transformer.py", line 59, in __call__
    newResult = handler.transformIterable(result, encoding)

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/plone.protect-4.1.6-py3.7.egg/plone/protect/auto.py", line 191, in transformIterable
    if not self.check():

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/plone.protect-4.1.6-py3.7.egg/plone/protect/auto.py", line 216, in check
    return self._check()

  File "/Users/anonymous/Plone524/backend/buildout-cache/eggs/cp37m/plone.protect-4.1.6-py3.7.egg/plone/protect/auto.py", line 288, in _check
    '\n'.join(traceback.format_stack()),

aborting transaction due to no CSRF protection on url http://localhost:3000/applicationform-2021-07-06-7962447364/recommendations-2021-07-06-0973417419/GET_application_json_
2021-07-07 10:00:00,241 ERROR   [Zope.SiteErrorLog:252][waitress-3] 1625666400.22654580.20582747520761824 http://localhost:3000/applicationform-2021-07-06-7962447364/recommendations-2021-07-06-0973417419/@votes
Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 162, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 371, in publish_module
  Module ZPublisher.WSGIPublisher, line 274, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 63, in call_object
  Module plone.rest.service, line 22, in __call__
  Module plone.restapi.services, line 20, in render
  Module yc.graduateapplication.restapi.voting, line 24, in reply
  Module yc.graduateapplication.behavior.voting, line 61, in vote
KeyError: 'You may not vote twice'
2021-07-07 10:02:15,421 ERROR   [Zope.SiteErrorLog:252][waitress-1] 1625666535.4213960.1312119072562815 http://localhost:3000/applicationform-2021-07-06-7962447364/recommendations-2021-07-06-0973417419/@votes
Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 162, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 371, in publish_module
  Module ZPublisher.WSGIPublisher, line 274, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 63, in call_object
  Module plone.rest.service, line 22, in __call__
  Module plone.restapi.services, line 20, in render
  Module yc.graduateapplication.restapi.voting, line 24, in reply
  Module yc.graduateapplication.behavior.voting, line 61, in vote
KeyError: 'You may not vote twice'

Is there an example as to how the full Voting Behavior is to be coded? I have followed the instructions as displayed in the tutorial for Plone 6, but I am still unclear as to how the final finished product is supposed to look like.

I thank you kindly.

Sincerely,

rbrown12

Well, yes, the endpoint code starzel.votable_behavior/voting.py at beecb8873acc5b27849c39260924ad44ac081978 · collective/starzel.votable_behavior · GitHub should handle the case already_voted. Will correct this.

The training code is working OK as the frontend does offer voting only if the user has not already voted for this object. volto-ploneconf/Voting.jsx at b288fb8498400279a4556b96e1392c22481f3349 · collective/volto-ploneconf · GitHub

Your question about the overall picture: With starzel.votable_behavior and volto-ploneconf you have all code.

1 Like