Package: django-yunohost-integration
django_yunohost_integrationPython packagedjango_yunohost_integrationwith helpers for integrate a Django project as YunoHost package.A example usage of this package is here:https://github.com/YunoHost-Apps/django_example_ynhPull requests welcome ;)These projects useddjango_yunohost_integration:https://github.com/YunoHost-Apps/pyinventory_ynhhttps://github.com/YunoHost-Apps/django-for-runners_ynhhttps://github.com/YunoHost-Apps/django-fmd_ynhFeaturesSSOwat integration (see below)Helper to create first super user forscripts/installRun Django development server with a local generated YunoHost package installation (calledlocal_test)Helper to 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:frompathlibimportPathas__Pathfromdjango_yunohost_integration.base_settingsimport*# noqafromdjango_yunohost_integration.secret_keyimportget_or_create_secretas__get_or_create_secretDEBUG=bool(int('__DEBUG_ENABLED__'))# Set via config_panel.toml# -----------------------------------------------------------------------------DATA_DIR_PATH=__Path('__DATA_DIR__')# /home/yunohost.app/$appassertDATA_DIR_PATH.is_dir(),f'Directory not exists:{DATA_DIR_PATH}'INSTALL_DIR_PATH=__Path('__INSTALL_DIR__')# /var/www/$appassertINSTALL_DIR_PATH.is_dir(),f'Directory not exists:{INSTALL_DIR_PATH}'LOG_FILE=__Path('__LOG_FILE__')# /var/log/$app/$app.logassertLOG_FILE.is_file(),f'File not exists:{LOG_FILE}'PATH_URL='__PATH_URL__'# $YNH_APP_ARG_PATHPATH_URL=PATH_URL.strip('/')# -----------------------------------------------------------------------------# Function that will be called to finalize a user profile:YNH_SETUP_USER='setup_user.setup_project_user'SECRET_KEY=__get_or_create_secret(DATA_DIR_PATH/'secret.txt')# /home/yunohost.app/$app/secret.txt# INSTALLED_APPS.append('<insert-your-app-here>')# -----------------------------------------------------------------------------At least you have to set these settings:fromdjango_yunohost_integration.base_settingsimport*# noqaINSTALLED_APPS.append('django_yunohost_integration')MIDDLEWARE.insert(MIDDLEWARE.index('django.contrib.auth.middleware.AuthenticationMiddleware')+1,# 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 superuserAUTHENTICATION_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=NoneLOGIN_URL='/yunohost/sso/'LOGOUT_REDIRECT_URL='/yunohost/sso/'# /yunohost/sso/?action=logoutROOT_URLCONF='urls'# .../conf/urls.pylocal testBuild prerequisitesWe installpsycopg2(a PostgreSQL adapter for the Python) that needs some build prerequisites, e.g.:~$sudoaptinstallbuild-essentialpython3-devlibpq-devFor 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.:~$gitclonehttps://github.com/YunoHost-Apps/django_yunohost_integration.git
~$cddjango_yunohost_integration/
~/django_yunohost_integration$./dev-cli.pyFor 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$./dev-cli.pylocal-testSQlite database will be usedA super user with usernametestand passwordtestis createdThe page is available underhttp://127.0.0.1:8000/app_path/historydevtbcv0.7.0 - 22.12.2023Fix:TypeError: SSOwatUserBackend.configure_user() got an unexpected keyword argument 'created'Update project setupRemove Python v3.9 support!v0.6.0 - 22.08.2023Update to YunoHost "Manifest v2"Replace devshell with a click CLI & replace pytest with normal unittestsv0.5.2 - 19.02.2023Migrate to "YunoHost Manifest v2":OLD:FINALPATH/__FINALPATH__-> NEW:DATA_DIR_PATH/__DATA_DIR__OLD:PUBLIC_PATH/__PUBLIC_PATH__-> NEW:INSTALL_DIR_PATH/__INSTALL_DIR__local tests tries to readmanifest.tomlinstead of oldmanifest.jsonRenamecli.pytodev-cli.pyv0.5.2 - 19.02.2023Update the projec setup a little bit via manageprojectsSupport Django 4.0 and 4.1 (backportRedirectURLMixinfor 4.0 from 4.1)v0.5.1 - 21.12.2022Skip versions check in Github actions to avoid the rate limit in pipelines ;)v0.5.0 - 21.12.2022AddSSOwatLoginRedirectViewSet min. Python version from 3.7 to 3.9 (Needs YunoHost 11!)Display logs in local tests and usecolorlog.StreamHandlerBugfix example url patternCode cleanup: Removerequest_media_debug_viewv0.4.1 - 04.10.2022Addassert_project_versionandget_github_version_tagintest_utilsv0.4.0 - 15.09.2022AddSyslogHandlerto logging settings and enhance logging example settings.rename replacements (but still support the old ones):__FINAL_HOME_PATH__->__FINALPATH____FINAL_WWW_PATH__->__PUBLIC_PATH__Add system checks to verify all "EMAIL" insettingsandsettings.LOG_LEVELBugfix dev shell and exit if it's called as CLIRun "saftey" check in CIv0.3.0 - 14.08.2022Addextra_replacements:dictargument tocreate_local_test()to pass own__YNH_VARIABLE__replacementsRemovepytest_helper.run_pytest()because every project should used a ownconftest.pywithcreate_local_test()usage.v0.2.5 - 12.08.2022Support new variable names, forynh_add_configusage in local test helper.Run tests with Python v3.10, too.Update project setup.v0.2.4 - 30.01.2022Rename git "master" branch to "main"Use darker and pytest-darker as code formatter + update requirementsv0.2.3 - 07.01.2022Bugfix Fix local test by set"SECURE_SSL_REDIRECT = False"v0.2.2 - 10.10.2021Read YunoHost App Id from "manifest.json" and check root directory namev0.2.1 - 16.09.2021Bugfix endless redirect loop, by addingSECURE_PROXY_SSL_HEADERto settingsv0.2.0 - 15.09.2021rename/splitdjango_ynhinto: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 YunoHostReplacepsycopg2-binarywithpsycopg2(needs some prerequisites packages, see above)v0.1.5 - 19.01.2021Make some depsgunicorn,psycopg2-binary,django-redis,django-axesoptionalv0.1.4 - 08.01.2021Bugfix: CSRF verification failed on POST requestsv0.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_yunohost_integration" 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_yunohost_integrationYunoHost website:https://yunohost.org/PyPi package:https://pypi.org/project/django_yunohost_integration/