forked from botswana-harvard/edc-consent
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/0.3.75' into main
- Loading branch information
Showing
11 changed files
with
223 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,40 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from django.db import models | ||
from edc_search.model_mixins import SearchSlugManager | ||
from edc_sites.managers import CurrentSiteManager | ||
|
||
from .site_consents import site_consents | ||
|
||
if TYPE_CHECKING: | ||
from .stubs import ConsentLikeModel | ||
|
||
class ConsentObjectsManager(SearchSlugManager, models.Manager): | ||
use_in_migrations = True | ||
|
||
class ObjectConsentManager(models.Manager): | ||
def get_by_natural_key(self, subject_identifier_as_pk): | ||
return self.get(subject_identifier_as_pk=subject_identifier_as_pk) | ||
|
||
|
||
class ConsentManager(models.Manager): | ||
def first_consent(self, subject_identifier=None) -> ConsentLikeModel: | ||
"""Returns the first consent by consent_datetime.""" | ||
return ( | ||
self.filter(subject_identifier=subject_identifier) | ||
.order_by("consent_datetime") | ||
.first() | ||
) | ||
class ConsentObjectsByCdefManager(ConsentObjectsManager): | ||
"""An objects model manager to use on consent proxy models | ||
linked to a ConsentDefinition. | ||
Filters queryset by the proxy model's label_lower | ||
""" | ||
|
||
def get_queryset(self): | ||
qs = super().get_queryset() | ||
cdef = site_consents.get_consent_definition(model=qs.model._meta.label_lower) | ||
return qs.filter(version=cdef.version) | ||
|
||
|
||
class CurrentSiteByCdefManager(CurrentSiteManager): | ||
"""A site model manager to use on consent proxy models | ||
linked to a ConsentDefinition. | ||
Filters queryset by the proxy model's label_lower | ||
""" | ||
|
||
def get_queryset(self): | ||
qs = super().get_queryset() | ||
cdef = site_consents.get_consent_definition(model=qs.model._meta.label_lower) | ||
return qs.filter(version=cdef.version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.