Simple classes related to the django sites framework for clinicedc projects


Keywords
django, Edc, sites, clinicedc, clinical, trials
Licenses
xpp/MIT-feh
Install
pip install edc-sites==0.3.50

Documentation

pypi actions codecov downloads

edc-sites

Site definitions to work with Django's Sites Framework and django_multisite.

Define a sites.py. This is usually in a separate project module. For example, for project meta there is a module meta_sites that contains a sites.py.

Register your sites in sites.py.

A post_migrate signal is registered in apps.py to update the django model Site and the EDC model SiteProfile on the next migration:

Now in your code you can use the sites global to inspect the trial sites:

Take a look at the Sites class in edc_sites.site for more available methods.

For another deployment, we have alot of sites spread out over a few countries.

For example:

You can use the sites global to get the trial sites for a country:

In a multisite, multi-country deployment, managing the SITE_ID is complicated. We use django_multisite which nicely reads the SITE_ID from the url. django_multisite will extract kojja from https://kojja.ug.example.clinicedc.org to do a model lookup to get the SITE_ID.

Viewing data from multiple sites using view_auditallsites

The mixins provided byedc_sites limit the EDC to only present data linked to the current site. To expand access beyond the current site, edc_sites provides a special permission codename; view_auditallsites. If a user has this permission, they will be shown data from the current site plus any additional sites granted in their user profile.

The permission codename view_auditallsites cannot be allocated to a user with add/edit/delete permissions to ANY model in the system. That is, the permission codename view_auditallsites is reserved for VIEW ONLY access, e.g the AUDITOR_ROLE. The one exception is for edc_auth andauth models accessible to users granted ACCOUNT_MANAGER_ROLE permissions.

In your code, you can check if a user has access to more than just the current site using function may_view_other_sites:

To get a list of sites that the user has access to in the current request, use function get_view_only_site_ids_for_user.

Default Site and tests

Edc sites may be configured to register a default site. This may be useful for testing where you are not registering any sites manually or through autodiscover.

In settings:

EDC_SITES_REGISTER_DEFAULT=True

The default site id is 1.

If your tests depend on a test app that has a sites.py, you might need to set the SITE_ID in your tests.

Use the override_settings decorator on the test class or on a specific test.

For example: