Skip to content

Commit

Permalink
Merge branch 'release/0.3.72' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Feb 21, 2024
2 parents 6163007 + 57ee70a commit a5337f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- "-x *test*.py"

- repo: https://github.com/psf/black
rev: 24.1.1
rev: 24.2.0
hooks:
- id: black
language_version: python3.11
Expand Down Expand Up @@ -42,7 +42,7 @@ repos:
- id: detect-private-key

- repo: https://github.com/adrienverge/yamllint
rev: v1.33.0
rev: v1.34.0
hooks:
- id: yamllint
args:
Expand Down
20 changes: 16 additions & 4 deletions edc_consent/models/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.db.models.signals import pre_save
from django.dispatch import receiver
from edc_registration.models import RegisteredSubject
from edc_screening.utils import get_subject_screening_model_cls
from edc_sites import site_sites

from ..exceptions import NotConsentedError
Expand All @@ -18,7 +19,6 @@ def requires_consent_on_pre_save(instance, raw, using, update_fields, **kwargs):
and not instance._meta.model_name.startswith("historical")
):
subject_identifier = getattr(instance, "related_visit", instance).subject_identifier
schedule = getattr(instance, "related_visit", instance).schedule
site = getattr(instance, "related_visit", instance).site
# is the subject registered?
try:
Expand All @@ -37,9 +37,21 @@ def requires_consent_on_pre_save(instance, raw, using, update_fields, **kwargs):
# get the consent definition valid for this report_datetime.
# Schedule may have more than one consent definition but only one
# is returned
consent_definition = schedule.get_consent_definition(
site=site_sites.get(site.id), report_datetime=instance.report_datetime
)
try:
schedule = getattr(instance, "related_visit", instance).schedule
except AttributeError:
schedule = None
if schedule:
consent_definition = schedule.get_consent_definition(
site=site_sites.get(site.id), report_datetime=instance.report_datetime
)
else:
# this is a model like SubjectLocator which has no visit_schedule
# fields. Assume the cdef from SubjectScreening
subject_screening = get_subject_screening_model_cls().objects.get(
subject_identifier=subject_identifier
)
consent_definition = subject_screening.consent_definition
get_consent_or_raise(
model=instance._meta.label_lower,
subject_identifier=subject_identifier,
Expand Down

0 comments on commit a5337f6

Please sign in to comment.