Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV download of similar title details. #727

Merged
merged 2 commits into from
May 1, 2024
Merged
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
5 changes: 5 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
16.1.3 (unreleased)
-------------------

- CSV download of similar title details.
Ref: scrum-2198

- Add registry setting `euphorie.notifications__allow_user_settings` to allow users to change their notification settings.
The default is set to `True` to allow users to do changes on their own.
This can be prevented if internal policies require so by changing this setting to `False`.
Expand All @@ -17,10 +20,12 @@ Changelog
- Do not do linkintegrity checks when removing contents
(Fix regression introduced in https://github.com/euphorie/Euphorie/pull/692)
[ale-rt]

- Delete guest account after sessions have been transferred
Ref: scrum-2155



16.1.2 (2024-03-20)
-------------------

Expand Down
8 changes: 8 additions & 0 deletions src/euphorie/content/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,14 @@
layer="plonetheme.nuplone.skin.interfaces.NuPloneSkin"
/>

<browser:page
name="similar-titles-details-csv"
for="*"
class=".similar_titles_details.SimilarTitlesDetailsCSV"
permission="cmf.ManagePortal"
layer="plonetheme.nuplone.skin.interfaces.NuPloneSkin"
/>

<browser:page
name="find-solution-title-duplications"
for="euphorie.content.survey.ISurvey"
Expand Down
42 changes: 42 additions & 0 deletions src/euphorie/content/browser/similar_titles_details.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from euphorie.content import MessageFactory as _
from euphorie.content.surveygroup import ISurveyGroup
from io import StringIO
from plone import api
from plone.memoize.view import memoize
from Products.Five import BrowserView

import csv
import datetime


class SimilarTitlesDetails(BrowserView):
"""A view that shows the risks that have a title similar to the title
Expand Down Expand Up @@ -40,3 +44,41 @@ def solutions_by_risk(self):
api.content.get(path) for path in self.request.form.get("paths", []) or []
]
return {risk: self.get_solutions(risk) for risk in risks}


class SimilarTitlesDetailsCSV(SimilarTitlesDetails):
def write_data(self, data, writer):
"""Write data to CSV writer.
First cell is the risk title (heading).
Starting from the second row, every column is headed by a tool title
and contains one solution per row.
"""
writer.writerow([self.context.Title()])
solutions = [
[self.get_tool_for_brain(risk).Title()]
+ [solution.Description() for solution in solutions]
for risk, solutions in data.items()
]
max_len = max(map(len, solutions))
for idx in range(max_len):
writer.writerow((sub[idx] if len(sub) > idx else "") for sub in solutions)

def __call__(self):
buffer = StringIO()
writer = csv.writer(buffer)

self.write_data(self.solutions_by_risk(), writer)

csv_data = buffer.getvalue()
buffer.close()
response = self.request.RESPONSE
today_iso = datetime.date.today().isoformat()
response.setHeader(
"Content-Disposition",
(
f"attachment; filename=similar_titles_details_{self.context.Title()}_"
f"{today_iso}.csv"
),
)
response.setHeader("Content-Type", "text/csv;charset=utf-8")
return csv_data
16 changes: 16 additions & 0 deletions src/euphorie/content/browser/templates/similar_titles_details.pt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@
solutions_by_risk view/solutions_by_risk;
"
>
<form action="${context/absolute_url}/@@similar-titles-details-csv"
method="post"
>
<p>
<input name="paths:list"
type="hidden"
value="${path}"
tal:repeat="path request/form/paths|nothing"
/>
<input class="details-button"
type="submit"
value="Download"
i18n:attributes="value"
/>
</p>
</form>
<div tal:repeat="risk solutions_by_risk">
<h3>
<a href="${risk/absolute_url}">${risk/Title}</a>
Expand Down
Loading