-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
29 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 20 additions & 4 deletions
24
src/collective/formsupport/counter/restapi/services/reset_counter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |