Skip to content

Commit

Permalink
Merge branch 'release/0.3.82' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Apr 12, 2024
2 parents 349a5f7 + 82b7ad3 commit ecf16e9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
5 changes: 1 addition & 4 deletions edc_consent/consent_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
from .managers import ConsentObjectsByCdefManager, CurrentSiteByCdefManager

if TYPE_CHECKING:
from edc_identifier.model_mixins import NonUniqueSubjectIdentifierModelMixin
from edc_model.models import BaseUuidModel
from edc_screening.model_mixins import EligibilityModelMixin, ScreeningModelMixin

from .model_mixins import ConsentModelMixin

class ConsentLikeModel(NonUniqueSubjectIdentifierModelMixin, ConsentModelMixin): ...
from .stubs import ConsentLikeModel

class SubjectScreening(ScreeningModelMixin, EligibilityModelMixin, BaseUuidModel): ...

Expand Down
16 changes: 8 additions & 8 deletions edc_consent/modelform_mixins/requires_consent_modelform_mixin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from django import forms
from edc_sites import site_sites
from edc_utils import formatted_date
Expand All @@ -13,6 +15,10 @@
)
from ..site_consents import site_consents

if TYPE_CHECKING:
from ..stubs import ConsentLikeModel


__all__ = ["RequiresConsentModelFormMixin"]


Expand All @@ -33,10 +39,11 @@ def validate_against_dob(self, consent_obj):
dte_str = formatted_date(consent_obj.dob)
raise forms.ValidationError(f"Report datetime cannot be before DOB. Got {dte_str}")

def validate_against_consent(self) -> None:
def validate_against_consent(self) -> ConsentLikeModel | None:
"""Raise an exception if the report datetime doesn't make
sense relative to the consent.
"""
consent_obj = None
if self.report_datetime:
try:
consent_obj = site_consents.get_consent_or_raise(
Expand All @@ -46,13 +53,6 @@ def validate_against_consent(self) -> None:
)
except (NotConsentedError, ConsentDefinitionNotConfiguredForUpdate) as e:
raise forms.ValidationError({"__all__": str(e)})
# if floor_secs(to_utc(self.report_datetime)) < floor_secs(
# model_obj.consent_datetime
# ):
# dte_str = formatted_datetime(to_local(model_obj.consent_datetime))
# raise forms.ValidationError(
# f"Report datetime cannot be before consent datetime. Got {dte_str}."
# )
return consent_obj

@property
Expand Down
7 changes: 2 additions & 5 deletions edc_consent/site_consents.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
)

if TYPE_CHECKING:
from edc_model.models import BaseUuidModel
from edc_sites.single_site import SingleSite

from .consent_definition import ConsentDefinition
from .model_mixins import ConsentModelMixin

class ConsentModel(ConsentModelMixin, BaseUuidModel): ...
from .stubs import ConsentLikeModel


__all__ = ["site_consents"]
Expand Down Expand Up @@ -116,7 +113,7 @@ def get_consent_or_raise(
report_datetime: datetime,
site_id: int | None = None,
raise_if_not_consented: bool | None = None,
):
) -> ConsentLikeModel:
"""Returns a subject consent using this consent_definition's
`model_cls` and `version`.
Expand Down
3 changes: 2 additions & 1 deletion edc_consent/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Protocol

from edc_identifier.model_mixins import NonUniqueSubjectIdentifierModelMixin
from edc_model.models import BaseUuidModel
from edc_sites.model_mixins import SiteModelMixin

from .model_mixins import ConsentModelMixin
Expand All @@ -14,5 +15,5 @@ class ConsentModelStub(Protocol):


class ConsentLikeModel(
SiteModelMixin, ConsentModelMixin, NonUniqueSubjectIdentifierModelMixin
SiteModelMixin, ConsentModelMixin, NonUniqueSubjectIdentifierModelMixin, BaseUuidModel
): ...

0 comments on commit ecf16e9

Please sign in to comment.