Skip to content

Commit

Permalink
Merge pull request #2552 from carpentries/feature/remove-member-affil…
Browse files Browse the repository at this point in the history
…iation

Remove member affiliation question; remove code question from SO and WI forms
  • Loading branch information
elichad authored Oct 26, 2023
2 parents 58a7ee2 + e7d55ab commit aef7bad
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 242 deletions.
2 changes: 0 additions & 2 deletions amy/extforms/tests/test_selforganised_submission_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ def test_fields_presence(self):
"institution_other_name",
"institution_other_URL",
"institution_department",
"member_affiliation",
"member_code",
"workshop_format",
"workshop_format_other",
"start",
Expand Down
2 changes: 0 additions & 2 deletions amy/extforms/tests/test_workshop_inquiry_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ def test_fields_presence(self):
"institution_other_name",
"institution_other_URL",
"institution_department",
"member_affiliation",
"member_code",
"location",
"country",
"routine_data",
Expand Down
1 change: 0 additions & 1 deletion amy/extforms/tests/test_workshop_request_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def test_fields_presence(self):
"institution_other_name",
"institution_other_URL",
"institution_department",
"member_affiliation",
"member_code",
"location",
"country",
Expand Down
42 changes: 10 additions & 32 deletions amy/extrequests/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ class Meta:
"institution_other_name",
"institution_other_URL",
"institution_department",
"member_affiliation",
"member_code",
"location",
"country",
Expand Down Expand Up @@ -389,19 +388,13 @@ def __init__(self, *args, **kwargs):
(self["institution_other_URL"], "Institution URL address"),
]

# move "member_code" field to "member_affiliation" subfield
self["member_affiliation"].field.widget.subfields = [
(self["member_code"], "Member registration code"),
]

# remove additional fields
self.helper.layout.fields.remove("travel_expences_management_other")
self.helper.layout.fields.remove("public_event_other")
self.helper.layout.fields.remove("institution_restrictions_other")
self.helper.layout.fields.remove("carpentries_info_source_other")
self.helper.layout.fields.remove("institution_other_name")
self.helper.layout.fields.remove("institution_other_URL")
self.helper.layout.fields.remove("member_code")

# add warning alert for dates falling within next 2-3 months
DATES_TOO_SOON_WARNING = (
Expand Down Expand Up @@ -429,7 +422,7 @@ def __init__(self, *args, **kwargs):
hr_fields_after = (
"secondary_email",
"institution_department",
"member_affiliation",
"member_code",
"country",
"audience_description",
"user_notes",
Expand Down Expand Up @@ -458,25 +451,16 @@ def validate_member_code(
self, request: HttpRequest
) -> None | dict[str, ValidationError]:
errors = dict()
affiliation = self.cleaned_data.get("member_affiliation") # yes/no/unsure
code = self.cleaned_data.get("member_code", "")
if affiliation in ["yes", "unsure"] and code:
# ensure that code belongs to a membership
try:
Membership.objects.get(registration_code=code)
except Membership.DoesNotExist:
errors["member_code"] = ValidationError(
"This code is invalid. "
"Please contact your Member Affiliate to verify your code."
)
elif affiliation == "yes" and not code:
errors["member_code"] = ValidationError(
"This field is required if you selected 'Yes' above."
)
elif affiliation == "no" and code:
errors["member_code"] = ValidationError(
"This field must be empty if you selected 'No' above."
)
error_msg = (
"This code is invalid. "
"Please contact your Member Affiliate to verify your code."
)
# ensure that code belongs to a membership
try:
Membership.objects.get(registration_code=code)
except Membership.DoesNotExist:
errors["member_code"] = ValidationError(error_msg)

return errors

Expand Down Expand Up @@ -745,8 +729,6 @@ class Meta:
"institution_other_name",
"institution_other_URL",
"institution_department",
"member_affiliation",
"member_code",
"location",
"country",
"online_inperson",
Expand Down Expand Up @@ -899,7 +881,6 @@ def __init__(self, *args, **kwargs):
hr_fields_after = (
"secondary_email",
"institution_department",
"member_code",
"audience_description",
"country",
"user_notes",
Expand Down Expand Up @@ -1165,8 +1146,6 @@ class Meta:
"institution_other_name",
"institution_other_URL",
"institution_department",
"member_affiliation",
"member_code",
"online_inperson",
"workshop_format",
"workshop_format_other",
Expand Down Expand Up @@ -1243,7 +1222,6 @@ def __init__(self, *args, **kwargs):
hr_fields_after = (
"secondary_email",
"institution_department",
"member_code",
"additional_contact",
"language",
"online_inperson",
Expand Down
21 changes: 21 additions & 0 deletions amy/extrequests/migrations/0033_auto_20231023_1345.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.20 on 2023-10-23 13:45

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('extrequests', '0032_add_member_affiliation_and_member_code'),
]

operations = [
migrations.RemoveField(
model_name='selforganisedsubmission',
name='member_affiliation',
),
migrations.RemoveField(
model_name='workshopinquiryrequest',
name='member_affiliation',
),
]
20 changes: 1 addition & 19 deletions amy/extrequests/tests/test_selforganised_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@
from extrequests.models import SelfOrganisedSubmission
import extrequests.views
from workshops.forms import EventCreateForm
from workshops.models import (
Curriculum,
Event,
Language,
Membership,
Organization,
Role,
Tag,
Task,
)
from workshops.models import Curriculum, Event, Language, Organization, Role, Tag, Task
from workshops.tests.base import FormTestHelper, TestBase


Expand Down Expand Up @@ -353,12 +344,6 @@ def test_accept_with_event_autofill(self):
"""Ensure that fields are autofilled correctly when creating an Event from a
SelfOrganisedSubmission."""
# Arrange
expected_membership = Membership.objects.create(
name="Hogwarts",
agreement_start=date.today() - timedelta(weeks=26),
agreement_end=date.today() + timedelta(weeks=26),
registration_code="hogwarts55",
)
sos = SelfOrganisedSubmission.objects.create(
# required fields
state="p",
Expand All @@ -374,8 +359,6 @@ def test_accept_with_event_autofill(self):
online_inperson="online",
workshop_listed=False,
additional_contact="[email protected]",
member_affiliation="yes",
member_code="hogwarts55",
)
curriculum = Curriculum.objects.filter(name__contains="Data Carpentry").first()
sos.workshop_types.set([curriculum])
Expand All @@ -399,7 +382,6 @@ def test_accept_with_event_autofill(self):
self.assertEqual(form_initial["host"].pk, sos.institution.pk)
self.assertEqual(form_initial["start"], sos.start)
self.assertEqual(form_initial["end"], sos.end)
self.assertEqual(form_initial["membership"].pk, expected_membership.pk)

def test_discarded_request_not_accepted_with_event(self):
rv = self.client.get(
Expand Down
10 changes: 0 additions & 10 deletions amy/extrequests/tests/test_workshop_inquiries.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Event,
KnowledgeDomain,
Language,
Membership,
Organization,
Role,
Tag,
Expand Down Expand Up @@ -511,12 +510,6 @@ def test_accept_with_event_autofill(self):
"""Ensure that fields are autofilled correctly when creating an Event from a
WorkshopInquiryRequest."""
# Arrange
expected_membership = Membership.objects.create(
name="Hogwarts",
agreement_start=date.today() - timedelta(weeks=26),
agreement_end=date.today() + timedelta(weeks=26),
registration_code="hogwarts55",
)
wi = WorkshopInquiryRequest.objects.create(
# required fields
state="p",
Expand All @@ -535,8 +528,6 @@ def test_accept_with_event_autofill(self):
online_inperson="online",
workshop_listed=False,
additional_contact="[email protected]",
member_affiliation="yes",
member_code="hogwarts55",
)
curriculum = Curriculum.objects.filter(name__contains="Data Carpentry").first()
wi.requested_workshop_types.set([curriculum])
Expand All @@ -558,7 +549,6 @@ def test_accept_with_event_autofill(self):
self.assertEqual(form_initial["host"].pk, wi.institution.pk)
self.assertEqual(form_initial["start"], wi.preferred_dates)
self.assertEqual(form_initial["end"], wi.preferred_dates + timedelta(days=1))
self.assertEqual(form_initial["membership"].pk, expected_membership.pk)

def test_discarded_request_not_accepted_with_event(self):
rv = self.client.get(
Expand Down
Loading

0 comments on commit aef7bad

Please sign in to comment.