Skip to content

Commit

Permalink
Merge branch 'release/0.3.42' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jan 29, 2024
2 parents c33dad8 + 1cce2a4 commit 12afb62
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 43 deletions.
7 changes: 0 additions & 7 deletions edc_sites/admin/site_model_admin_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ def get_list_display(self, request):
list_display = (list_display[0],) + (self.site_code,) + list_display[1:]
return list_display

def get_readonly_fields(self, request, obj=None) -> tuple[str, ...]:
"""Add site to readonly_fields."""
readonly_fields = super().get_readonly_fields(request, obj=obj)
if "site" not in readonly_fields:
return readonly_fields + ("site",)
return readonly_fields

def get_queryset(self, request) -> QuerySet:
"""Limit modeladmin queryset for the current site only"""
qs = super().get_queryset(request)
Expand Down
23 changes: 0 additions & 23 deletions edc_sites/apps.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
import sys

from django.apps import AppConfig as DjangoAppConfig
from django.core.management.color import color_style
from django.db.models.signals import post_migrate

from .site import get_autodiscover_sites, sites

style = color_style()


def post_migrate_update_sites(sender=None, **kwargs):
from edc_sites.utils import add_or_update_django_sites

sys.stdout.write(style.MIGRATE_HEADING("Updating sites:\n"))

for country in sites.countries:
sys.stdout.write(style.MIGRATE_HEADING(f" (*) sites for {country} ...\n"))
add_or_update_django_sites(verbose=True)
sys.stdout.write("Done.\n")
sys.stdout.flush()


class AppConfig(DjangoAppConfig):
name = "edc_sites"
verbose_name = "Edc Sites"
has_exportable_data = True
default_auto_field = "django.db.models.BigAutoField"
include_in_administration_section = True

def ready(self):
if get_autodiscover_sites():
post_migrate.connect(post_migrate_update_sites, sender=self)
sys.stdout.write(f"Loading {self.verbose_name} ...\n")
sites.autodiscover()
18 changes: 18 additions & 0 deletions edc_sites/post_migrate_signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys

from django.core.management.color import color_style

style = color_style()


def post_migrate_update_sites(sender=None, **kwargs):
from .site import sites as site_sites
from .utils import add_or_update_django_sites

sys.stdout.write(style.MIGRATE_HEADING("Updating sites:\n"))

for country in site_sites.countries:
sys.stdout.write(style.MIGRATE_HEADING(f" (*) sites for {country} ...\n"))
add_or_update_django_sites(verbose=True)
sys.stdout.write("Done.\n")
sys.stdout.flush()
6 changes: 2 additions & 4 deletions edc_sites/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,14 @@ def autodiscover(self, module_name=None, verbose=True):
module_name = module_name or "sites"
writer = sys.stdout.write if verbose else lambda x: x
style = color_style()
writer(f" * checking for {module_name} ...\n")
writer(f" * checking for {module_name} (edc_sites)...\n")
for app in django_apps.app_configs:
writer(f" * searching {app} \r")
try:
mod = import_module(app)
try:
before_import_registry = deepcopy(sites._registry)
import_module(f"{app}.{module_name}")
writer(f" * registered '{module_name}' from '{app}'\n")
writer(f" - registered '{module_name}' from '{app}'\n")
except SitesError as e:
writer(f" - loading {app}.{module_name} ... ")
writer(style.ERROR(f"ERROR! {e}\n"))
Expand All @@ -377,7 +376,6 @@ def autodiscover(self, module_name=None, verbose=True):
raise SitesError(str(e))
except ImportError:
pass
writer(f" Done loading {module_name}.\n")


sites = Sites()
11 changes: 9 additions & 2 deletions edc_sites/system_checks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django.core.checks import Error, register
from django.core.checks import Error

from edc_sites.site import SitesCheckError, sites


@register()
def sites_check(app_configs, **kwargs): # noqa
errors = []
try:
Expand All @@ -17,4 +16,12 @@ def sites_check(app_configs, **kwargs): # noqa
id="edc_sites.E001",
)
)
if not sites.all():
errors.append(
Error(
"No sites have been registered",
id="edc_sites.E002",
)
)

return errors
2 changes: 1 addition & 1 deletion edc_sites/utils/get_user_codenames_or_raise.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import TYPE_CHECKING

from edc_auth.auth_objects import ACCOUNT_MANAGER_ROLE
from edc_auth.constants import ACCOUNT_MANAGER_ROLE
from edc_auth.utils import get_codenames_for_role

if TYPE_CHECKING:
Expand Down
27 changes: 21 additions & 6 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
from pathlib import Path

from edc_constants.constants import IGNORE
from edc_test_utils import DefaultTestSettings, func_main

app_name = "edc_sites"
Expand All @@ -19,7 +18,14 @@
APP_NAME=app_name,
SITE_ID=10,
EDC_SITES_MODULE_NAME="edc_sites.tests.sites",
EDC_NAVBAR_VERIFY_ON_LOAD=IGNORE,
SILENCED_SYSTEM_CHECKS=[
"sites.E101",
"edc_navbar.E002",
"edc_navbar.E003",
"edc_consent.E001",
"edc_sites.E001",
"edc_sites.E002",
],
SUBJECT_VISIT_MODEL="edc_visit_tracking.subjectvisit",
INSTALLED_APPS=[
"django.contrib.admin",
Expand All @@ -29,21 +35,30 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sites",
"django_crypto_fields",
"edc_auth.apps.AppConfig",
"multisite",
"django_crypto_fields.apps.AppConfig",
"django_revision.apps.AppConfig",
"edc_action_item.apps.AppConfig",
"edc_appointment.apps.AppConfig",
"edc_auth.apps.AppConfig",
"edc_dashboard.apps.AppConfig",
"edc_data_manager.apps.AppConfig",
"edc_facility.apps.AppConfig",
"edc_form_runners.apps.AppConfig",
"edc_lab.apps.AppConfig",
"edc_list_data.apps.AppConfig",
"edc_listboard.apps.AppConfig",
"edc_metadata.apps.AppConfig",
"edc_navbar.apps.AppConfig",
"edc_notification.apps.AppConfig",
"edc_registration.apps.AppConfig",
"edc_review_dashboard.apps.AppConfig",
"edc_screening.apps.AppConfig",
"edc_sites.apps.AppConfig",
"edc_subject_dashboard.apps.AppConfig",
"edc_visit_schedule.apps.AppConfig",
"edc_visit_tracking.apps.AppConfig",
"multisite",
"edc_sites",
"edc_appconfig.apps.AppConfig",
],
USE_I18N=True,
USE_L10N=True,
Expand Down

0 comments on commit 12afb62

Please sign in to comment.