Skip to main content

Simple classes related to the django sites framework for clinicedc projects

Project description

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.

# sites.py
from edc_sites.single_site import SingleSite

    fqdn = "example.clinicedc.org"

    all_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 all_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=all_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 Distribution

edc-sites-0.3.32.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

edc_sites-0.3.32-py3-none-any.whl (38.6 kB view details)

Uploaded Python 3

File details

Details for the file edc-sites-0.3.32.tar.gz.

File metadata

  • Download URL: edc-sites-0.3.32.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for edc-sites-0.3.32.tar.gz
Algorithm Hash digest
SHA256 9c528a4425af6432d9edb86861d1b8ee19c8e70f3040fe0883643f6360045909
MD5 f90434beaddd2f9136124c3ad308766b
BLAKE2b-256 e414e034fb2bb6b4baa1b10150d5e00b460f5ae162ef1783d94f3bc802ccbe8c

See more details on using hashes here.

File details

Details for the file edc_sites-0.3.32-py3-none-any.whl.

File metadata

  • Download URL: edc_sites-0.3.32-py3-none-any.whl
  • Upload date:
  • Size: 38.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for edc_sites-0.3.32-py3-none-any.whl
Algorithm Hash digest
SHA256 5afbab3f1cd97c14fb019e251db1113219f2bc3df7a213710eaf61af4520d7dc
MD5 6e1da62f0e4d5cc88e38436145f86079
BLAKE2b-256 fe48f6a71f916d3ace9d29747ecdfefe089f85b9dfe2b097d379f9021ee02cfa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page