Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Changelog
- Updated resources from proto and applied a number of markup fixes in a review session with Daniel
[pilz]

- Support feedback page after answering a risk
(`#2857 <https://github.com/syslabcom/scrum/issues/2857>`_)
[reinhardt]


16.2.7 (2025-01-15)
-------------------
Expand Down
7 changes: 7 additions & 0 deletions src/euphorie/client/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,13 @@
permission="euphorie.client.ViewSurvey"
layer="euphorie.client.interfaces.IClientSkinLayer"
/>
<browser:page
name="identification_feedback"
for="euphorie.client.model.Risk"
class=".risk.IdentificationFeedbackView"
permission="euphorie.client.ViewSurvey"
layer="euphorie.client.interfaces.IClientSkinLayer"
/>

<browser:page
name="actionplan"
Expand Down
133 changes: 76 additions & 57 deletions src/euphorie/client/browser/risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,61 @@ def action_plan_condition(self):
return None
return condition

def save_data(self, reply):
old_values = {}
for prop, default in self.monitored_properties.items():
val = getattr(self.context, prop, default)
old_values[prop] = val

self.set_answer_data(reply)

session = Session()
changed = self.set_measure_data(reply, session)

if reply.get("answer", None):
# If answer is not present in the request, do not attempt to set
# any action-related data, since the request might have come
# from a sub-form.
if self.webhelpers.integrated_action_plan:
new_plans, changes = self.extract_plans_from_request()
for plan in (
self.context.standard_measures + self.context.custom_measures
):
session.delete(plan)
self.context.action_plans.extend(new_plans)
changed = changes or changed

# This only happens on custom risks
if reply.get("handle_custom_description"):
self.context.custom_description = self.webhelpers.check_markup(
reply.get("custom_description")
)

if reply.get("title"):
self.context.title = reply.get("title")

if not changed:
for prop, default in self.monitored_properties.items():
val = getattr(self.context, prop, None)
if val and val != old_values[prop]:
changed = True
break
if changed:
self.session.touch()

def post(self):
reply = self.request.form
if not self.webhelpers.can_edit_session:
return self.proceed_to_next(reply)
_next = self._get_next(reply)
# Don't persist anything if the user skipped the question
if _next == "skip":
return self.proceed_to_next(reply)

self.save_data(reply)

return self.proceed_to_next(reply)

def __call__(self):
# Render the page only if the user has inspection rights,
# otherwise redirect to the start page of the session.
Expand All @@ -523,64 +578,15 @@ def __call__(self):
self.set_parameter_values()

if self.request.method == "POST":
reply = self.request.form
if not self.webhelpers.can_edit_session:
return self.proceed_to_next(reply)
_next = self._get_next(reply)
# Don't persist anything if the user skipped the question
if _next == "skip":
return self.proceed_to_next(reply)
old_values = {}
for prop, default in self.monitored_properties.items():
val = getattr(self.context, prop, default)
old_values[prop] = val

self.set_answer_data(reply)

session = Session()
changed = self.set_measure_data(reply, session)
return self.post()

if reply.get("answer", None):
# If answer is not present in the request, do not attempt to set
# any action-related data, since the request might have come
# from a sub-form.
if self.webhelpers.integrated_action_plan:
new_plans, changes = self.extract_plans_from_request()
for plan in (
self.context.standard_measures + self.context.custom_measures
):
session.delete(plan)
self.context.action_plans.extend(new_plans)
changed = changes or changed

# This only happens on custom risks
if reply.get("handle_custom_description"):
self.context.custom_description = self.webhelpers.check_markup(
reply.get("custom_description")
)

if reply.get("title"):
self.context.title = reply.get("title")

if not changed:
for prop, default in self.monitored_properties.items():
val = getattr(self.context, prop, None)
if val and val != old_values[prop]:
changed = True
break
if changed:
self.session.touch()

return self.proceed_to_next(reply)

else:
self._prepare_risk()
if self.is_custom_risk:
next = FindNextQuestion(
self.context, self.context.session, filter=self.question_filter
)
self.has_next_risk = next or False
return self.template()
self._prepare_risk()
if self.is_custom_risk:
next = FindNextQuestion(
self.context, self.context.session, filter=self.question_filter
)
self.has_next_risk = next or False
return self.template()

@property
def template(self):
Expand Down Expand Up @@ -1003,6 +1009,11 @@ def proceed_to_next(self, reply):
session_url=self.webhelpers.traversed_session.absolute_url()
)
return self.request.response.redirect(url)

elif _next == "next" and getattr(self.risk, "feedback_text", None):
url = self.context.absolute_url() + "/@@identification_feedback"
return self.request.response.redirect(url)

elif _next in ("next", "skip"):
target = self.next_question
if target is None:
Expand Down Expand Up @@ -1113,6 +1124,14 @@ def calculatePriority(self, risk, reply):
return self.context.priority


class IdentificationFeedbackView(IdentificationView):
default_template = ViewPageTemplateFile("templates/risk_identification_feedback.pt")

def post(self):
reply = self.request.form
return self.proceed_to_next(reply)


class ImageUpload(BrowserView):
def redirect(self):
return self.request.response.redirect(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
xmlns:meta="http://xml.zope.org/namespaces/meta"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:tal="http://xml.zope.org/namespaces/tal"
meta:interpolation="true"
metal:use-macro="context/@@shell/macros/shell"
tal:define="
client nocall:request/client;
webhelpers nocall:context/@@webhelpers;
"
i18n:domain="euphorie"
>

<body>
<metal:slot fill-slot="content"
tal:define="
risk nocall:view/risk;
"
>
<tal:block replace="tile:statusmessages" />
<form class="pat-form pat-inject panel-style"
accept-charset="UTF-8"
action="${here/absolute_url}/@@${view/__name__}"
enctype="multipart/form-data"
method="post"
data-pat-inject="history: record; source: #step-2-topics; target: #step-2-topics &amp;&amp; source: #main-content; target: #main-content &amp;&amp; source: #toolbar; target: #toolbar &amp;&amp; source: #status; target: #status"
>
<a class="pat-scroll pat-scroll-animated"
hidden
href="#content-pane"
data-pat-scroll="selector: #content-pane; trigger: auto; offset: 0"
>Scroll to top</a>

<div class="pat-scroll-box"
id="content-pane"
>
<article class="rich"
tal:content="structure:risk/feedback_text|nothing"
></article>
</div>

<p class="button-bar pat-bumper"
id="nav-bar"
>
<button class="pat-button continue"
name="next"
type="submit"
value="skip"
i18n:translate="label_continue"
>Continue</button>
</p>
</form>
</metal:slot>
</body>
</html>
6 changes: 6 additions & 0 deletions src/euphorie/content/risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ class IRisk(model.Schema, IRichDescription, IBasic):
default="low",
)

feedback_text = HtmlText(
title=_("label_feedback_text", default="Feedback after answer"),
required=False,
)
directives.widget(feedback_text="plone.app.z3cform.wysiwyg.WysiwygFieldWidget")

model.fieldset(
"main_image",
label=_("header_main_image", default="Main image"),
Expand Down