Package: django-ynh
django_ynhGlue code to package django projects as yunohost apps.This repository is:The Python packagedjango-ynhwith helpers for integrate a Django project as YunoHost packageA exampleYunoHost Applicationthat can be installedPull requests welcome ;)FeaturesSSOwat integration (see below)Helper to create first super user forscripts/installRun Django development server with a local generated YunoHost package installation (calledlocal_test)Runpytestagainstlocal_test"installation"SSO authenticationSSOwatis fully supported:First user ($YNH_APP_ARG_ADMIN) will be created as Django's super userAll new users will be created as normal usersLogin via SSO is fully supportedUser Email, First / Last name will be updated from SSO datausageTo create/update the first user ininstall/upgrade, e.g.:./manage.pycreate_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 insettings.py:fromdjango_ynh.secret_keyimportget_or_create_secretas__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.txtINSTALLED_APPS=[#...'django_ynh',#...]MIDDLEWARE=[#... after AuthenticationMiddleware ...## login a user via HTTP_REMOTE_USER header from SSOwat:'django_ynh.sso_auth.auth_middleware.SSOwatRemoteUserMiddleware',#...]# Keep ModelBackend around for per-user permissions and superuserAUTHENTICATION_BACKENDS=('axes.backends.AxesBackend',# AxesBackend should be the first backend!## Authenticate via SSO and nginx 'HTTP_REMOTE_USER' header:'django_ynh.sso_auth.auth_backend.SSOwatUserBackend',## Fallback to normal Django model backend:'django.contrib.auth.backends.ModelBackend',)LOGIN_REDIRECT_URL=NoneLOGIN_URL='/yunohost/sso/'LOGOUT_REDIRECT_URL='/yunohost/sso/'local testFor quicker developing of django_ynh 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.:~$gitclonehttps://github.com/YunoHost-Apps/django_ynh.git
~$cddjango_ynh/
~/django_ynh$make
install-poetryinstallorupdatepoetry
installinstallprojectviapoetry
updateupdatethesourcesandinstallationandgenerate"conf/requirements.txt"lintRuncodeformattersandlinter
fix-code-styleFixcodeformatting
tox-listenvsListalltoxtestenvironments
toxRunpytestviatoxwithallenvironments
pytestRunpytest
publishReleasenewversiontoPyPi
local-testRunlocal_test.pytoruntheprojectlocally
local-diff-settingsRun"manage.py diffsettings"withlocaltest~/django_ynh$makeinstall-poetry
~/django_ynh$makeinstall
~/django_ynh$makelocal-testNotes:SQlite database will be usedA super user with usernametestand passwordtestis createdThe page is available underhttp://127.0.0.1:8000/app_path/historycompare v0.1.5...masterdevtbcv0.1.5 - 19.01.2021Make some depsgunicorn,psycopg2-binary,django-redis,django-axesoptionalv0.1.4 - 08.01.2021BugfixCSRF verification failed on POST requests #7v0.1.3 - 08.01.2021set "DEBUG = True" in local_test (so static files are served and auth works)Bugfixes and cleanupsv0.1.2 - 29.12.2020Bugfixesv0.1.1 - 29.12.2020Refactor "create_superuser" to a manage command, useable via "django_ynh" inINSTALLED_APPSGenerate "conf/requirements.txt" and use this file for installrename own settings and urls (in/conf/)v0.1.0 - 28.12.2020first working state23.12.2020init the projectLinksReport a bug about this package:https://github.com/YunoHost-Apps/django_ynhYunoHost website:https://yunohost.org/PyPi package:https://pypi.org/project/django-ynh/These projects useddjango_ynh:https://github.com/YunoHost-Apps/pyinventory_ynhhttps://github.com/YunoHost-Apps/django-for-runners_ynhDeveloper infopackage installation / debuggingPlease send your pull request tohttps://github.com/YunoHost-Apps/django_ynhTry 'main' branch, e.g.:sudoyunohostappinstallhttps://github.com/YunoHost-Apps/django_ynh/tree/master--debug
or
sudoyunohostappupgradedjango_ynh-uhttps://github.com/YunoHost-Apps/django_ynh/tree/master--debugTry 'testing' branch, e.g.:sudoyunohostappinstallhttps://github.com/YunoHost-Apps/django_ynh/tree/testing--debug
or
sudoyunohostappupgradedjango_ynh-uhttps://github.com/YunoHost-Apps/django_ynh/tree/testing--debugTo remove call e.g.:sudoyunohostappremovedjango_ynhBackup / remove / restore cycle, e.g.:yunohostbackupcreate--appsdjango_ynh
yunohostbackuplist
archives:-django_ynh-pre-upgrade1-20201223-163434
yunohostappremovedjango_ynh
yunohostbackuprestore20201223-163434--appsdjango_ynhDebug installation, e.g.:root@yunohost:~#ls-la/var/www/django_ynh/
total18drwxr-xr-x4rootroot4Dec808:36.
drwxr-xr-x6rootroot6Dec808:36..
drwxr-xr-x2rootroot2Dec808:36media
drwxr-xr-x7rootroot8Dec808:40static

root@yunohost:~#ls-la/opt/yunohost/django_ynh/
total58drwxr-xr-x5django_ynhdjango_ynh11Dec808:39.
drwxr-xr-x3rootroot3Dec808:36..
-rw-r--r--1django_ynhdjango_ynh460Dec808:39gunicorn.conf.py
-rw-r--r--1django_ynhdjango_ynh0Dec808:39local_settings.py
-rwxr-xr-x1django_ynhdjango_ynh274Dec808:39manage.py
-rw-r--r--1django_ynhdjango_ynh171Dec808:39secret.txt
drwxr-xr-x6django_ynhdjango_ynh6Dec808:37venv
-rw-r--r--1django_ynhdjango_ynh115Dec808:39wsgi.py
-rw-r--r--1django_ynhdjango_ynh4737Dec808:39django_ynh_demo_settings.py

root@yunohost:~#cd/opt/yunohost/django_ynh/
root@yunohost:/opt/yunohost/django_ynh#sourcevenv/bin/activate(venv)root@yunohost:/opt/yunohost/django_ynh#./manage.pycheck
django_ynhv0.8.2(Djangov2.2.17)DJANGO_SETTINGS_MODULE='django_ynh_demo_settings'PROJECT_PATH:/opt/yunohost/django_ynh/venv/lib/python3.7/site-packages
BASE_PATH:/opt/yunohost/django_ynh
Systemcheckidentifiednoissues(0silenced).

root@yunohost:~#tail-f/var/log/django_ynh/django_ynh.log
root@yunohost:~#cat/etc/systemd/system/django_ynh.service

root@yunohost:~#systemctlreload-or-restartdjango_ynh
root@yunohost:~#journalctl--unit=django_ynh--follow