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

Feature/revise study end questions 4 #707

Merged
merged 24 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2f46c2f
feat: rename TranslatedConsentForm
EdoStorm96 Sep 24, 2024
045e437
feat: add fields to proposal and make migration
EdoStorm96 Sep 25, 2024
b3ed947
feat: modify study model and migration
EdoStorm96 Sep 25, 2024
40e7235
feat: make KnowledgeSecurityForm
EdoStorm96 Sep 25, 2024
fb6b7d8
feat: update StudyEndForm
EdoStorm96 Sep 25, 2024
1b538c3
feat: add KnowledgeSecurityView
EdoStorm96 Sep 25, 2024
6446f56
feat: implement pdf_diff_logic for new questions
EdoStorm96 Sep 25, 2024
1515411
feat: update auto_review & tests
EdoStorm96 Sep 25, 2024
8c523b5
fix: woops, some ugly string stuff
EdoStorm96 Sep 25, 2024
33be1ae
fix: rename KnowledgeSecurityChecker
EdoStorm96 Sep 25, 2024
712270f
style: steez
EdoStorm96 Sep 25, 2024
d75c387
fix: update a lot of translations
EdoStorm96 Sep 30, 2024
d00f26c
fix: rename TranslatedConsentFormsView to TranslatedConsentView
EdoStorm96 Sep 30, 2024
72634a5
fix: remove stressful from soft_validation_fields
EdoStorm96 Sep 30, 2024
4d094e1
fix: improvements to the StudyEndForm
EdoStorm96 Sep 30, 2024
a2a2fa9
style: blck
EdoStorm96 Sep 30, 2024
e3f9788
fix: update link on index.html
EdoStorm96 Oct 1, 2024
17a6d1d
style: djlint
EdoStorm96 Oct 1, 2024
6c0c319
fix: tests
EdoStorm96 Oct 1, 2024
44ecaca
Merge branch 'major/4' into feature/revise_study_end_questions_4
EdoStorm96 Oct 1, 2024
b3f7861
fix: add test_pdf.pdf for tests
EdoStorm96 Oct 1, 2024
a29de10
fix: indentation TasksOverviewSection
EdoStorm96 Oct 2, 2024
703ddfe
fix: save proposal in AutoReviewTests
EdoStorm96 Oct 2, 2024
41e6347
fix: rename self.choice_fields attribute of StudyEndForm
EdoStorm96 Oct 2, 2024
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
61 changes: 59 additions & 2 deletions proposals/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,64 @@ def clean(self):
)


class TranslatedConsentForms(SoftValidationMixin, ConditionalModelForm):
class KnowledgeSecurityForm(SoftValidationMixin, ConditionalModelForm):

class Meta:
model = Proposal
fields = [
"knowledge_security",
"knowledge_security_details",
"researcher_risk",
"researcher_risk_details",
]
widgets = {
"knowledge_security": BootstrapRadioSelect(),
"researcher_risk": BootstrapRadioSelect(),
}

_soft_validation_fields = [
"knowledge_security",
"knowledge_security_details",
"researcher_risk",
"researcher_risk_details",
]

def __init__(self, *args, **kwargs):
"""
- Set the Study for later reference
- Remove empty label from fields and reset the choices
"""
super(KnowledgeSecurityForm, self).__init__(*args, **kwargs)

self.base_fields = (
"knowledge_security",
"researcher_risk",
)
for field in self.base_fields:
self.fields[field].empty_label = None
self.fields[field].choices = YesNoDoubt.choices

def clean(self):
"""
Check for conditional requirements:
- If deception is set to yes, make sure deception_details has been filled out
- If negativity is set to yes, make sure negativity_details has been filled out
- If risk is set to yes, make sure risk_details has been filled out
"""
cleaned_data = super(KnowledgeSecurityForm, self).clean()

self.mark_soft_required(cleaned_data, "knowledge_security", "researcher_risk")

for field in self.base_fields:
self.check_dependency_list(
cleaned_data,
f"{field}",
f"{field}_details",
f1_value_list=[YesNoDoubt.YES, YesNoDoubt.DOUBT],
)


class TranslatedConsentForm(SoftValidationMixin, ConditionalModelForm):
class Meta:
model = Proposal
fields = ["translated_forms", "translated_forms_languages"]
Expand All @@ -862,7 +919,7 @@ class Meta:
_soft_validation_fields = ["translated_forms", "translated_forms_languages"]

def clean(self):
cleaned_data = super(TranslatedConsentForms, self).clean()
cleaned_data = super(TranslatedConsentForm, self).clean()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TranslatedConsentFormsView still uses a plural which is a tiny bit confusing


if cleaned_data["translated_forms"] is None:
self.add_error(
Expand Down
49 changes: 49 additions & 0 deletions proposals/migrations/0054_proposal_knowledge_security_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generated by Django 4.2.11 on 2024-09-24 14:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("proposals", "0053_auto_20240201_1557"),
]

operations = [
migrations.AddField(
model_name="proposal",
name="knowledge_security",
field=models.CharField(
blank=True,
choices=[("Y", "ja"), ("N", "nee"), ("?", "twijfel")],
help_text="Kennisveiligheid gaat over het tijdig signaleren en mitigeren van veiligheidsrisico's bij wetenschappelijk onderzoek. Klik <a href='https://intranet.uu.nl/kennisbank/kennisveiligheid'>hier</a> voor meer informatie.",
max_length=1,
verbose_name="Zijn er kwesties rondom kennisveiligheid?",
),
),
migrations.AddField(
model_name="proposal",
name="knowledge_security_details",
field=models.TextField(
blank=True, max_length=200, verbose_name="Licht toe"
),
),
migrations.AddField(
model_name="proposal",
name="researcher_risk",
field=models.CharField(
blank=True,
choices=[("Y", "ja"), ("N", "nee"), ("?", "twijfel")],
help_text="Houd hierbij niet alleen rekening met mogelijke psychische of fysieke schade, maar ook met andere mogelijke schade, zoals bijv. hiërarchische machtsverhoudingen in veldwerk, mogelijke negatieve gevolgen voor de zichtbaarheid/vindbaarheid van de onderzoeker in in het publieke domein, juridische vervolging of aansprakelijkheid, e.d.",
max_length=1,
verbose_name="Zijn er kwesties rondom de veiligheid van of risico's voor de onderzoeker(s)?",
),
),
migrations.AddField(
model_name="proposal",
name="researcher_risk_details",
field=models.TextField(
blank=True, max_length=200, verbose_name="Licht toe"
),
),
]
36 changes: 36 additions & 0 deletions proposals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,42 @@ class PracticeReasons(models.IntegerChoices):
MaxWordsValidator(SELF_ASSESSMENT_MAX_WORDS),
],
)
knowledge_security = models.CharField(
_("Zijn er kwesties rondom kennisveiligheid?"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of these strings remain untranslated

help_text=mark_safe_lazy(
_(
"Kennisveiligheid gaat over het tijdig signaleren en mitigeren "
"van veiligheidsrisico's bij wetenschappelijk onderzoek. Klik "
"<a href='https://intranet.uu.nl/kennisbank/kennisveiligheid'>hier</a> "
"voor meer informatie."
)
),
max_length=1,
choices=YesNoDoubt.choices,
blank=True,
)
knowledge_security_details = models.TextField(
_("Licht toe"), max_length=200, blank=True
)
researcher_risk = models.CharField(
_(
"Zijn er kwesties rondom de veiligheid van of risico's voor de onderzoeker(s)?"
),
help_text=_(
"Houd hierbij niet alleen rekening met mogelijke psychische of "
"fysieke schade, maar ook met andere mogelijke schade, zoals bijv. "
"hiërarchische machtsverhoudingen in veldwerk, mogelijke negatieve "
"gevolgen voor de zichtbaarheid/vindbaarheid van de onderzoeker in "
"in het publieke domein, juridische vervolging of "
"aansprakelijkheid, e.d."
),
max_length=1,
choices=YesNoDoubt.choices,
blank=True,
)
researcher_risk_details = models.TextField(
_("Licht toe"), max_length=200, blank=True
)

# References to other models
relation = models.ForeignKey(
Expand Down
22 changes: 22 additions & 0 deletions proposals/templates/proposals/knowledge_security_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "base/fetc_form_base.html" %}

{% load static %}
{% load i18n %}

{% block header_title %}
{% trans "Afronding trajecten" %} - {{ block.super }}
{% endblock %}

{% block html_head %}
{{ block.super }}
<script>
$(function () {
depends_on_list_value('knowledge_security', ['Y', '?'], 'knowledge_security_details');
depends_on_list_value('researcher_risk', ['Y', '?'], 'researcher_risk_details');
});
</script>
{% endblock %}

{% block pre-form-text %}
<h3>{% trans "Afronding trajecten" %}</h3>
{% endblock %}
6 changes: 6 additions & 0 deletions proposals/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
ProposalUpdateDataManagement,
TranslatedConsentFormsView,
ProposalUpdateDateStart,
ProposalKnowledgeSecurity,
)

from .views.study_views import StudyStart, StudyConsent
Expand Down Expand Up @@ -213,6 +214,11 @@
),
path("confirm/<int:pk>/", ProposalConfirmation.as_view(), name="confirmation"),
path("study_start/<int:pk>/", StudyStart.as_view(), name="study_start"),
path(
"knowledge_security/<int:pk>/",
ProposalKnowledgeSecurity.as_view(),
name="knowledge_security",
),
path("consent/<int:pk>/", StudyConsent.as_view(), name="consent"),
path(
"translated/<int:pk>/", TranslatedConsentFormsView.as_view(), name="translated"
Expand Down
23 changes: 21 additions & 2 deletions proposals/utils/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ def remaining_checkers(
self,
):
return [
KnowledgeSecurityChecker(self.stepper, parent=self.item),
DocumentsChecker,
DataManagementChecker,
SubmitChecker,
Expand Down Expand Up @@ -350,6 +351,24 @@ def get_form_kwargs(self):
return kwargs


class KnowledgeSecurityChecker(
ModelFormChecker,
):
form_class = proposal_forms.KnowledgeSecurityForm
title = _("Traject afronding")

def check(self):
if self.stepper.has_multiple_studies():
self.title = _("Trajecten afronding")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice touch

self.stepper.items.append(self.make_stepper_item())
return []

def get_url(
self,
):
return reverse("proposals:knowledge_security", args=[self.proposal.pk])


class StudyChecker(
Checker,
):
Expand Down Expand Up @@ -497,7 +516,7 @@ def get_url(
class StudyEndChecker(
ModelFormChecker,
):
title = _("Afronding")
title = _("Traject overzicht")
form_class = study_forms.StudyEndForm

def __init__(
Expand Down Expand Up @@ -803,7 +822,7 @@ def make_stepper_item(self):
class TranslationChecker(
ModelFormChecker,
):
form_class = proposal_forms.TranslatedConsentForms
form_class = proposal_forms.TranslatedConsentForm
title = _("Vertalingen")
location = "data_management"

Expand Down
67 changes: 49 additions & 18 deletions proposals/utils/pdf_diff_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,6 @@ class StudyOverviewSection(BaseSection):
"deception_details",
"negativity",
"negativity_details",
"stressful",
"stressful_details",
"risk",
"risk_details",
]
Expand All @@ -842,7 +840,7 @@ def get_row_fields(self):
obj = self.obj

rows_to_remove = []
for x in range(0, 7, 2):
for x in range(0, len(self.row_fields), 2):
if getattr(obj, rows[x]) == "N":
rows_to_remove.append(rows[x + 1])
rows = [row for row in rows if row not in rows_to_remove]
Expand All @@ -856,6 +854,30 @@ def get_row_fields(self):
return rows


class KnowledgeSecuritySection(BaseSection):
"""This class receives a Proposal object."""

section_title = _("Kennisveiligheid en risico onderzoekers")
row_fields = [
"knowledge_security",
"knowledge_security_details",
"researcher_risk",
"researcher_risk_details",
]

def get_row_fields(self):
rows = copy(self.row_fields)
obj = self.obj

rows_to_remove = []
for x in range(0, len(self.row_fields), 2):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is such an unnecessarily complicated way to remove at most two fields. But it's kind of funny as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I have kindoff a love/hate relationship with this ... I often start thinking of a way to get rid of it, but then end up spending too much time on it (again ...) and I just move on. I'll get around to it someday ;p

if getattr(obj, rows[x]) == "N":
rows_to_remove.append(rows[x + 1])
rows = [row for row in rows if row not in rows_to_remove]

return rows


class InformedConsentFormsSection(BaseSection):
"""This class receives a Documents object"""

Expand Down Expand Up @@ -997,24 +1019,24 @@ def get_extra_documents(obj):
return extra_documents


def create_context_pdf(context, model):
def create_context_pdf(context, proposal):
"""A function to create the context for the PDF, which gets called in the ProposalAsPdf view."""

sections = []

sections.append(GeneralSection(model))
sections.append(GeneralSection(proposal))

if hasattr(model, "wmo"):
sections.append(WMOSection(model.wmo))
if hasattr(proposal, "wmo"):
sections.append(WMOSection(proposal.wmo))

if not model.is_pre_assessment:
if model.wmo.status != model.wmo.WMOStatuses.NO_WMO:
sections.append(METCSection(model.wmo))
if not proposal.is_pre_assessment:
if proposal.wmo.status != proposal.wmo.WMOStatuses.NO_WMO:
sections.append(METCSection(proposal.wmo))

sections.append(TrajectoriesSection(model))
sections.append(TrajectoriesSection(proposal))

if model.wmo.status == model.wmo.WMOStatuses.NO_WMO:
for study in model.study_set.all():
if proposal.wmo.status == proposal.wmo.WMOStatuses.NO_WMO:
for study in proposal.study_set.all():
sections.append(StudySection(study))
if study.has_intervention:
sections.append(InterventionSection(study.intervention))
Expand All @@ -1029,15 +1051,17 @@ def create_context_pdf(context, model):
sections.append(StudyOverviewSection(study))
sections.append(InformedConsentFormsSection(study.documents))

extra_documents = get_extra_documents(model)
sections.append(KnowledgeSecuritySection(proposal))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When generating a PDF for a proposal with sessions, line 1050 causes an error. I suspect this is just a mismatched indent and that the line just needs one more indentation level.

This doesn't seem to be related to this PR in particular, so I couldn't select the specific line in this review. But if you could quickly fix it here that would be great.


extra_documents = get_extra_documents(proposal)

for num, document in enumerate(extra_documents):
sections.append(ExtraDocumentsSection(document, num))

sections.append(DMPFileSection(model))
sections.append(DMPFileSection(proposal))

sections.append(EmbargoSection(model))
sections.append(CommentsSection(model))
sections.append(EmbargoSection(proposal))
sections.append(CommentsSection(proposal))

context["sections"] = sections

Expand Down Expand Up @@ -1193,6 +1217,13 @@ def create_context_diff(context, old_proposal, new_proposal):
)
)

sections.append(
DiffSection(
KnowledgeSecuritySection(old_proposal),
KnowledgeSecuritySection(new_proposal),
)
)

old_extra_docs = get_extra_documents(old_proposal)
new_extra_docs = get_extra_documents(new_proposal)

Expand All @@ -1210,7 +1241,7 @@ def create_context_diff(context, old_proposal, new_proposal):

sections.append(
DiffSection(
*multi_sections(DMPFileSection, [old_proposal, new_proposal])
DMPFileSection(old_proposal), DMPFileSection(new_proposal)
)
)

Expand Down
Loading
Loading