Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/clinicedc/edc-sites into…
Browse files Browse the repository at this point in the history
… develop
  • Loading branch information
JonathanWillitts committed Feb 2, 2024
2 parents 1906f52 + c1dd46d commit aa212e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion edc_sites/admin/site_model_admin_mixin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import collections
from typing import TYPE_CHECKING, Type

from django.contrib import admin
from django.core.exceptions import FieldError, ObjectDoesNotExist
Expand All @@ -10,6 +11,10 @@
from ..site import sites
from .list_filters import SiteListFilter

if TYPE_CHECKING:
from django.contrib.admin import SimpleListFilter


__all__ = ["SiteModelAdminMixin"]


Expand All @@ -35,7 +40,7 @@ def site_name(self, obj=None):
return obj.site.name
return f"{site_profile.site.id} {site_profile.description}"

def get_list_filter(self, request):
def get_list_filter(self, request) -> tuple[str | Type[SimpleListFilter], ...]:
"""Insert `SiteListFilter` before field name `created`.
Remove site from the list if user does not have access
Expand Down
12 changes: 6 additions & 6 deletions edc_sites/modelform_mixins.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from django import forms

if TYPE_CHECKING:
from django.contrib.sites.models import Site
from django.contrib.sites.models import Site

__all__ = ["SiteModelFormMixin"]

Expand All @@ -32,7 +28,11 @@ def clean(self) -> dict:

@property
def site(self) -> Site:
return self.cleaned_data.get("site") or self.instance.site or self.related_visit.site
if related_visit := getattr(self, "related_visit", None):
return related_visit.site
return (
self.cleaned_data.get("site") or self.instance.site or Site.objects.get_current()
)

def validate_with_current_site(self) -> None:
current_site = getattr(self, "current_site", None)
Expand Down

0 comments on commit aa212e0

Please sign in to comment.