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

Allow exporting abstract contents to CSV/XLSX #5356

Closed
rppt opened this issue May 27, 2022 · 2 comments · Fixed by #5372
Closed

Allow exporting abstract contents to CSV/XLSX #5356

rppt opened this issue May 27, 2022 · 2 comments · Fixed by #5372
Milestone

Comments

@rppt
Copy link
Contributor

rppt commented May 27, 2022

Is your feature request related to a problem? Please describe.
In our model not all reviewers have access to the submissions in indicio. For the review we export all the abstracts to a spreadsheet and ask reviewers to vote in the spreadsheet. Unfortunately, exporting CSV/XLSX from event/N/manage/abstracts/list/ does not allow to include the abstract text in the generated spreadsheet.

Describe the solution you'd like
I would like to be able to see the abstract text in the exported CSV/XLSX when the "Contents" button is pressed in "Customize list" in abstracts list form. I.e. if event/N/manage/abstracts/list/ shows the abstract content, then exporting abstracts to CSV/XLSX will include the abstract text.

For our indico setup I've added the patch below as a temporal solution, but it mangles some characters because I didn't find how to correctly put abstract.description to the generated spreadsheet.

From fbb27612aa86a508fc10179a7ef0adf85749e6bb Mon Sep 17 00:00:00 2001
From: Mike Rapoport <rppt@kernel.org>
Date: Sat, 21 May 2022 22:49:55 +0300
Subject: [PATCH] LPC: add abstract contents to CSV and XLSX exports

---
 indico/modules/events/abstracts/util.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/indico/modules/events/abstracts/util.py b/indico/modules/events/abstracts/util.py
index faea32873f..8d09b5956a 100644
--- a/indico/modules/events/abstracts/util.py
+++ b/indico/modules/events/abstracts/util.py
@@ -70,6 +70,7 @@ def generate_spreadsheet_from_abstracts(abstracts, static_item_ids, dynamic_item
         'score': ('Score', lambda x: round(x.score, 1) if x.score is not None else None),
         'submitted_dt': ('Submission date', lambda x: x.submitted_dt),
         'modified_dt': ('Modification date', lambda x: x.modified_dt if x.modified_dt else ''),
+        'description': ('Content', lambda x: x.description),
     }
     field_names.extend(unique_col(item.title, item.id) for item in dynamic_items)
     field_names.extend(title for name, (title, fn) in static_item_mapping.items() if name in static_item_ids)
-- 
2.34.1
@ThiefMaster ThiefMaster added this to the v3.2 milestone Jun 17, 2022
@ThiefMaster
Copy link
Member

This change looks good. My guess is that the "mangling" you experienced comes from this sanitization we apply to data that goes into CSV files:

def _prepare_csv_data(data, _linebreak_re=re.compile(r'(\r?\n)+'), _dangerous_chars_re=re.compile(r'^[=+@-]+')):
    if isinstance(data, (list, tuple)):
        data = '; '.join(data)
    elif isinstance(data, set):
        data = '; '.join(sorted(data, key=str.lower))
    elif isinstance(data, bool):
        data = 'Yes' if data else 'No'
    elif data is None:
        data = ''
    data = _linebreak_re.sub('    ', str(data))
    # https://www.owasp.org/index.php/CSV_Injection
    # quoting the cell's value does NOT mitigate this, so we need to strip
    # those characters from the beginning...
    return _dangerous_chars_re.sub('', data)

However, this seems acceptable - if someone wants something that's exactly the same, they can use the Excel (XLSX) export instead.. CSV is not well-suited for multi-line content.

I will open a PR containing your commit and merge it once CI passed.

@rppt
Copy link
Contributor Author

rppt commented Jun 18, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants