Simple classes related to the django sites framework for clinicedc projects.
Project description
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.
# sites.py
from edc_sites.single_site import SingleSite
fqdn = "example.clinicedc.org"
meta_sites = (
SingleSite(
10,
"hindu_mandal",
title="Hindu Mandal Hospital",
country="tanzania",
country_code="tz",
domain=f"hindu_mandal.tz.{fqdn}",
),
SingleSite(
20,
"amana",
title="Amana Hospital",
country="tanzania",
country_code="tz",
domain=f"hindu_mandal.tz.{fqdn}",
),
)
Register a post_migrate signal in apps.py to update the django model Site and the EDC model SiteProfile on the next migration:
# apps.py
from .sites import meta_sites, fqdn
def post_migrate_update_sites(sender=None, **kwargs):
from edc_sites.add_or_update_django_sites import add_or_update_django_sites
sys.stdout.write(style.MIGRATE_HEADING("Updating sites:\n"))
add_or_update_django_sites(
apps=django_apps, sites=meta_sites, fqdn=fqdn, verbose=True
)
sys.stdout.write("Done.\n")
sys.stdout.flush()
For another deployment, we have alot of sites spread out over a few countries. In this case we pass a dictionary and separate the lists of sites by country.
For example:
fqdn = "inte.clinicedc.org"
all_sites = {
"tanzania":(
SingleSite(
101,
"hindu_mandal",
title="Hindu Mandal Hospital",
country="tanzania",
country_code="tz",
domain=f"hindu_mandal.tz.{fqdn}",
),
SingleSite(
102,
"amana",
title="Amana Hospital",
country="tanzania",
country_code="tz",
domain=f"hindu_mandal.tz.{fqdn}",
),
),
"uganda":(
SingleSite(
201,
"kojja",
country="uganda",
country_code="ug",
domain=f"kojja.ug.{fqdn}",
),
SingleSite(
202,
"mbarara",
country="uganda",
country_code="ug",
domain=f"mbarara.ug.{fqdn}",
),
),
}
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file edc_sites-0.3.3-py3-none-any.whl
.
File metadata
- Download URL: edc_sites-0.3.3-py3-none-any.whl
- Upload date:
- Size: 28.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3867677ae32634f679f1b0a32809fe32d797a2c70cee5fcb0aaa5e6d1bfec6a1 |
|
MD5 | a1a262137dfd51855617519447f85dfc |
|
BLAKE2b-256 | f621593d7cfc58cf495694dc117a58ca2be56dd6a235005d016bfd32697410a6 |