Skip to main content

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:

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 against local_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

Build prerequisites

We install psycopg2 (a PostgreSQL adapter for the Python) that needs some build prerequisites, e.g.:

~$ sudo apt install build-essential python3-dev libpq-dev

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$ ./devshell.py

+ .venv/bin/python .venv/bin/devshell



Developer shell - django_yunohost_integration - v0.2.0


Documented commands (use 'help -v' for verbose/'help <topic>' for details):

dev-shell commands
==================
fix_code_style  linting  list_venv_packages  publish  pytest  update


Django-YunoHost-Integration commands
====================================
local_test

Uncategorized
=============
alias  help     macro  run_pyscript  set    shortcuts
edit   history  quit   run_script    shell


(django_yunohost_integration)

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.:

~/django_yunohost_integration$ ./devshell.py
(django_yunohost_integration) local_test
  • SQlite database will be used
  • A super user with username test and password test is created
  • The page is available under http://127.0.0.1:8000/app_path/

history

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_yunohost_integration-0.2.2.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django_yunohost_integration-0.2.2.tar.gz.

File metadata

  • Download URL: django_yunohost_integration-0.2.2.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for django_yunohost_integration-0.2.2.tar.gz
Algorithm Hash digest
SHA256 5f6c02a9bffb90449a2bcefc8f75736da8731c4aea6c033b5c35ff8906b79424
MD5 8e5ab6391ffd77c51cc3fefa1eb6453d
BLAKE2b-256 d94838832cc5d7ce6ac10effbaa854b2de942568495e3145222f69488456a312

See more details on using hashes here.

Provenance

File details

Details for the file django_yunohost_integration-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: django_yunohost_integration-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 29.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for django_yunohost_integration-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e5290ea079bf0f340c73445b9655957fafa1dd4042ae8dcf3ace2f903fceda05
MD5 1f0ddf05ce033b184024a15674aadecf
BLAKE2b-256 2d97cfdb8153052c687fc9d8dbbacb3d29670f4086a2cb25983029fe44fe0103

See more details on using hashes here.

Provenance

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