Coverage for src/comments_views/journal/utils.py: 93%
12 statements
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-09 14:49 +0000
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-09 14:49 +0000
1from django.http import HttpRequest
3SESSION_PENDING_COMMENT = "pending_comment"
6def pending_comment_session_key(doi: str) -> str:
7 """
8 Returns the session key for a pending comment.
9 There can be max. one pending comment per session per DOI.
10 """
11 return f"{SESSION_PENDING_COMMENT}_{doi}"
14def add_pending_comment(request: HttpRequest, doi: str, comment: dict):
15 """Stores a comment in the current session."""
16 request.session[pending_comment_session_key(doi)] = comment
19def get_pending_comment(request: HttpRequest, doi: str) -> dict | None:
20 """
21 Retrieves the pending comment associated to the given DOI from the session, if any.
22 """
23 return request.session.get(pending_comment_session_key(doi))
26def delete_pending_comment(request: HttpRequest, doi: str):
27 """Removes the pending comment associated to the given DOI stored in the session."""
28 session_key = pending_comment_session_key(doi)
29 if session_key in request.session: 29 ↛ exitline 29 didn't return from function 'delete_pending_comment' because the condition on line 29 was always true
30 del request.session[session_key]