Glue code to package django projects as yunohost apps.
Project description
django_yunohost_integration
Python package django_yunohost_integration with helpers for integrate a Django project as YunoHost package.
A example usage of this package is here:
Pull requests welcome ;)
These projects used django_yunohost_integration
:
- https://github.com/YunoHost-Apps/pyinventory_ynh
- https://github.com/YunoHost-Apps/django-for-runners_ynh
Features
- SSOwat integration (see below)
- Helper to create first super user for
scripts/install
- Run Django development server with a local generated YunoHost package installation (called
local_test
) - Run
pytest
againstlocal_test
"installation"
SSO authentication
SSOwat is fully supported:
- First user (
$YNH_APP_ARG_ADMIN
) will be created as Django's super user - All new users will be created as normal users
- Login via SSO is fully supported
- User Email, First / Last name will be updated from SSO data
usage
To create/update the first user in install
/upgrade
, e.g.:
./manage.py create_superuser --username="$admin" --email="$admin_mail"
This Create/update Django superuser and set a unusable password. A password is not needed, because auth done via SSOwat ;)
Main parts in settings.py
:
from django_yunohost_integration.secret_key import get_or_create_secret as __get_or_create_secret
# Function that will be called to finalize a user profile:
YNH_SETUP_USER = 'setup_user.setup_project_user'
SECRET_KEY = __get_or_create_secret(FINAL_HOME_PATH / 'secret.txt') # /opt/yunohost/$app/secret.txt
INSTALLED_APPS = [
#...
'django_yunohost_integration',
#...
]
MIDDLEWARE = [
#... after AuthenticationMiddleware ...
#
# login a user via HTTP_REMOTE_USER header from SSOwat:
'django_yunohost_integration.sso_auth.auth_middleware.SSOwatRemoteUserMiddleware',
#...
]
# Keep ModelBackend around for per-user permissions and superuser
AUTHENTICATION_BACKENDS = (
'axes.backends.AxesBackend', # AxesBackend should be the first backend!
#
# Authenticate via SSO and nginx 'HTTP_REMOTE_USER' header:
'django_yunohost_integration.sso_auth.auth_backend.SSOwatUserBackend',
#
# Fallback to normal Django model backend:
'django.contrib.auth.backends.ModelBackend',
)
LOGIN_REDIRECT_URL = None
LOGIN_URL = '/yunohost/sso/'
LOGOUT_REDIRECT_URL = '/yunohost/sso/'
local test
For quicker developing of django_yunohost_integration in the context of YunoHost app, it's possible to run the Django developer server with the settings and urls made for YunoHost installation.
e.g.:
~$ git clone https://github.com/jedie/django_yunohost_integration.git
~$ cd django_yunohost_integration/
~/django_yunohost_integration$ make
install-poetry install or update poetry
install install project via poetry
update update the sources and installation and generate "conf/requirements.txt"
lint Run code formatters and linter
fix-code-style Fix code formatting
tox-listenvs List all tox test environments
tox Run pytest via tox with all environments
pytest Run pytest
publish Release new version to PyPi
local-test Run local_test.py to run the project locally
local-diff-settings Run "manage.py diffsettings" with local test
~/django_yunohost_integration$ make install-poetry
~/django_yunohost_integration$ make install
~/django_yunohost_integration$ make local-test
Notes:
- SQlite database will be used
- A super user with username
test
and passwordtest
is created - The page is available under
http://127.0.0.1:8000/app_path/
history
- compare v0.1.5...master dev
- tbc
- v0.2.0.alpha0 dev
- rename/split
django_ynh
into:django_yunohost_integration
- Python package with the glue code to integrate a Django project with YunoHostdjango_example_ynh
- Demo YunoHost App to demonstrate the integration of a Django project under YunoHost
- rename/split
- v0.1.5 - 19.01.2021
- Make some deps
gunicorn
,psycopg2-binary
,django-redis
,django-axes
optional
- Make some deps
- v0.1.4 - 08.01.2021
- v0.1.3 - 08.01.2021
- set "DEBUG = True" in local_test (so static files are served and auth works)
- Bugfixes and cleanups
- v0.1.2 - 29.12.2020
- Bugfixes
- v0.1.1 - 29.12.2020
- Refactor "create_superuser" to a manage command, useable via "django_yunohost_integration" in
INSTALLED_APPS
- Generate "conf/requirements.txt" and use this file for install
- rename own settings and urls (in
/conf/
)
- Refactor "create_superuser" to a manage command, useable via "django_yunohost_integration" in
- v0.1.0 - 28.12.2020
- first working state
- 23.12.2020
- init the project
Links
- Report a bug about this package: https://github.com/YunoHost-Apps/django_yunohost_integration
- YunoHost website: https://yunohost.org/
- PyPi package: https://pypi-hypernode.com/project/django_yunohost_integration/
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
Built Distribution
File details
Details for the file django_yunohost_integration-0.2.0a0.tar.gz
.
File metadata
- Download URL: django_yunohost_integration-0.2.0a0.tar.gz
- Upload date:
- Size: 25.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9acdf320537ccce47ceb1d51d2a00fafbf30938152d3b22c59a3a2ead7952227 |
|
MD5 | b34ec0a04b22a0016d314ec3416c0b13 |
|
BLAKE2b-256 | 8b82d2e398874d664ee0c449974b64c687d6e8d955501d059f6585530153764d |
Provenance
File details
Details for the file django_yunohost_integration-0.2.0a0-py3-none-any.whl
.
File metadata
- Download URL: django_yunohost_integration-0.2.0a0-py3-none-any.whl
- Upload date:
- Size: 27.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a45197a3c4595a496674e7e48a58f58351b6022526893264831e0d6ba463a44f |
|
MD5 | 67ccd92e9624b9fa905f06b2dc53f6c0 |
|
BLAKE2b-256 | 480a0574fc36f0e723da753abf8f05fb02b43fbd5eaf7357e4763af36361bbdc |