Skip to content

Commit 099f40e

Browse files
committed
require site_id
1 parent 3dee4e1 commit 099f40e

File tree

5 files changed

+10
-26
lines changed

5 files changed

+10
-26
lines changed

edc_consent/__init__.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1 @@
1-
from importlib.metadata import version
2-
3-
__version__ = version("edc_consent")
4-
__all__ = [
5-
"site_consents",
6-
"ConsentDefinitionDoesNotExist",
7-
"ConsentDefinitionError",
8-
"ConsentError",
9-
"ConsentVersionSequenceError",
10-
"NotConsentedError",
11-
]
12-
13-
from .exceptions import (
14-
ConsentDefinitionDoesNotExist,
15-
ConsentDefinitionError,
16-
ConsentError,
17-
ConsentVersionSequenceError,
18-
NotConsentedError,
19-
)
201
from .site_consents import site_consents

edc_consent/form_validators/consent_definition_form_validator_mixin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
from edc_form_validators import INVALID_ERROR
77
from edc_sites.site import sites as site_sites
88

9-
from edc_consent import ConsentDefinitionDoesNotExist, site_consents
109
from edc_consent.consent_definition import ConsentDefinition
1110
from edc_consent.exceptions import (
11+
ConsentDefinitionDoesNotExist,
1212
ConsentDefinitionNotConfiguredForUpdate,
1313
NotConsentedError,
1414
SiteConsentError,
1515
)
16+
from edc_consent.site_consents import site_consents
1617

1718

1819
class ConsentDefinitionFormValidatorMixin:
@@ -47,7 +48,7 @@ def get_consent_or_raise(
4748
error_code = error_code or INVALID_ERROR
4849
try:
4950
consent_obj = site_consents.get_consent_or_raise(
50-
subject_identifier=self.subject_consent, report_datetime=report_datetime
51+
subject_identifier=self.subject_identifier, report_datetime=report_datetime
5152
)
5253
except (NotConsentedError, ConsentDefinitionNotConfiguredForUpdate) as e:
5354
self.raise_validation_error({fldname: str(e)}, error_code)

edc_consent/modelform_mixins/requires_consent_modelform_mixin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def clean(self):
2929
return cleaned_data
3030

3131
def validate_against_dob(self, consent_obj):
32-
if to_utc(self.report_datetime).date() < consent_obj.dob:
32+
if consent_obj and to_utc(self.report_datetime).date() < consent_obj.dob:
3333
dte_str = formatted_date(consent_obj.dob)
3434
raise forms.ValidationError(f"Report datetime cannot be before DOB. Got {dte_str}")
3535

edc_consent/site_consents.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def get_consent_or_raise(
115115
self,
116116
subject_identifier: str,
117117
report_datetime: datetime,
118-
site_id: int,
118+
site_id: int | None = None,
119119
raise_if_not_consented: bool | None = None,
120120
):
121121
"""Returns a subject consent using this consent_definition's
@@ -133,10 +133,12 @@ def get_consent_or_raise(
133133
raise_if_not_consented = (
134134
True if raise_if_not_consented is None else raise_if_not_consented
135135
)
136-
single_site = site_sites.get(site_id)
136+
137+
single_site = site_sites.get(site_id) if site_id else None
137138
cdef = self.get_consent_definition(report_datetime=report_datetime, site=single_site)
138139
consent_obj = cdef.get_consent_for(
139-
subject_identifier, raise_if_not_consented=raise_if_not_consented
140+
subject_identifier=subject_identifier,
141+
raise_if_not_consented=raise_if_not_consented,
140142
)
141143
if consent_obj and report_datetime < consent_obj.consent_datetime:
142144
if not cdef.updates:

edc_consent/system_checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.core.checks import CheckMessage, Error, Warning
22

3-
from . import ConsentDefinitionError
43
from .consent_definition import ConsentDefinition
4+
from .exceptions import ConsentDefinitionError
55
from .site_consents import site_consents
66

77

0 commit comments

Comments
 (0)