将粘合代码打包为yunohost应用。
项目描述
django_yunohost_integration
Python包django_yunohost_integration,包含将Django项目集成为YunoHost包的帮助工具。
此包的示例用法在此
欢迎提交pull请求 ;)
以下项目使用了django_yunohost_integration
- https://github.com/YunoHost-Apps/pyinventory_ynh
- https://github.com/YunoHost-Apps/django-for-runners_ynh
- https://github.com/YunoHost-Apps/django-fmd_ynh
功能
- SSOwat集成(见下文)
- 为
scripts/install
创建第一个超级用户的帮助工具 - 使用本地生成的YunoHost包安装(称为
local_test
)运行Django开发服务器 - 运行针对
local_test
"安装"的pytest
的辅助工具
SSO身份验证
SSOwat完全支持
- 第一个用户(
$YNH_APP_ARG_ADMIN
)将被创建为Django的超级用户 - 所有新用户都将被创建为普通用户
- 完全支持通过SSO登录
- 用户电子邮件、姓名和姓氏将从SSO数据更新
用法
在install
/upgrade
中创建/更新第一个用户,例如
./manage.py create_superuser --username="$admin" --email="$admin_mail"
创建/更新Django超级用户并设置一个不可用的密码。密码不是必需的,因为身份验证是通过SSOwat完成的 ;)
settings.py中的主要部分
from pathlib import Path as __Path
from django_yunohost_integration.base_settings import * # noqa
from django_yunohost_integration.secret_key import get_or_create_secret as __get_or_create_secret
DEBUG = bool(int('__DEBUG_ENABLED__')) # Set via config_panel.toml
# -----------------------------------------------------------------------------
DATA_DIR_PATH = __Path('__DATA_DIR__') # /home/yunohost.app/$app
assert DATA_DIR_PATH.is_dir(), f'Directory not exists: {DATA_DIR_PATH}'
INSTALL_DIR_PATH = __Path('__INSTALL_DIR__') # /var/www/$app
assert INSTALL_DIR_PATH.is_dir(), f'Directory not exists: {INSTALL_DIR_PATH}'
LOG_FILE = __Path('__LOG_FILE__') # /var/log/$app/$app.log
assert LOG_FILE.is_file(), f'File not exists: {LOG_FILE}'
PATH_URL = '__PATH_URL__' # $YNH_APP_ARG_PATH
PATH_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>')
# -----------------------------------------------------------------------------
至少您必须设置以下设置
from django_yunohost_integration.base_settings import * # noqa
INSTALLED_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 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/'
# /yunohost/sso/?action=logout
ROOT_URLCONF = 'urls' # .../conf/urls.py
本地测试
构建前提条件
例如,我们需要安装psycopg2
(Python的PostgreSQL适配器),它需要一些构建前提条件
~$ sudo apt install build-essential python3-dev libpq-dev
为了在YunoHost应用环境中快速开发django_yunohost_integration,可以运行Django开发服务器,使用为YunoHost安装设置的设置和urls。
例如
~$ git clone https://github.com/YunoHost-Apps/django_yunohost_integration.git
~$ cd django_yunohost_integration/
~/django_yunohost_integration$ ./dev-cli.py
为了在YunoHost应用环境中快速开发django_yunohost_integration,可以运行Django开发服务器,使用为YunoHost安装设置的设置和urls。
例如
~/django_yunohost_integration$ ./dev-cli.py local-test
- 将使用SQLite数据库
- 将创建一个用户名为
test
、密码为test
的超级用户 - 页面可在以下地址访问:
http://127.0.0.1:8000/app_path/
历史记录
- v0.8.1
- 2024-08-25 - 更新 assert_is_dir, assert_is_file 导入
- 2024-08-25 - 修复 README 中的 codecov.io 徽章
- 2024-08-25 - 修复 CI
- 2024-08-25 - 更新需求
- 2024-08-25 - 应用 manageprojects 更新
- v0.8.0
- 2024-08-04 - 解决方案:[https://github.com/jazzband/pip-tools/issues/1866](https://github.com/jazzband/pip-tools/issues/1866)
- 2024-08-04 - 修复本地 "manage.py" 辅助工具
- 2024-08-04 - 更新需求
- 2024-08-04 - 设置 Python 3.11 为最低版本
- 2024-08-04 - 添加 pre-commit 脚本
- 2024-08-04 - safety -> pip-audit
- 2024-08-04 - 'psycopg2' -> 'psycopg[binary]'
- 2024-08-04 - 使用 pre-commit 更新 README 中的历史记录
- 2024-08-04 - 应用 manageprojects 更新
- v0.7.1
- 2024-01-04 - 修复 create_local_test()
- v0.7.0
- 2023-12-22 - 修复发布
- 2023-12-22 - 更新项目设置
- 2023-12-22 - 修复:意外关键字参数 'created'
- 2023-08-22 - 更新 README.md
扩展更早的历史记录 ...
- v0.6.0
- 2023-08-22 - 更新 requeirements, README 并将版本提升到 v0.6.0
- 2023-08-20 - PATH_URL -> PATH
- 2023-08-20 - 更新测试
- 2023-08-20 - 在本地测试中将 DEBUG_ENABLED 替换为 "YES"
- 2023-08-20 - 更新到 YunoHost "Manifest v2"
- 2023-02-19 - 用 click CLI 替换 devshell 并用 normal unittests 替换 pytest
- v0.5.2
- 2023-02-19 - 支持 Django 4.0:添加 RedirectURLMixin 4.1 作为备用
- 2023-02-18 - 通过 manageprojects 更新
- v0.5.1
- 2022-12-21 - 在 GitHub actions 中禁用 assert_project_version
- v0.5.0
- 2022-12-21 - 包含 SSOwatLoginRedirectView
- 2022-10-19 - 项目升级
- 2022-10-07 - "-pytest-darker" -> 通过测试调用 darker
- 2022-10-05 - 更新
- v0.4.1
- 2022-10-04 - v0.4.1 添加
assert_project_version
和get_github_version_tag
- 2022-09-19 - 更新需求
- 2022-09-19 - README
- 2022-10-04 - v0.4.1 添加
- v0.4.0
- 2022-09-15 - 更新 django-tools 到 v0.54.0
- 2022-09-15 - 在 CI 中运行 "saftey" 检查
- 2022-09-15 - 更新项目设置测试
- 2022-09-15 - 更新需求并作为 v0.4.0rc6 发布
- 2022-09-15 - 测试中静默 "DEBUG=True" 警告
- 2022-09-15 - 删除自制的 assert_is_file() 和 assert_is_dir() 实现
- 2022-09-15 - 通过测试更新 devshell.py
- 2022-08-25 - v0.4.0rc5 - 更好的日志示例设置
- 2022-08-25 - v0.4.0rc4 - 添加
SyslogHandler
到日志设置 - 2022-08-25 - 将系统检查的 "Error" 降低到 "Warning"
- 2022-08-24 - 删除未使用的 "check_process"
- 2022-08-24 - 更新 dev shell:运行 cmd2 App 作为 CLI 或 shell
- 2022-08-24 - 添加系统检查以验证 settings.LOG_LEVEL
- 2022-08-24 - 清理测试设置
- 2022-08-24 - 添加系统检查以验证设置中的所有电子邮件地址
- 2022-08-24 - FINAL_HOME_PATH -> FINALPATH 和 FINAL_WWW_PATH -> PUBLIC_PATH
- v0.3.0
- 2022-08-14 - 更新 README
- 2022-08-14 - 更新需求
- 2022-08-14 - 代码清理
- 2022-08-14 - 将
extra_replacements:dict
添加到create_local_test()
- 2022-08-14 - 重命名
setup_demo_user()
->setup_project_user()
- 2022-08-14 - 删除
pytest_helper.run_pytest()
- 2022-08-12 - 更新 README.md
- v0.2.5
- 2022-08-12 - 将版本提升到 v0.2.5
- 2022-08-12 - 更新 README.md
- 2022-08-12 - 新变量名,用于 "ynh_add_config" 的使用
- 2022-08-12 - 更新测试设置
- 2022-08-12 - 修复行长度问题
- 2022-08-12 - 使用 codecov/codecov-action@v2
- 2022-08-12 - 修复 editorconfig
- 2022-07-11 - 扩展本地设置以用于本地测试。
- v0.2.4
- 2022-01-30 - 更新 README.md
- 2022-01-30 - 使用 darker 和 pytest-darker 作为代码格式化工具,并更新需求
- 2022-01-30 - 添加/更新一些元信息
- v0.2.3
- 2022-01-07 - 修复错误测试
- 2022-01-07 - 更新需求
- 2022-01-07 - 通过设置 "SECURE_SSL_REDIRECT = False" 修复本地测试
- 2021-10-10 - 更新 README.md
- v0.2.2
- 2021-10-10 - 从项目 manifest.json 文件中读取 YunoHost 应用名称
- v0.2.1
- 2021-09-16 - 通过在设置中添加
SECURE_PROXY_SSL_HEADER
修复无限重定向循环错误 - 2021-09-15 - 更新 README.md
- 2021-09-16 - 通过在设置中添加
- v0.2.0
- 2021-09-15 - 更新依赖项
- 2021-08-17 - 更新 README 并添加 poetry.lock 文件
- 2021-08-16 - 修复发布命令错误
- 2021-08-16 - 修复 "linting" 和 "fix_code_style" 命令并删除过时的 Makefile
- 2021-08-16 - 修复 flake8
- 2021-08-16 - 设置安全设置
- 2021-08-16 - 更新 GitHub 操作
- 2021-08-16 - 设置针对本地测试安装的 pytest
- 2021-02-28 - 从 django_ynh 重命名/拆分
- v0.1.5
- 2021-01-19 - 发布 v0.1.5
- 2021-01-17 - 将一些依赖项设置为可选
- v0.1.4
- 2021-01-08 - 准备 v0.1.4 版本发布
- 2021-01-08 - 修复错误 #7 POST 请求 CSRF 验证失败
- v0.1.3
- 2021-01-08 - 更新 README
- 2021-01-08 - 升级 v0.1.3
- 2021-01-08 - 在本地测试中重命名日志文件名
- 2021-01-08 - 在 pyproject.toml 中添加主页
- 2020-12-29 - 更新 README.md
- 2020-12-29 - 更新文档
- 2020-12-29 - -volumes
- 2020-12-29 - -pytest-randomly
- 2020-12-29 - 在本地_test 中设置 "DEBUG = True"(以便提供静态文件)
- v0.1.2
- 2020-12-29 - 修复 nginx 配置错误
- 2020-12-29 - 也复制 conf/setup_user.py
- 2020-12-29 - 修复提供静态文件错误
- 2020-12-29 - 修复超级用户设置错误
- 2020-12-29 - 在 "create_superuser" 管理命令中使 "--email" 可选
- v0.1.1
- 2020-12-29 - 传递现有的 pytest 参数
- 2020-12-29 - 修复代码风格
- 2020-12-29 - 更新测试
- 2020-12-29 - 在 scripts/_common.sh 中测试版本
- 2020-12-29 - 通过 pip 安装应用程序
- 2020-12-29 - 重命名设置和 urls
- 2020-12-29 - 修复 nginx.conf
- 2020-12-29 - 代码清理
- 2020-12-29 - 将更多关于此项目的信息添加到 README 中
- 2020-12-29 - 生成 "conf/requirements.txt" 并使用此文件进行安装
- 2020-12-29 - 将 "django_ynh" 添加到 INSTALLED_APPS 并将 "create_superuser" 迁移到管理命令
- v0.1.0
- 2020-12-28 - 修复 "make publish"
- 2020-12-28 - 修复 linting
- 2020-12-28 - 修复版本测试
- 2020-12-28 - 升级版本
- 2020-12-28 - 修复 "make publish" 错误
- 2020-12-28 - 删除测试文件
- 2020-12-28 - +DocString
- 2020-12-28 - 代码风格
- 2020-12-28 - 将 "make lint" 作为 unittest 调用
- 2020-12-28 - +test_project_setup.py
- 2020-12-28 - 使用本地测试副本运行 pytest
- 2020-12-28 - WIP:设置项目
- 2020-12-23 - 初始化
链接
- 关于此包的 bug 报告:https://github.com/YunoHost-Apps/django_yunohost_integration
- YunoHost 网站:https://yunohost.org/
- PyPi 包:https://pypi.ac.cn/project/django_yunohost_integration/
项目详情
关闭
哈希值 for django_yunohost_integration-0.8.1-py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 236bc1e427162182ca5efbf773bbad642b20741e7bf42308134887f4b7c27ced |
|
MD5 | 3bce52eb441c0bd176a42d0a25808641 |
|
BLAKE2b-256 | 87b95bc3a727ce92b6607d6613d0a39c4449be2a8e64f67de7cbdaaa72bd1a4f |