Skip to content

Commit

Permalink
reset
Browse files Browse the repository at this point in the history
  • Loading branch information
mamico committed Nov 11, 2024
1 parent e3caa05 commit f6b44ce
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/collective/formsupport/counter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"""Init and utils."""
from zope.i18nmessageid import MessageFactory

import logging


_ = MessageFactory("collective.formsupport.counter")
logger = logging.getLogger(__name__)
6 changes: 6 additions & 0 deletions src/collective/formsupport/counter/adapters/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collective.formsupport.counter.config import COUNTER_ENABLED_FORM_FLAG_NAME
from collective.formsupport.counter.interfaces import ICollectiveFormsupportCounterLayer
from collective.volto.formsupport.interfaces import IDataAdapter
from fromcollective.formsupport.counter import logger
from zope.annotation.interfaces import IAnnotations
from zope.component import adapter
from zope.interface import implementer
Expand All @@ -17,6 +18,11 @@ def __init__(self, context, request):
self.request = request

def get_block(self, block_id):
if not block_id:
logger.warning(
"missing block_id for %s get the first formsupport block",
self.context.absolute_url(),
)
blocks = getattr(self.context, "blocks", {})
if not blocks:
return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
from collective.formsupport import logger
from collective.formsupport.counter.config import COUNTER_ANNOTATIONS_NAME
from plone.restapi.services import Service
from zException import NotFound
from zope.annotation.interfaces import IAnnotations


class CounterReset(Service):
def get_block_id(self, block_id):
if not block_id:
logger.warning(
"missing block_id for %s get the first formsupport block",
self.context.absolute_url(),
)
blocks = getattr(self.context, "blocks", {})
if not blocks:
return
for id, block in blocks.items():
if block.get("@type", "") == "form":
if not block_id or block_id == id:
return id

def reply(self):
form_id = self.request.get("form_id")
block_id = self.get_block_id(self.request.get("block_id"))
if not block_id:
raise NotFound(self.context, "", self.request)
annotations = IAnnotations(self.context)
counter_object = annotations.setdefault(COUNTER_ANNOTATIONS_NAME, {})

counter_object[form_id] = 0

counter_object[block_id] = 0
self.request.response.setStatus(204)

0 comments on commit f6b44ce

Please sign in to comment.