Skip to content

Commit

Permalink
[#2370] Merging persons: display & merge consents
Browse files Browse the repository at this point in the history
  • Loading branch information
pbanaszkiewicz committed Apr 16, 2023
1 parent e78fed1 commit 6a59289
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
18 changes: 16 additions & 2 deletions amy/templates/workshops/persons_merge.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,22 @@
</tr>
<tr>
<th>Consents</th>
<td></td>
<td></td>
<td>
<dl>
{% for consent in obj_a_consents.values %}
<dt>{{ consent.term.content}}</dt>
<dd>{{ consent.term_option|default:"Unset" }}</dd>
{% endfor %}
</dl>
</td>
<td>
<dl>
{% for consent in obj_b_consents.values %}
<dt>{{ consent.term.content}}</dt>
<dd>{{ consent.term_option|default:"Unset" }}</dd>
{% endfor %}
</dl>
</td>
<th>{% include "includes/merge_radio.html" with field=form.consent_set %}</th>
</tr>
</table>
Expand Down
2 changes: 1 addition & 1 deletion amy/workshops/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ class PersonsMergeForm(forms.Form):
widget=forms.RadioSelect,
)
consent_set = forms.ChoiceField(
choices=THREE,
choices=TWO,
initial=DEFAULT,
widget=forms.RadioSelect,
)
Expand Down
23 changes: 2 additions & 21 deletions amy/workshops/tests/test_person.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ def setUp(self):
"trainingprogress_set": "combine",
"comment_comments": "combine", # made by this person
"comments": "combine", # regarding this person
"consent_set": "combine",
"consent_set": "obj_a",
}
base_url = reverse("persons_merge")
query = urlencode({"person_a": self.person_a.pk, "person_b": self.person_b.pk})
Expand Down Expand Up @@ -937,6 +937,7 @@ def test_form_invalid_values(self):
"occupation": "combine",
"orcid": "combine",
"is_active": "combine",
"consent_set": "combine",
}
# fields additionally accepting "combine"
passing = {
Expand All @@ -948,7 +949,6 @@ def test_form_invalid_values(self):
"trainingprogress_set": "combine",
"comment_comments": "combine",
"comments": "combine",
"consent_set": "combine",
}
data = hidden.copy()
data.update(failing)
Expand Down Expand Up @@ -1113,25 +1113,6 @@ def test_merging_comments_strategy3(self):
set(comments),
)

def test_merging_consents_combine(self):
"""Ensure consents regarding persons are correctly merged using
`merge_objects`.
This test uses strategy 1 (combine)."""
self.strategy["consent_set"] = "combine"
expected_consents = list(
Consent.objects.filter(person__in=[self.person_a, self.person_b])
)
rv = self.client.post(self.url, data=self.strategy)
self.assertEqual(rv.status_code, 302)
self.person_b.refresh_from_db()
self.assertCountEqual(
[
(c.term, c.term_option, c.person)
for c in Consent.objects.filter(person=self.person_b)
],
[(c.term, c.term_option, self.person_b) for c in expected_consents],
)

def test_merging_consents_obj_a(self):
"""Ensure consents regarding persons are correctly merged using
`merge_objects`.
Expand Down
4 changes: 0 additions & 4 deletions amy/workshops/utils/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from django.db import IntegrityError, transaction
from django_comments.models import Comment

from workshops.utils.consents import archive_least_recent_active_consents


def merge_objects(
object_a, object_b, easy_fields, difficult_fields, choices, base_a=True
Expand Down Expand Up @@ -108,8 +106,6 @@ def merge_objects(

elif value == "combine":
to_add = None
if attr == "consent_set":
archive_least_recent_active_consents(object_a, object_b, base_obj)

if manager == related_a:
to_add = related_b.all()
Expand Down
12 changes: 12 additions & 0 deletions amy/workshops/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,18 @@ def persons_merge(request):
"form": form,
"obj_a": obj_a,
"obj_b": obj_b,
"obj_a_consents": {
consent.term.key: consent
for consent in Consent.objects.select_related("term", "term_option").filter(
person=obj_a
)
},
"obj_b_consents": {
consent.term.key: consent
for consent in Consent.objects.select_related("term", "term_option").filter(
person=obj_b
)
},
}
return render(request, "workshops/persons_merge.html", context)

Expand Down

0 comments on commit 6a59289

Please sign in to comment.