Name | ichec-django-core JSON |
Version |
0.0.4
JSON |
| download |
home_page | None |
Summary | Library of base Django app building blocks and utilities. |
upload_time | 2025-08-26 08:31:23 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | None |
keywords |
web application
django
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# ICHEC Django Core #
This is a set of Django application building blocks and utilities for use at ICHEC. They can be used to build and test other Django apps.
Useful elements include:
* A common collection of Django Settings for use in consuming projects, intended to provide secure defaults:
``` python
from ichec_django_core import settings
MY_DJANGO_SETTING = settings.MY_DJANGO_SETTING
```
* Core functionality for authentication, including:
* models of portal members and organizations
* OpenID Connect integration
* Functionality for handling user provided media and subsequent access in a secure and performant way
* Tested, re-usable components
# Usage #
This guide assumes you are comfortable building a basic Django app - if not you should create one first following the [Getting Started with Django guide](https://www.djangoproject.com/start/).
You can include this project `ichec-django-core` as a Python package in your `requirements.txt` or `pyproject.toml`.
## Example project ##
The [app](./app) directory is an example use of the module to build a minimal portal. Note that there's not much code involved, `ichec-django-core` has enough defaults to get somethings basic running.
You are encoouraged to try it our before proceeding with the rest of the guide. You can do:
``` shell
git clone https://git.ichec.ie/platform-engineering/ichec-django-core.git
python -m venv .venv
source .venv/bin/activate
pip install .
source infra/set_dev_environment.sh
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser --no-input
python manage.py runserver
```
and open http:://localhost:8000 in your browser to check it out.
## Including default settings ##
The module will define some sensible default Django settings, leaving you to only define a few for a basic portal. See the sample settings in the [app](./app) directory:
``` python
from pathlib import Path
from ichec_django_core import settings
from ichec_django_core.settings import *
BASE_DIR = Path(__file__).resolve().parent.parent
ROOT_URLCONF = "app.urls"
WSGI_APPLICATION = "app.wsgi.application"
ASGI_APPLICATION = "app.asgi.application"
TEMPLATES = settings.get_templates(BASE_DIR)
DATABASES = settings.get_databases(BASE_DIR)
STATIC_ROOT = settings.get_static_root(BASE_DIR)
MEDIA_ROOT = settings.get_media_root(BASE_DIR)
```
Of course - if you need something different from the default `ichec-django-core` values you can override them in your own settings file.
The settings values in `ichec-django-core` come from evironment variables. It is most convenient to keep a development version of these variables in a text file and then load them into your shell environment when working with the server. The [infra](./infra) directory shows an example of how to do this. We keep variables in a `dev.txt` file and use the shell script `set_dev_environment.sh` to load them using:
``` shell
source infra/set_dev_environment.sh
```
. In production, these values may be passed into a container using a `.env` file or via the container orchestration environment (e.g. compose files).
## Including Urls ##
The module comes with some useful default Django and Django Rest Framework (DRF) default views, such as for admin and user and organisation management.
To include them, using the [app](./app) directory as an example, you can do:
``` python
from django.urls import include, path
from django.views.generic.base import RedirectView
from rest_framework import routers
from ichec_django_core.urls import register_drf_views
router = routers.DefaultRouter()
register_drf_views(router)
urlpatterns = [
path("api/", include(router.urls)),
path("", include("ichec_django_core.urls")),
path("", RedirectView.as_view(url='/api', permanent=True), name='index'),
]
```
This is a slightly non-standard approach for Django apps. Here we are creating a top-level DRF router and registering the `ichec_django_core` DRF API views with it. This approach allows for easier composition of DRF views from different modules.
We are using the standard Django approach to include the Django Views, namely ` path("", include("ichec_django_core.urls")),`.
The remaining view is a boilerplate redirect since the example doesn't come with an 'index.html' template and directs straight to the DRF landing instead.
## Using OpenID Connect ##
The module has basic user managment and authentication built-in, however you likely want this to be handled in a more suitable application or want to include the portal in a Single-Sign-On framework. This can be handled using OAuth 2.0 and OpenID Connect.
To set this up we first need to register our app as a client in an OIDC provider. ICHEC uses Keycloak so will focus on it in the guide, but the module itself is agnostic of the particulars of the provider.
Once the client has been registered you can set the following environment variables:
``` shell
WITH_OIDC=1
OIDC_RP_CLIENT_ID=xxx
OIDC_RP_CLIENT_SECRET=xxx
OIDC_OP_AUTHORIZATION_ENDPOINT=xxx
OIDC_OP_TOKEN_ENDPOINT=xxx
OIDC_OP_USER_ENDPOINT=xxx
OIDC_OP_JWKS_ENDPOINT=xxx
```
using [this guide](https://mozilla-django-oidc.readthedocs.io/en/stable/installation.html) as a reference. You can look at [infra/dev.txt](./infra/dev.txt) as an example if running a local Keycloak provider, just the client ID and secret need to be changed.
# Licensing #
This software is copyright of the Irish Centre for High End Computing (ICHEC). It may be used under the terms of the GNU AGPL version 3 or later, with license details in the included `LICENSE` file. Exemptions are available for Marinerg project partners and possibly others on request.
Raw data
{
"_id": null,
"home_page": null,
"name": "ichec-django-core",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "Web Application, Django",
"author": null,
"author_email": "Irish Centre for High End Computing <platformengineering@ichec.ie>",
"download_url": "https://files.pythonhosted.org/packages/86/17/7175b44120c355ff11123fecdcb5268ec72fa1393b487f6452d704163e9d/ichec_django_core-0.0.4.tar.gz",
"platform": null,
"description": "# ICHEC Django Core #\n\nThis is a set of Django application building blocks and utilities for use at ICHEC. They can be used to build and test other Django apps.\n\nUseful elements include:\n\n* A common collection of Django Settings for use in consuming projects, intended to provide secure defaults:\n\n``` python\nfrom ichec_django_core import settings\n\nMY_DJANGO_SETTING = settings.MY_DJANGO_SETTING\n```\n\n* Core functionality for authentication, including:\n * models of portal members and organizations \n * OpenID Connect integration\n\n* Functionality for handling user provided media and subsequent access in a secure and performant way\n\n* Tested, re-usable components\n\n# Usage #\n\nThis guide assumes you are comfortable building a basic Django app - if not you should create one first following the [Getting Started with Django guide](https://www.djangoproject.com/start/).\n\nYou can include this project `ichec-django-core` as a Python package in your `requirements.txt` or `pyproject.toml`.\n\n## Example project ##\n\nThe [app](./app) directory is an example use of the module to build a minimal portal. Note that there's not much code involved, `ichec-django-core` has enough defaults to get somethings basic running.\n\nYou are encoouraged to try it our before proceeding with the rest of the guide. You can do:\n\n``` shell\ngit clone https://git.ichec.ie/platform-engineering/ichec-django-core.git\npython -m venv .venv\nsource .venv/bin/activate\npip install .\nsource infra/set_dev_environment.sh\npython manage.py makemigrations\npython manage.py migrate\npython manage.py createsuperuser --no-input\npython manage.py runserver\n```\n\nand open http:://localhost:8000 in your browser to check it out.\n\n\n## Including default settings ##\n\nThe module will define some sensible default Django settings, leaving you to only define a few for a basic portal. See the sample settings in the [app](./app) directory:\n\n``` python\nfrom pathlib import Path\n\nfrom ichec_django_core import settings\nfrom ichec_django_core.settings import *\n\nBASE_DIR = Path(__file__).resolve().parent.parent\n\nROOT_URLCONF = \"app.urls\"\nWSGI_APPLICATION = \"app.wsgi.application\"\nASGI_APPLICATION = \"app.asgi.application\"\n\nTEMPLATES = settings.get_templates(BASE_DIR)\nDATABASES = settings.get_databases(BASE_DIR)\n\nSTATIC_ROOT = settings.get_static_root(BASE_DIR)\nMEDIA_ROOT = settings.get_media_root(BASE_DIR)\n```\n\nOf course - if you need something different from the default `ichec-django-core` values you can override them in your own settings file.\n\nThe settings values in `ichec-django-core` come from evironment variables. It is most convenient to keep a development version of these variables in a text file and then load them into your shell environment when working with the server. The [infra](./infra) directory shows an example of how to do this. We keep variables in a `dev.txt` file and use the shell script `set_dev_environment.sh` to load them using:\n\n``` shell\nsource infra/set_dev_environment.sh\n```\n\n. In production, these values may be passed into a container using a `.env` file or via the container orchestration environment (e.g. compose files).\n\n## Including Urls ##\n\nThe module comes with some useful default Django and Django Rest Framework (DRF) default views, such as for admin and user and organisation management.\n\nTo include them, using the [app](./app) directory as an example, you can do:\n\n``` python\nfrom django.urls import include, path\nfrom django.views.generic.base import RedirectView\nfrom rest_framework import routers\n\nfrom ichec_django_core.urls import register_drf_views\n\nrouter = routers.DefaultRouter()\nregister_drf_views(router)\n\nurlpatterns = [\n path(\"api/\", include(router.urls)),\n path(\"\", include(\"ichec_django_core.urls\")),\n path(\"\", RedirectView.as_view(url='/api', permanent=True), name='index'),\n]\n```\n\nThis is a slightly non-standard approach for Django apps. Here we are creating a top-level DRF router and registering the `ichec_django_core` DRF API views with it. This approach allows for easier composition of DRF views from different modules.\n\nWe are using the standard Django approach to include the Django Views, namely ` path(\"\", include(\"ichec_django_core.urls\")),`.\n\nThe remaining view is a boilerplate redirect since the example doesn't come with an 'index.html' template and directs straight to the DRF landing instead.\n\n## Using OpenID Connect ##\n\nThe module has basic user managment and authentication built-in, however you likely want this to be handled in a more suitable application or want to include the portal in a Single-Sign-On framework. This can be handled using OAuth 2.0 and OpenID Connect.\n\nTo set this up we first need to register our app as a client in an OIDC provider. ICHEC uses Keycloak so will focus on it in the guide, but the module itself is agnostic of the particulars of the provider.\n\nOnce the client has been registered you can set the following environment variables:\n\n``` shell\nWITH_OIDC=1\nOIDC_RP_CLIENT_ID=xxx\nOIDC_RP_CLIENT_SECRET=xxx\nOIDC_OP_AUTHORIZATION_ENDPOINT=xxx\nOIDC_OP_TOKEN_ENDPOINT=xxx\nOIDC_OP_USER_ENDPOINT=xxx\nOIDC_OP_JWKS_ENDPOINT=xxx\n```\n\nusing [this guide](https://mozilla-django-oidc.readthedocs.io/en/stable/installation.html) as a reference. You can look at [infra/dev.txt](./infra/dev.txt) as an example if running a local Keycloak provider, just the client ID and secret need to be changed.\n\n\n# Licensing #\n\nThis software is copyright of the Irish Centre for High End Computing (ICHEC). It may be used under the terms of the GNU AGPL version 3 or later, with license details in the included `LICENSE` file. Exemptions are available for Marinerg project partners and possibly others on request.\n",
"bugtrack_url": null,
"license": null,
"summary": "Library of base Django app building blocks and utilities.",
"version": "0.0.4",
"project_urls": {
"Homepage": "https://git.ichec.ie/platform-engineering/ichec-django-core",
"Repository": "https://git.ichec.ie/platform-engineering/ichec-django-core"
},
"split_keywords": [
"web application",
" django"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "c4d66f413ae0f843e8af381f1879fa6c457bf588dd63da105bd7dfe4e418f485",
"md5": "862103d606e4db6abbe8f70d747015ac",
"sha256": "cb2935a812243170f6b6d7c12b8fe96bbc6f016bd07e1e79dac1c813713ee57b"
},
"downloads": -1,
"filename": "ichec_django_core-0.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "862103d606e4db6abbe8f70d747015ac",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 32529,
"upload_time": "2025-08-26T08:31:22",
"upload_time_iso_8601": "2025-08-26T08:31:22.358417Z",
"url": "https://files.pythonhosted.org/packages/c4/d6/6f413ae0f843e8af381f1879fa6c457bf588dd63da105bd7dfe4e418f485/ichec_django_core-0.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "86177175b44120c355ff11123fecdcb5268ec72fa1393b487f6452d704163e9d",
"md5": "426721ba230567b71008aaae5697dba2",
"sha256": "33fc6caa5b050cd24bb77e0483c31c49579b90078a162738f175e435ab88ddac"
},
"downloads": -1,
"filename": "ichec_django_core-0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "426721ba230567b71008aaae5697dba2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 31305,
"upload_time": "2025-08-26T08:31:23",
"upload_time_iso_8601": "2025-08-26T08:31:23.795794Z",
"url": "https://files.pythonhosted.org/packages/86/17/7175b44120c355ff11123fecdcb5268ec72fa1393b487f6452d704163e9d/ichec_django_core-0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-26 08:31:23",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "ichec-django-core"
}