hyper-admin 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hyper_admin-1.0.0.dist-info/METADATA +366 -0
- hyper_admin-1.0.0.dist-info/RECORD +442 -0
- hyper_admin-1.0.0.dist-info/WHEEL +4 -0
- hyper_admin-1.0.0.dist-info/entry_points.txt +2 -0
- hyper_admin-1.0.0.dist-info/licenses/LICENSE +21 -0
- hyperadmin/__init__.py +52 -0
- hyperadmin/__main__.py +21 -0
- hyperadmin/adapters/__init__.py +28 -0
- hyperadmin/adapters/_estimate.py +33 -0
- hyperadmin/adapters/_filter_clause.py +9 -0
- hyperadmin/adapters/_occ.py +44 -0
- hyperadmin/adapters/_relation_loading.py +23 -0
- hyperadmin/adapters/_search.py +84 -0
- hyperadmin/adapters/filtering.py +86 -0
- hyperadmin/adapters/introspection.py +239 -0
- hyperadmin/adapters/registry.py +37 -0
- hyperadmin/adapters/schema.py +239 -0
- hyperadmin/adapters/sqlalchemy.py +423 -0
- hyperadmin/adapters/sqlmodel.py +650 -0
- hyperadmin/auth/__init__.py +156 -0
- hyperadmin/auth/_types.py +52 -0
- hyperadmin/auth/backend.py +37 -0
- hyperadmin/auth/bridge.py +351 -0
- hyperadmin/auth/exceptions.py +124 -0
- hyperadmin/auth/middleware.py +287 -0
- hyperadmin/auth/models.py +245 -0
- hyperadmin/auth/oauth/__init__.py +81 -0
- hyperadmin/auth/oauth/backend.py +611 -0
- hyperadmin/auth/oauth/providers.py +214 -0
- hyperadmin/auth/oauth/refresh.py +126 -0
- hyperadmin/auth/oauth/session.py +96 -0
- hyperadmin/auth/oauth/tokens.py +114 -0
- hyperadmin/auth/oauth/views.py +306 -0
- hyperadmin/auth/oauth/wiring.py +131 -0
- hyperadmin/auth/otp.py +189 -0
- hyperadmin/auth/permissions.py +232 -0
- hyperadmin/auth/session.py +81 -0
- hyperadmin/auth/session_middleware.py +164 -0
- hyperadmin/auth/token_handoff.py +452 -0
- hyperadmin/auth/user_cache.py +222 -0
- hyperadmin/auth/views.py +581 -0
- hyperadmin/core/__init__.py +76 -0
- hyperadmin/core/actions.py +151 -0
- hyperadmin/core/adapters.py +883 -0
- hyperadmin/core/app.py +1437 -0
- hyperadmin/core/auth.py +97 -0
- hyperadmin/core/bulk_results.py +28 -0
- hyperadmin/core/cache.py +68 -0
- hyperadmin/core/choices.py +38 -0
- hyperadmin/core/concurrency.py +107 -0
- hyperadmin/core/csrf.py +108 -0
- hyperadmin/core/discovery.py +161 -0
- hyperadmin/core/display.py +172 -0
- hyperadmin/core/fields.py +158 -0
- hyperadmin/core/fieldsets.py +22 -0
- hyperadmin/core/filtering.py +403 -0
- hyperadmin/core/filters_compat.py +78 -0
- hyperadmin/core/inlines.py +64 -0
- hyperadmin/core/introspection.py +280 -0
- hyperadmin/core/layouts.py +17 -0
- hyperadmin/core/lifecycle.py +278 -0
- hyperadmin/core/model.py +189 -0
- hyperadmin/core/navigation.py +354 -0
- hyperadmin/core/options.py +391 -0
- hyperadmin/core/palette.py +94 -0
- hyperadmin/core/panels.py +227 -0
- hyperadmin/core/plugin_wiring.py +205 -0
- hyperadmin/core/plugins.py +588 -0
- hyperadmin/core/primary_key.py +118 -0
- hyperadmin/core/rate_limit.py +90 -0
- hyperadmin/core/registry.py +129 -0
- hyperadmin/core/relation_loading.py +25 -0
- hyperadmin/core/schema.py +83 -0
- hyperadmin/core/sensitive.py +134 -0
- hyperadmin/core/settings.py +377 -0
- hyperadmin/core/storage_paths.py +54 -0
- hyperadmin/core/timezones.py +137 -0
- hyperadmin/core/uploads.py +16 -0
- hyperadmin/db.py +160 -0
- hyperadmin/discover.py +54 -0
- hyperadmin/filters/__init__.py +39 -0
- hyperadmin/filters/base.py +246 -0
- hyperadmin/filters/boolean.py +105 -0
- hyperadmin/filters/choice.py +74 -0
- hyperadmin/filters/date.py +265 -0
- hyperadmin/filters/relation.py +69 -0
- hyperadmin/filters/saved_views.py +203 -0
- hyperadmin/i18n/__init__.py +50 -0
- hyperadmin/i18n/loader.py +150 -0
- hyperadmin/i18n/middleware.py +159 -0
- hyperadmin/i18n/validation_messages.py +264 -0
- hyperadmin/loadtest/__init__.py +28 -0
- hyperadmin/loadtest/batch.py +263 -0
- hyperadmin/loadtest/checkpoint.py +168 -0
- hyperadmin/loadtest/generators/__init__.py +29 -0
- hyperadmin/loadtest/generators/auth.py +86 -0
- hyperadmin/loadtest/generators/erp.py +177 -0
- hyperadmin/loadtest/plan.py +189 -0
- hyperadmin/loadtest/pool.py +113 -0
- hyperadmin/loadtest/progress.py +150 -0
- hyperadmin/locale/ar/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/ar/LC_MESSAGES/messages.po +2139 -0
- hyperadmin/locale/de/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/de/LC_MESSAGES/messages.po +2114 -0
- hyperadmin/locale/en/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/en/LC_MESSAGES/messages.po +1780 -0
- hyperadmin/locale/es/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/es/LC_MESSAGES/messages.po +2094 -0
- hyperadmin/locale/fr/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/fr/LC_MESSAGES/messages.po +2100 -0
- hyperadmin/locale/he/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/he/LC_MESSAGES/messages.po +2076 -0
- hyperadmin/locale/hi/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/hi/LC_MESSAGES/messages.po +2084 -0
- hyperadmin/locale/id/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/id/LC_MESSAGES/messages.po +2071 -0
- hyperadmin/locale/it/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/it/LC_MESSAGES/messages.po +2098 -0
- hyperadmin/locale/ja/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/ja/LC_MESSAGES/messages.po +2049 -0
- hyperadmin/locale/ko/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/ko/LC_MESSAGES/messages.po +2049 -0
- hyperadmin/locale/nl/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/nl/LC_MESSAGES/messages.po +2100 -0
- hyperadmin/locale/pl/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/pl/LC_MESSAGES/messages.po +2112 -0
- hyperadmin/locale/pt_BR/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/pt_BR/LC_MESSAGES/messages.po +2098 -0
- hyperadmin/locale/ru/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/ru/LC_MESSAGES/messages.po +2112 -0
- hyperadmin/locale/th/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/th/LC_MESSAGES/messages.po +2065 -0
- hyperadmin/locale/tr/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/tr/LC_MESSAGES/messages.po +2084 -0
- hyperadmin/locale/uk/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/uk/LC_MESSAGES/messages.po +1889 -0
- hyperadmin/locale/vi/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/vi/LC_MESSAGES/messages.po +2063 -0
- hyperadmin/locale/zh_CN/LC_MESSAGES/messages.mo +0 -0
- hyperadmin/locale/zh_CN/LC_MESSAGES/messages.po +2049 -0
- hyperadmin/main.py +3 -0
- hyperadmin/management/__init__.py +0 -0
- hyperadmin/management/commands/__init__.py +0 -0
- hyperadmin/management/commands/createsuperuser.py +114 -0
- hyperadmin/management/commands/initdb.py +76 -0
- hyperadmin/management/commands/plugins.py +31 -0
- hyperadmin/management/commands/seed.py +125 -0
- hyperadmin/navigation/__init__.py +9 -0
- hyperadmin/navigation/pins.py +153 -0
- hyperadmin/panels/__init__.py +10 -0
- hyperadmin/panels/pdf.py +151 -0
- hyperadmin/permissions/__init__.py +59 -0
- hyperadmin/permissions/audit.py +109 -0
- hyperadmin/permissions/matrix.py +343 -0
- hyperadmin/permissions/object_rules.py +143 -0
- hyperadmin/realtime/__init__.py +51 -0
- hyperadmin/realtime/_debug.py +77 -0
- hyperadmin/realtime/config.py +124 -0
- hyperadmin/realtime/emitting.py +143 -0
- hyperadmin/realtime/events.py +107 -0
- hyperadmin/realtime/presence.py +193 -0
- hyperadmin/realtime/presence_redis.py +142 -0
- hyperadmin/realtime/pubsub.py +129 -0
- hyperadmin/realtime/pubsub_redis.py +159 -0
- hyperadmin/realtime/registry.py +102 -0
- hyperadmin/realtime/sse.py +82 -0
- hyperadmin/realtime/ws.py +477 -0
- hyperadmin/routing.py +680 -0
- hyperadmin/static/css/_accessibility.css +149 -0
- hyperadmin/static/css/_alerts.css +147 -0
- hyperadmin/static/css/_autocomplete.css +39 -0
- hyperadmin/static/css/_banner.css +118 -0
- hyperadmin/static/css/_buttons.css +241 -0
- hyperadmin/static/css/_card.css +86 -0
- hyperadmin/static/css/_dark-mode.css +232 -0
- hyperadmin/static/css/_fieldsets.css +71 -0
- hyperadmin/static/css/_filter.css +203 -0
- hyperadmin/static/css/_fonts.css +25 -0
- hyperadmin/static/css/_forms.css +862 -0
- hyperadmin/static/css/_inline-cell.css +222 -0
- hyperadmin/static/css/_inlines.css +160 -0
- hyperadmin/static/css/_layout.css +62 -0
- hyperadmin/static/css/_login.css +112 -0
- hyperadmin/static/css/_menu.css +156 -0
- hyperadmin/static/css/_navbar.css +299 -0
- hyperadmin/static/css/_page-header.css +139 -0
- hyperadmin/static/css/_pagination.css +125 -0
- hyperadmin/static/css/_palette.css +304 -0
- hyperadmin/static/css/_panels.css +174 -0
- hyperadmin/static/css/_permissions.css +547 -0
- hyperadmin/static/css/_pill.css +123 -0
- hyperadmin/static/css/_popover.css +170 -0
- hyperadmin/static/css/_popup.css +65 -0
- hyperadmin/static/css/_progress.css +161 -0
- hyperadmin/static/css/_realtime.css +78 -0
- hyperadmin/static/css/_reset.css +48 -0
- hyperadmin/static/css/_responsive.css +51 -0
- hyperadmin/static/css/_rtl.css +23 -0
- hyperadmin/static/css/_search.css +67 -0
- hyperadmin/static/css/_seg.css +95 -0
- hyperadmin/static/css/_sidebar.css +446 -0
- hyperadmin/static/css/_sticky.css +54 -0
- hyperadmin/static/css/_table.css +776 -0
- hyperadmin/static/css/_theme-terminal-type.css +92 -0
- hyperadmin/static/css/_theme-terminal.css +330 -0
- hyperadmin/static/css/_theme-toggle.css +46 -0
- hyperadmin/static/css/_tokens.css +232 -0
- hyperadmin/static/css/_utilities.css +133 -0
- hyperadmin/static/css/hyperadmin.css +58 -0
- hyperadmin/static/fonts/Inter-OFL.txt +93 -0
- hyperadmin/static/fonts/InterVariable.woff2 +0 -0
- hyperadmin/static/fonts/JetBrainsMono-OFL.txt +93 -0
- hyperadmin/static/fonts/JetBrainsMonoVariable.woff2 +0 -0
- hyperadmin/static/icons/arrow-down.svg +1 -0
- hyperadmin/static/icons/arrow-up.svg +1 -0
- hyperadmin/static/icons/bar-chart-3.svg +1 -0
- hyperadmin/static/icons/bell.svg +1 -0
- hyperadmin/static/icons/bookmark.svg +1 -0
- hyperadmin/static/icons/briefcase.svg +1 -0
- hyperadmin/static/icons/building-2.svg +1 -0
- hyperadmin/static/icons/calendar.svg +1 -0
- hyperadmin/static/icons/check.svg +1 -0
- hyperadmin/static/icons/chevron-down.svg +1 -0
- hyperadmin/static/icons/chevron-left.svg +1 -0
- hyperadmin/static/icons/chevron-right.svg +1 -0
- hyperadmin/static/icons/circle-check.svg +1 -0
- hyperadmin/static/icons/circle-help.svg +1 -0
- hyperadmin/static/icons/circle-x.svg +1 -0
- hyperadmin/static/icons/clock.svg +1 -0
- hyperadmin/static/icons/columns-3.svg +1 -0
- hyperadmin/static/icons/command.svg +1 -0
- hyperadmin/static/icons/copy.svg +1 -0
- hyperadmin/static/icons/credit-card.svg +1 -0
- hyperadmin/static/icons/database.svg +1 -0
- hyperadmin/static/icons/download.svg +1 -0
- hyperadmin/static/icons/ellipsis.svg +1 -0
- hyperadmin/static/icons/external-link.svg +1 -0
- hyperadmin/static/icons/eye.svg +1 -0
- hyperadmin/static/icons/file-text.svg +1 -0
- hyperadmin/static/icons/filter.svg +1 -0
- hyperadmin/static/icons/folder.svg +1 -0
- hyperadmin/static/icons/globe.svg +1 -0
- hyperadmin/static/icons/history.svg +1 -0
- hyperadmin/static/icons/home.svg +1 -0
- hyperadmin/static/icons/image.svg +1 -0
- hyperadmin/static/icons/info.svg +1 -0
- hyperadmin/static/icons/key-round.svg +1 -0
- hyperadmin/static/icons/layers.svg +1 -0
- hyperadmin/static/icons/layout-grid.svg +1 -0
- hyperadmin/static/icons/list-checks.svg +1 -0
- hyperadmin/static/icons/lock.svg +1 -0
- hyperadmin/static/icons/log-out.svg +1 -0
- hyperadmin/static/icons/mail.svg +1 -0
- hyperadmin/static/icons/map-pin.svg +1 -0
- hyperadmin/static/icons/menu.svg +1 -0
- hyperadmin/static/icons/moon.svg +1 -0
- hyperadmin/static/icons/package.svg +1 -0
- hyperadmin/static/icons/panel-left-close.svg +1 -0
- hyperadmin/static/icons/panel-left-open.svg +1 -0
- hyperadmin/static/icons/pencil.svg +1 -0
- hyperadmin/static/icons/pin-off.svg +1 -0
- hyperadmin/static/icons/pin.svg +1 -0
- hyperadmin/static/icons/plus.svg +1 -0
- hyperadmin/static/icons/receipt.svg +1 -0
- hyperadmin/static/icons/refresh-cw.svg +1 -0
- hyperadmin/static/icons/rotate-ccw.svg +1 -0
- hyperadmin/static/icons/search.svg +1 -0
- hyperadmin/static/icons/settings.svg +1 -0
- hyperadmin/static/icons/shield-check.svg +1 -0
- hyperadmin/static/icons/shopping-cart.svg +1 -0
- hyperadmin/static/icons/sliders-horizontal.svg +1 -0
- hyperadmin/static/icons/sparkles.svg +1 -0
- hyperadmin/static/icons/store.svg +1 -0
- hyperadmin/static/icons/sun.svg +1 -0
- hyperadmin/static/icons/tag.svg +1 -0
- hyperadmin/static/icons/trash-2.svg +1 -0
- hyperadmin/static/icons/triangle-alert.svg +1 -0
- hyperadmin/static/icons/truck.svg +1 -0
- hyperadmin/static/icons/upload.svg +1 -0
- hyperadmin/static/icons/user.svg +1 -0
- hyperadmin/static/icons/users.svg +1 -0
- hyperadmin/static/icons/wallet.svg +1 -0
- hyperadmin/static/icons/x.svg +1 -0
- hyperadmin/static/img/hyperadmin-favicon.svg +1 -0
- hyperadmin/static/img/hyperadmin-mark-mono.svg +1 -0
- hyperadmin/static/img/hyperadmin-mark.svg +1 -0
- hyperadmin/static/img/hyperadmin-wordmark-dark.svg +1 -0
- hyperadmin/static/img/hyperadmin-wordmark.svg +1 -0
- hyperadmin/static/img/terminal/hyperadmin-favicon-16.svg +1 -0
- hyperadmin/static/img/terminal/hyperadmin-favicon.svg +1 -0
- hyperadmin/static/img/terminal/hyperadmin-mark.svg +1 -0
- hyperadmin/static/img/terminal/hyperadmin-wordmark-dark.svg +1 -0
- hyperadmin/static/img/terminal/hyperadmin-wordmark.svg +1 -0
- hyperadmin/static/js/autocomplete.js +475 -0
- hyperadmin/static/js/confirm_delete.js +113 -0
- hyperadmin/static/js/error_summary.js +37 -0
- hyperadmin/static/js/form_guard.js +77 -0
- hyperadmin/static/js/inline_edit.js +97 -0
- hyperadmin/static/js/palette.js +292 -0
- hyperadmin/static/js/primitives.js +205 -0
- hyperadmin/static/js/realtime-status.js +515 -0
- hyperadmin/static/js/request_errors.js +85 -0
- hyperadmin/static/js/shortcuts.js +175 -0
- hyperadmin/static/js/sidebar.js +83 -0
- hyperadmin/static/js/vendor/LICENSE-alpinejs.txt +21 -0
- hyperadmin/static/js/vendor/LICENSE-htmx.txt +25 -0
- hyperadmin/static/js/vendor/alpinejs-3.17.4.min.js +21 -0
- hyperadmin/static/js/vendor/alpinejs-focus-3.17.4.min.js +18 -0
- hyperadmin/static/js/vendor/htmx-1.9.10.min.js +1 -0
- hyperadmin/templates/_base.html +161 -0
- hyperadmin/templates/_messages.html +11 -0
- hyperadmin/templates/_navbar.html +126 -0
- hyperadmin/templates/_sidebar.html +80 -0
- hyperadmin/templates/auth/mfa_challenge.html +75 -0
- hyperadmin/templates/auth/mfa_settings.html +110 -0
- hyperadmin/templates/auth/oauth_link_required.html +24 -0
- hyperadmin/templates/auth/oauth_settings.html +55 -0
- hyperadmin/templates/base.html +16 -0
- hyperadmin/templates/bulk_form.html +18 -0
- hyperadmin/templates/bulk_result.html +20 -0
- hyperadmin/templates/components/_icons.html +86 -0
- hyperadmin/templates/components/_macros.html +27 -0
- hyperadmin/templates/components/_nav.html +55 -0
- hyperadmin/templates/components/_row_access.html +26 -0
- hyperadmin/templates/components/banner.html +77 -0
- hyperadmin/templates/components/bulk_form.html +81 -0
- hyperadmin/templates/components/bulk_result.html +133 -0
- hyperadmin/templates/components/bulk_toolbar.html +63 -0
- hyperadmin/templates/components/command_palette.html +59 -0
- hyperadmin/templates/components/confirm_delete_dialog.html +26 -0
- hyperadmin/templates/components/conflict_dialog.html +42 -0
- hyperadmin/templates/components/csrf_reload_banner.html +20 -0
- hyperadmin/templates/components/error_summary.html +39 -0
- hyperadmin/templates/components/error_toast.html +18 -0
- hyperadmin/templates/components/fieldset.html +38 -0
- hyperadmin/templates/components/filter_bar.html +50 -0
- hyperadmin/templates/components/filter_sidebar.html +31 -0
- hyperadmin/templates/components/filters/boolean.html +10 -0
- hyperadmin/templates/components/filters/current_period.html +8 -0
- hyperadmin/templates/components/filters/date_range.html +26 -0
- hyperadmin/templates/components/filters/is_owner.html +8 -0
- hyperadmin/templates/components/filters/multi_choice.html +10 -0
- hyperadmin/templates/components/filters/multi_relation.html +20 -0
- hyperadmin/templates/components/filters/select.html +11 -0
- hyperadmin/templates/components/inline_cell.html +23 -0
- hyperadmin/templates/components/inline_cell_error.html +51 -0
- hyperadmin/templates/components/inline_cell_stale.html +20 -0
- hyperadmin/templates/components/inline_editor.html +85 -0
- hyperadmin/templates/components/inline_formset.html +34 -0
- hyperadmin/templates/components/inline_row.html +49 -0
- hyperadmin/templates/components/list_error.html +12 -0
- hyperadmin/templates/components/menu.html +74 -0
- hyperadmin/templates/components/nav_pinned.html +24 -0
- hyperadmin/templates/components/pagination.html +87 -0
- hyperadmin/templates/components/panel_document.html +19 -0
- hyperadmin/templates/components/panel_states.html +35 -0
- hyperadmin/templates/components/panel_tab_strip.html +31 -0
- hyperadmin/templates/components/pill.html +15 -0
- hyperadmin/templates/components/popover.html +59 -0
- hyperadmin/templates/components/presence_banner.html +28 -0
- hyperadmin/templates/components/progress.html +72 -0
- hyperadmin/templates/components/saved_views.html +61 -0
- hyperadmin/templates/components/search_input.html +19 -0
- hyperadmin/templates/components/seg.html +38 -0
- hyperadmin/templates/components/shortcuts_overlay.html +45 -0
- hyperadmin/templates/components/sortable_header.html +23 -0
- hyperadmin/templates/components/table.html +45 -0
- hyperadmin/templates/components/table_body.html +86 -0
- hyperadmin/templates/components/thumbnail.html +8 -0
- hyperadmin/templates/components/toast.html +36 -0
- hyperadmin/templates/components/tooltip.html +20 -0
- hyperadmin/templates/create.html +43 -0
- hyperadmin/templates/dashboard.html +8 -0
- hyperadmin/templates/detail.html +120 -0
- hyperadmin/templates/detail_layout.html +15 -0
- hyperadmin/templates/error.html +24 -0
- hyperadmin/templates/form_layout.html +26 -0
- hyperadmin/templates/list.html +5 -0
- hyperadmin/templates/list_layout.html +105 -0
- hyperadmin/templates/login.html +79 -0
- hyperadmin/templates/permissions/_banner.html +55 -0
- hyperadmin/templates/permissions/_diff_row.html +6 -0
- hyperadmin/templates/permissions/_group_gone.html +16 -0
- hyperadmin/templates/permissions/_macros.html +22 -0
- hyperadmin/templates/permissions/matrix.html +408 -0
- hyperadmin/templates/permissions/object_popover.html +95 -0
- hyperadmin/templates/update.html +69 -0
- hyperadmin/templates/widgets/autocomplete.html +100 -0
- hyperadmin/templates/widgets/checkbox_input.html +20 -0
- hyperadmin/templates/widgets/choices_options.html +3 -0
- hyperadmin/templates/widgets/date_input.html +13 -0
- hyperadmin/templates/widgets/datetime_input.html +18 -0
- hyperadmin/templates/widgets/encoded_textarea.html +4 -0
- hyperadmin/templates/widgets/file_input.html +15 -0
- hyperadmin/templates/widgets/float_input.html +12 -0
- hyperadmin/templates/widgets/image_input.html +108 -0
- hyperadmin/templates/widgets/multiselect_input.html +13 -0
- hyperadmin/templates/widgets/number_input.html +11 -0
- hyperadmin/templates/widgets/popup_form.html +64 -0
- hyperadmin/templates/widgets/relation_multiselect_input.html +36 -0
- hyperadmin/templates/widgets/relation_select_input.html +38 -0
- hyperadmin/templates/widgets/select_input.html +17 -0
- hyperadmin/templates/widgets/text_input.html +13 -0
- hyperadmin/templates/widgets/textarea.html +4 -0
- hyperadmin/uploads/__init__.py +44 -0
- hyperadmin/uploads/images.py +272 -0
- hyperadmin/uploads/storage.py +265 -0
- hyperadmin/uploads/validation.py +37 -0
- hyperadmin/views/__init__.py +3 -0
- hyperadmin/views/csrf.py +316 -0
- hyperadmin/views/dynamic/__init__.py +35 -0
- hyperadmin/views/dynamic/actions.py +264 -0
- hyperadmin/views/dynamic/base.py +576 -0
- hyperadmin/views/dynamic/concurrency.py +138 -0
- hyperadmin/views/dynamic/core.py +33 -0
- hyperadmin/views/dynamic/create.py +189 -0
- hyperadmin/views/dynamic/detail.py +231 -0
- hyperadmin/views/dynamic/files.py +233 -0
- hyperadmin/views/dynamic/form_data.py +162 -0
- hyperadmin/views/dynamic/helpers.py +151 -0
- hyperadmin/views/dynamic/inline.py +348 -0
- hyperadmin/views/dynamic/list_view.py +612 -0
- hyperadmin/views/dynamic/model_view.py +17 -0
- hyperadmin/views/dynamic/palette_search.py +78 -0
- hyperadmin/views/dynamic/relations.py +544 -0
- hyperadmin/views/dynamic/saved_views.py +159 -0
- hyperadmin/views/dynamic/update.py +313 -0
- hyperadmin/views/error_pages.py +46 -0
- hyperadmin/views/forms.py +1294 -0
- hyperadmin/views/htmx.py +53 -0
- hyperadmin/views/locale.py +113 -0
- hyperadmin/views/nav_pins.py +149 -0
- hyperadmin/views/navigation.py +143 -0
- hyperadmin/views/palette_context.py +91 -0
- hyperadmin/views/palette_search.py +103 -0
- hyperadmin/views/permissions_matrix.py +490 -0
- hyperadmin/views/rate_limit.py +87 -0
- hyperadmin/views/route.py +316 -0
- hyperadmin/views/static.py +138 -0
- hyperadmin/views/template_filters.py +305 -0
- hyperadmin/views/uploads.py +92 -0
- hyperadmin/views/urls.py +180 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
"""Centralised configuration for HyperAdmin via pydantic-settings BaseSettings."""
|
|
2
|
+
|
|
3
|
+
from functools import lru_cache
|
|
4
|
+
from typing import Any, Literal
|
|
5
|
+
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError, available_timezones
|
|
6
|
+
|
|
7
|
+
from pydantic import AliasChoices, Field, SecretStr, field_validator, model_validator
|
|
8
|
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
9
|
+
from typing_extensions import Self
|
|
10
|
+
|
|
11
|
+
from hyperadmin.core.csrf import CsrfMode
|
|
12
|
+
|
|
13
|
+
_DEFAULT_SECRET_KEY = "hyperadmin-default-secret" # noqa: S105
|
|
14
|
+
_DEFAULT_DATABASE_URL = "sqlite+aiosqlite:///:memory:"
|
|
15
|
+
_DEFAULT_SUPPORTED_LOCALES = [
|
|
16
|
+
# Original v0.4.1 set (LTR, ordered by speaker count + admin-UI relevance).
|
|
17
|
+
"en",
|
|
18
|
+
"es",
|
|
19
|
+
"fr",
|
|
20
|
+
"de",
|
|
21
|
+
"zh_CN",
|
|
22
|
+
"ja",
|
|
23
|
+
"uk",
|
|
24
|
+
# v0.5.2 top-20 expansion: 2 RTL + 1 Devanagari + European + SE-Asian.
|
|
25
|
+
"ar",
|
|
26
|
+
"he",
|
|
27
|
+
"hi",
|
|
28
|
+
"pt_BR",
|
|
29
|
+
"ru",
|
|
30
|
+
"ko",
|
|
31
|
+
"it",
|
|
32
|
+
"tr",
|
|
33
|
+
"pl",
|
|
34
|
+
"nl",
|
|
35
|
+
"vi",
|
|
36
|
+
"id",
|
|
37
|
+
"th",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
ThemeLiteral = Literal["auto", "light", "dark"]
|
|
41
|
+
#: Visual theme presets: ``"terminal"`` (HyperAdmin v2, default) or ``"classic"`` (teal).
|
|
42
|
+
ThemePresetLiteral = Literal["terminal", "classic"]
|
|
43
|
+
MountModeLiteral = Literal["isolated", "router"]
|
|
44
|
+
StorageBackendLiteral = Literal["local", "s3"]
|
|
45
|
+
#: ``cookie_secure`` setting values (SDD C.4).
|
|
46
|
+
CookieSecure = Literal["auto"] | bool
|
|
47
|
+
SameSiteLiteral = Literal["lax", "strict", "none"]
|
|
48
|
+
|
|
49
|
+
#: Request schemes whose cookies get ``Secure`` under ``cookie_secure="auto"``.
|
|
50
|
+
_SECURE_SCHEMES = frozenset({"https", "wss"})
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def resolve_cookie_secure(cookie_secure: CookieSecure, scheme: str) -> bool:
|
|
54
|
+
"""Return whether an admin cookie gets the ``Secure`` flag (SDD C.4).
|
|
55
|
+
|
|
56
|
+
``True`` / ``False`` are used as-is. ``"auto"`` follows the effective request
|
|
57
|
+
scheme (``request.url.scheme``, which honours ``X-Forwarded-Proto`` when the
|
|
58
|
+
server trusts the proxy), so plain-http installs and ``TestClient`` keep their
|
|
59
|
+
cookies while https/wss requests get ``Secure``.
|
|
60
|
+
"""
|
|
61
|
+
if cookie_secure == "auto":
|
|
62
|
+
return scheme.lower() in _SECURE_SCHEMES
|
|
63
|
+
return cookie_secure is True
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@lru_cache(maxsize=1)
|
|
67
|
+
def _available_timezones() -> frozenset[str]:
|
|
68
|
+
"""Return the canonical IANA zone keys known on this host (cached)."""
|
|
69
|
+
return frozenset(available_timezones())
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class HyperAdminSettings(BaseSettings):
|
|
73
|
+
"""Django-like centralised settings for HyperAdmin.
|
|
74
|
+
|
|
75
|
+
All scalar configuration lives here — no duplicate params on ``Admin()``.
|
|
76
|
+
Values can be provided via environment variables (``HYPERADMIN_*`` prefix),
|
|
77
|
+
a ``.env`` file, or explicit keyword arguments (highest priority).
|
|
78
|
+
|
|
79
|
+
Example::
|
|
80
|
+
|
|
81
|
+
settings = HyperAdminSettings(secret_key="my-secret", theme="dark")
|
|
82
|
+
Admin(app, engine=engine, settings=settings)
|
|
83
|
+
|
|
84
|
+
# Or rely entirely on env vars / .env:
|
|
85
|
+
Admin(app, engine=engine)
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
model_config = SettingsConfigDict(
|
|
89
|
+
env_prefix="HYPERADMIN_",
|
|
90
|
+
env_file=".env",
|
|
91
|
+
env_file_encoding="utf-8",
|
|
92
|
+
case_sensitive=False,
|
|
93
|
+
extra="ignore",
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# ── Branding ─────────────────────────────────────────────────────────────
|
|
97
|
+
site_title: str = "HyperAdmin"
|
|
98
|
+
site_header: str = "HyperAdmin"
|
|
99
|
+
|
|
100
|
+
# ── Security ─────────────────────────────────────────────────────────────
|
|
101
|
+
secret_key: str = Field(default=_DEFAULT_SECRET_KEY)
|
|
102
|
+
|
|
103
|
+
# ── CSRF (SDD D.1) ──────────────────────────────────────────────────────────
|
|
104
|
+
#: ``"auto"`` enforces the signed double-submit check whenever auth is
|
|
105
|
+
#: configured and is off otherwise; ``"report"`` only logs failures.
|
|
106
|
+
csrf_mode: CsrfMode = "auto"
|
|
107
|
+
csrf_cookie_name: str = Field(default="hyperadmin_csrf", min_length=1)
|
|
108
|
+
csrf_header_name: str = Field(default="X-CSRF-Token", min_length=1)
|
|
109
|
+
csrf_field_name: str = Field(default="csrf_token", min_length=1)
|
|
110
|
+
#: Extra origins (``"https://admin.example"``) the ``Origin`` check accepts.
|
|
111
|
+
csrf_trusted_origins: list[str] = Field(default_factory=list)
|
|
112
|
+
#: ``Secure`` flag for every admin cookie (session, CSRF, token, locale; SDD C.4):
|
|
113
|
+
#: ``"auto"`` follows the effective request scheme; set ``True`` behind a TLS
|
|
114
|
+
#: proxy uvicorn does not trust.
|
|
115
|
+
cookie_secure: CookieSecure = "auto"
|
|
116
|
+
|
|
117
|
+
# ── OAuth sign-in (docs/specs/oauth-sso.md) ───────────────────────────────
|
|
118
|
+
# Read only with ``Admin(oauth_backend=...)``; providers are wired in code.
|
|
119
|
+
#: Fernet key (32 url-safe base64 bytes) that encrypts stored OAuth tokens;
|
|
120
|
+
#: required with OAuth. Several keys separated by commas rotate it: the first
|
|
121
|
+
#: encrypts, all decrypt.
|
|
122
|
+
oauth_token_secret: SecretStr | None = None
|
|
123
|
+
#: Seconds a sign-in may take between the redirect to the provider and its callback.
|
|
124
|
+
oauth_state_ttl_seconds: int = Field(default=600, ge=1)
|
|
125
|
+
#: An access token is refreshed when it expires within this many seconds.
|
|
126
|
+
oauth_refresh_leeway_seconds: int = Field(default=60, ge=0)
|
|
127
|
+
#: Where a completed OAuth sign-in lands; ``None`` is the admin index.
|
|
128
|
+
oauth_login_redirect: str | None = None
|
|
129
|
+
#: ``(requests, seconds)`` one client may send to the OAuth callback.
|
|
130
|
+
oauth_callback_rate_limit: tuple[int, int] = (20, 60)
|
|
131
|
+
|
|
132
|
+
# ── Database ─────────────────────────────────────────────────────────────
|
|
133
|
+
database_url: str = _DEFAULT_DATABASE_URL
|
|
134
|
+
#: Connection pool of the engine HyperAdmin builds from ``database_url`` (no
|
|
135
|
+
#: ``engine=`` passed); a host engine keeps its own pool. ``None`` keeps
|
|
136
|
+
#: SQLAlchemy's default. The ``pool_*`` sizes are ignored for in-memory SQLite.
|
|
137
|
+
database_pool_size: int | None = Field(default=None, ge=1)
|
|
138
|
+
#: Connections opened above ``database_pool_size`` under load; ``-1`` is unlimited.
|
|
139
|
+
database_max_overflow: int | None = Field(default=None, ge=-1)
|
|
140
|
+
#: Seconds a request waits for a free connection before it fails.
|
|
141
|
+
database_pool_timeout: float | None = Field(default=None, gt=0)
|
|
142
|
+
#: Seconds after which a connection is replaced; ``-1`` never replaces it.
|
|
143
|
+
database_pool_recycle: int | None = Field(default=None, ge=-1)
|
|
144
|
+
#: Test each connection before use, so ones the server dropped are replaced.
|
|
145
|
+
database_pool_pre_ping: bool = False
|
|
146
|
+
|
|
147
|
+
# ── Runtime behaviour ─────────────────────────────────────────────────────
|
|
148
|
+
debug: bool = False
|
|
149
|
+
#: Defaults to ``False`` (SDD C.2): a host engine or session_factory never gets DDL
|
|
150
|
+
#: run against it unless requested. Demo mode (no engine=, no session_factory=) is
|
|
151
|
+
#: the one exception — it still auto-creates tables when database_url is SQLite, so
|
|
152
|
+
#: zero-config ``Admin(app).mount("/admin")`` keeps working. Set this to ``True`` to
|
|
153
|
+
#: keep the old "always create every table at startup" behaviour.
|
|
154
|
+
create_tables: bool = False
|
|
155
|
+
#: Register the built-in ``User``/``Group``/``Permission`` admins (SDD B.3).
|
|
156
|
+
#: ``None`` (default) means on with ``auth_backend=`` and off with ``auth=``
|
|
157
|
+
#: (bring-your-own-auth) or no auth; ``True``/``False`` force it either way.
|
|
158
|
+
register_auth_models: bool | None = None
|
|
159
|
+
|
|
160
|
+
# ── Mounting (SDD C.1) ──────────────────────────────────────────────────────
|
|
161
|
+
#: ``"isolated"`` (default) attaches the admin as a private sub-application, so
|
|
162
|
+
#: its middleware, static files, route names and OpenAPI stay out of the host.
|
|
163
|
+
#: ``"router"`` is the deprecated legacy mode (``include_router`` + global
|
|
164
|
+
#: middleware), removed in 0.6.
|
|
165
|
+
mount_mode: MountModeLiteral = "isolated"
|
|
166
|
+
#: Name of the sub-application mount; admin routes resolve as
|
|
167
|
+
#: ``f"{route_namespace}:{name}"`` (e.g. ``hyperadmin:user-list``) in isolated mode.
|
|
168
|
+
route_namespace: str = Field(default="hyperadmin", min_length=1, pattern=r"^[^:/]+$")
|
|
169
|
+
|
|
170
|
+
# ── Admin cookies (SDD C.4) ─────────────────────────────────────────────────
|
|
171
|
+
#: Name of the admin's own session cookie. Its ``Path`` is the per-request admin
|
|
172
|
+
#: path, so it never collides with a host ``session`` cookie. In the deprecated
|
|
173
|
+
#: router mode the legacy cookie (``session``, ``Path=/``) is kept unless this
|
|
174
|
+
#: is set explicitly.
|
|
175
|
+
session_cookie: str = Field(default="hyperadmin_session", min_length=1)
|
|
176
|
+
#: Session lifetime in seconds (default: 14 days).
|
|
177
|
+
session_max_age: int = Field(default=1_209_600, gt=0)
|
|
178
|
+
session_same_site: SameSiteLiteral = "lax"
|
|
179
|
+
#: Seconds the authenticated user and its permission set are cached per worker,
|
|
180
|
+
#: keyed by session user id (``0`` = off: loaded on every request). Writes on the
|
|
181
|
+
#: same worker invalidate the entry; other workers may serve a stale user for up
|
|
182
|
+
#: to this many seconds, so the value is capped at one minute.
|
|
183
|
+
user_cache_ttl: int = Field(default=0, ge=0, le=60)
|
|
184
|
+
|
|
185
|
+
# ── Discovery ─────────────────────────────────────────────────────────────
|
|
186
|
+
auto_discover: bool = False
|
|
187
|
+
discover_apps: list[str] = Field(default_factory=list)
|
|
188
|
+
#: Load ``hyperadmin.plugins`` entry points when the ``Admin`` is built. ``False``
|
|
189
|
+
#: skips discovery entirely; plugins can still be registered by hand with
|
|
190
|
+
#: ``admin.plugins.register(plugin, admin=admin)`` before ``mount()``.
|
|
191
|
+
plugins_enabled: bool = True
|
|
192
|
+
|
|
193
|
+
# ── Permission matrix (docs/specs/permission-matrix-ui.md) ───────────────
|
|
194
|
+
#: Register the ``{prefix}/permissions-matrix/`` page and its sidebar entry.
|
|
195
|
+
#: ``False`` leaves the URL unrouted (404) for projects without groups.
|
|
196
|
+
permissions_matrix_enabled: bool = True
|
|
197
|
+
#: Codename an operator needs to open and save the matrix (superusers always
|
|
198
|
+
#: may). Synced into ``hyperadmin_permissions`` next to the plugin codenames.
|
|
199
|
+
permissions_matrix_codename: str = Field(
|
|
200
|
+
default="change_groups_permissions", min_length=1, pattern=r"^[a-z][a-z0-9_]*$"
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
# ── Templates ─────────────────────────────────────────────────────────────
|
|
204
|
+
template_dirs: list[str] = Field(default_factory=list)
|
|
205
|
+
|
|
206
|
+
# ── UI ────────────────────────────────────────────────────────────────────
|
|
207
|
+
theme: ThemeLiteral = "auto"
|
|
208
|
+
#: Visual theme preset, independent of the light/dark ``theme``: ``"terminal"``
|
|
209
|
+
#: (near-black, square, acid green; the default) or ``"classic"`` (the teal look).
|
|
210
|
+
theme_preset: ThemePresetLiteral = "terminal"
|
|
211
|
+
#: Rows a list page shows when the request has no ``page_size`` query parameter.
|
|
212
|
+
#: A value above 100 (the most a list page shows) is capped at 100.
|
|
213
|
+
items_per_page: int = Field(default=10, gt=0)
|
|
214
|
+
|
|
215
|
+
# ── Uploads ───────────────────────────────────────────────────────────────
|
|
216
|
+
upload_dir: str = "uploads"
|
|
217
|
+
#: Escape hatch (SDD C.5): when set, the storage directory is also mounted
|
|
218
|
+
#: publicly at this host path, outside the admin's authentication, and a
|
|
219
|
+
#: startup warning is logged. Files are otherwise served only per record at
|
|
220
|
+
#: ``{prefix}/{model}/{item_id}/file/{field}``.
|
|
221
|
+
public_uploads_path: str | None = Field(default=None, pattern=r"^/[^\s]*[^/\s]$")
|
|
222
|
+
|
|
223
|
+
# ── Uploads: S3-compatible object storage (epic #410, story #402) ──────────
|
|
224
|
+
#: ``"s3"`` makes ``Admin()`` build an ``S3StorageBackend`` from the ``aws_*``
|
|
225
|
+
#: settings when no ``storage=`` is passed (needs ``pip install 'hyper-admin[s3]'``).
|
|
226
|
+
#: ``"local"`` (default) leaves the choice to the host: uploads stay off until
|
|
227
|
+
#: a ``FileSystemStorage`` is passed.
|
|
228
|
+
storage_backend: StorageBackendLiteral = "local"
|
|
229
|
+
#: Every ``aws_*`` setting reads ``HYPERADMIN_AWS_*`` first and then the plain
|
|
230
|
+
#: ``AWS_*`` variable the AWS SDK and ``fastapi-storages`` use, so one set of
|
|
231
|
+
#: variables configures both. Credentials are optional: when unset, boto3's
|
|
232
|
+
#: own chain applies (profiles, instance and task roles).
|
|
233
|
+
aws_access_key_id: str | None = Field(
|
|
234
|
+
default=None,
|
|
235
|
+
validation_alias=AliasChoices("hyperadmin_aws_access_key_id", "aws_access_key_id"),
|
|
236
|
+
)
|
|
237
|
+
aws_secret_access_key: SecretStr | None = Field(
|
|
238
|
+
default=None,
|
|
239
|
+
validation_alias=AliasChoices("hyperadmin_aws_secret_access_key", "aws_secret_access_key"),
|
|
240
|
+
)
|
|
241
|
+
aws_s3_bucket_name: str | None = Field(
|
|
242
|
+
default=None,
|
|
243
|
+
validation_alias=AliasChoices("hyperadmin_aws_s3_bucket_name", "aws_s3_bucket_name"),
|
|
244
|
+
)
|
|
245
|
+
aws_s3_region: str | None = Field(
|
|
246
|
+
default=None,
|
|
247
|
+
validation_alias=AliasChoices(
|
|
248
|
+
"hyperadmin_aws_s3_region", "aws_s3_region", "aws_default_region"
|
|
249
|
+
),
|
|
250
|
+
)
|
|
251
|
+
#: ``http(s)://host[:port]`` of an S3-compatible service (MinIO, R2, Hetzner,
|
|
252
|
+
#: Spaces); unset for AWS S3.
|
|
253
|
+
aws_s3_endpoint_url: str | None = Field(
|
|
254
|
+
default=None,
|
|
255
|
+
validation_alias=AliasChoices("hyperadmin_aws_s3_endpoint_url", "aws_s3_endpoint_url"),
|
|
256
|
+
)
|
|
257
|
+
#: Host object URLs are served from instead of the endpoint (CDN, R2 public
|
|
258
|
+
#: bucket domain); such URLs are not signed.
|
|
259
|
+
aws_s3_custom_domain: str | None = Field(
|
|
260
|
+
default=None,
|
|
261
|
+
validation_alias=AliasChoices("hyperadmin_aws_s3_custom_domain", "aws_s3_custom_domain"),
|
|
262
|
+
)
|
|
263
|
+
#: Sign object URLs (presigned, time-limited). ``False`` only for a
|
|
264
|
+
#: public-read bucket.
|
|
265
|
+
aws_s3_querystring_auth: bool = Field(
|
|
266
|
+
default=True,
|
|
267
|
+
validation_alias=AliasChoices(
|
|
268
|
+
"hyperadmin_aws_s3_querystring_auth", "aws_s3_querystring_auth", "aws_querystring_auth"
|
|
269
|
+
),
|
|
270
|
+
)
|
|
271
|
+
#: ACL set on every written object (``"public-read"``); unset keeps objects
|
|
272
|
+
#: private and sends no ACL (required by services without ACLs, such as R2).
|
|
273
|
+
aws_s3_default_acl: str | None = Field(
|
|
274
|
+
default=None,
|
|
275
|
+
validation_alias=AliasChoices(
|
|
276
|
+
"hyperadmin_aws_s3_default_acl", "aws_s3_default_acl", "aws_default_acl"
|
|
277
|
+
),
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
# ── Formatting ────────────────────────────────────────────────────────────
|
|
281
|
+
date_format: str = "%Y-%m-%d"
|
|
282
|
+
datetime_format: str = "%Y-%m-%d %H:%M:%S"
|
|
283
|
+
#: IANA zone used to enter and display timezone-aware datetimes.
|
|
284
|
+
timezone: str = "UTC"
|
|
285
|
+
|
|
286
|
+
# ── Performance ───────────────────────────────────────────────────────────
|
|
287
|
+
#: Most list totals the built-in count cache keeps; the least recently used go first.
|
|
288
|
+
#: Only used by models that set ``AdminOptions.count_cache_ttl``.
|
|
289
|
+
count_cache_max_entries: int = Field(default=1024, ge=1)
|
|
290
|
+
#: Requests one client may make to the admin per ``rate_limit_window_seconds``;
|
|
291
|
+
#: over that gets ``429``. ``None`` (default) applies no limit. Counted per process,
|
|
292
|
+
#: so N workers allow up to N times this; pass ``Admin(rate_limiter=...)`` for a
|
|
293
|
+
#: shared limiter. Static assets are never counted.
|
|
294
|
+
rate_limit_requests: int | None = Field(default=None, ge=1)
|
|
295
|
+
#: A further, normally stricter, limit on login form submissions per client, within
|
|
296
|
+
#: the same window. ``None`` (default) applies none.
|
|
297
|
+
rate_limit_login_requests: int | None = Field(default=None, ge=1)
|
|
298
|
+
rate_limit_window_seconds: int = Field(default=60, ge=1)
|
|
299
|
+
|
|
300
|
+
# ── Concurrency (docs/specs/realtime-occ.md) ──────────────────────────────
|
|
301
|
+
#: Let ``updated_at`` act as the version field of models with no ``version`` column.
|
|
302
|
+
#: Approximate: writes within the column's timestamp resolution can go undetected.
|
|
303
|
+
concurrency_use_updated_at: bool = False
|
|
304
|
+
#: Render the HTML conflict dialog on a stale save; ``False`` answers API clients
|
|
305
|
+
#: with a JSON 409 body instead.
|
|
306
|
+
occ_render_dialog: bool = True
|
|
307
|
+
|
|
308
|
+
# ── Navigation ────────────────────────────────────────────────────────────
|
|
309
|
+
#: Most sidebar pages one user may pin (built-in or bridge auth only).
|
|
310
|
+
nav_pins_max: int = Field(default=20, ge=1)
|
|
311
|
+
|
|
312
|
+
# ── Internationalization ──────────────────────────────────────────────────
|
|
313
|
+
default_locale: str = "en"
|
|
314
|
+
supported_locales: list[str] = Field(default_factory=lambda: list(_DEFAULT_SUPPORTED_LOCALES))
|
|
315
|
+
locale_response_header: bool = True
|
|
316
|
+
|
|
317
|
+
# ── Derived helpers ───────────────────────────────────────────────────────
|
|
318
|
+
@property
|
|
319
|
+
def database_engine_kwargs(self) -> dict[str, Any]:
|
|
320
|
+
"""Return the ``create_async_engine`` pool arguments set by ``database_pool_*``."""
|
|
321
|
+
kwargs: dict[str, Any] = {
|
|
322
|
+
"pool_size": self.database_pool_size,
|
|
323
|
+
"max_overflow": self.database_max_overflow,
|
|
324
|
+
"pool_timeout": self.database_pool_timeout,
|
|
325
|
+
"pool_recycle": self.database_pool_recycle,
|
|
326
|
+
}
|
|
327
|
+
kwargs = {key: value for key, value in kwargs.items() if value is not None}
|
|
328
|
+
if self.database_pool_pre_ping:
|
|
329
|
+
kwargs["pool_pre_ping"] = True
|
|
330
|
+
return kwargs
|
|
331
|
+
|
|
332
|
+
@property
|
|
333
|
+
def is_default_secret_key(self) -> bool:
|
|
334
|
+
"""Return ``True`` when ``secret_key`` has not been changed from the default."""
|
|
335
|
+
return self.secret_key == _DEFAULT_SECRET_KEY
|
|
336
|
+
|
|
337
|
+
@property
|
|
338
|
+
def tzinfo(self) -> ZoneInfo:
|
|
339
|
+
"""Return the configured display timezone as a ``ZoneInfo``."""
|
|
340
|
+
return ZoneInfo(self.timezone)
|
|
341
|
+
|
|
342
|
+
@field_validator("timezone")
|
|
343
|
+
@classmethod
|
|
344
|
+
def _validate_timezone(cls, value: str) -> str:
|
|
345
|
+
try:
|
|
346
|
+
ZoneInfo(value)
|
|
347
|
+
except (ZoneInfoNotFoundError, ValueError) as exc:
|
|
348
|
+
msg = f"Invalid timezone {value!r}. Must be an IANA zone name such as 'UTC'"
|
|
349
|
+
raise ValueError(msg) from exc
|
|
350
|
+
# A case-insensitive filesystem (macOS) resolves 'utc' too; Linux and the
|
|
351
|
+
# Windows tzdata package do not, so require the canonical spelling.
|
|
352
|
+
known = _available_timezones()
|
|
353
|
+
if known and value not in known:
|
|
354
|
+
canonical = next((key for key in known if key.lower() == value.lower()), None)
|
|
355
|
+
hint = f" Did you mean {canonical!r}?" if canonical else ""
|
|
356
|
+
msg = f"Invalid timezone {value!r}. Zone names are case-sensitive.{hint}"
|
|
357
|
+
raise ValueError(msg)
|
|
358
|
+
return value
|
|
359
|
+
|
|
360
|
+
@model_validator(mode="after")
|
|
361
|
+
def _validate_storage_backend(self) -> Self:
|
|
362
|
+
if self.storage_backend == "s3" and not self.aws_s3_bucket_name:
|
|
363
|
+
msg = (
|
|
364
|
+
"storage_backend='s3' requires aws_s3_bucket_name "
|
|
365
|
+
"(HYPERADMIN_AWS_S3_BUCKET_NAME or AWS_S3_BUCKET_NAME)"
|
|
366
|
+
)
|
|
367
|
+
raise ValueError(msg)
|
|
368
|
+
return self
|
|
369
|
+
|
|
370
|
+
@field_validator("theme", mode="before")
|
|
371
|
+
@classmethod
|
|
372
|
+
def _validate_theme(cls, value: str) -> str:
|
|
373
|
+
valid = ("auto", "light", "dark")
|
|
374
|
+
if value not in valid:
|
|
375
|
+
msg = f"Invalid theme {value!r}. Must be one of {valid}"
|
|
376
|
+
raise ValueError(msg)
|
|
377
|
+
return value
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Storage-root containment for file paths derived from database values.
|
|
2
|
+
|
|
3
|
+
A file column stores a name relative to the storage root. A value written into
|
|
4
|
+
the database by a user (or an attacker who can edit any text column) must never
|
|
5
|
+
let the admin read or delete a file outside that root, whether through an
|
|
6
|
+
absolute path, ``..`` segments or a symlink.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import logging
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def storage_root(storage: Any) -> Path | None:
|
|
19
|
+
"""Return the resolved root directory of ``storage``, or ``None`` when unknown."""
|
|
20
|
+
raw = getattr(storage, "_path", None) or getattr(storage, "path", None)
|
|
21
|
+
if raw is None or callable(raw):
|
|
22
|
+
return None
|
|
23
|
+
try:
|
|
24
|
+
return Path(raw).resolve()
|
|
25
|
+
except (OSError, RuntimeError, TypeError):
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def resolve_storage_path(storage: Any, name: str | None) -> Path | None:
|
|
30
|
+
"""Resolve ``name`` through ``storage`` and return it only if it stays inside the root.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
storage: A ``FileSystemStorage`` (or compatible object exposing ``get_path``
|
|
34
|
+
and a ``_path``/``path`` root).
|
|
35
|
+
name: The stored file name, as held by the file column.
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
The fully resolved path (symlinks followed) when it lies strictly inside
|
|
39
|
+
the storage root, otherwise ``None``. Callers must treat ``None`` as
|
|
40
|
+
"do not touch the filesystem".
|
|
41
|
+
"""
|
|
42
|
+
if storage is None or not name:
|
|
43
|
+
return None
|
|
44
|
+
root = storage_root(storage)
|
|
45
|
+
if root is None:
|
|
46
|
+
return None
|
|
47
|
+
try:
|
|
48
|
+
candidate = Path(storage.get_path(str(name))).resolve()
|
|
49
|
+
except (OSError, RuntimeError, TypeError, ValueError):
|
|
50
|
+
return None
|
|
51
|
+
if candidate == root or root not in candidate.parents:
|
|
52
|
+
logger.warning("Refusing storage path outside the storage root: %r", name)
|
|
53
|
+
return None
|
|
54
|
+
return candidate
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"""Timezone-aware datetime helpers for forms, filters and display.
|
|
2
|
+
|
|
3
|
+
Pure helpers built on the stdlib ``zoneinfo`` and ``datetime`` (plus pydantic's
|
|
4
|
+
``AwareDatetime`` / ``NaiveDatetime`` annotation markers). Columns are
|
|
5
|
+
either *aware* (values are stored as UTC instants) or *naive* (values are stored
|
|
6
|
+
as wall-clock time). User input is entered in a display timezone and converted
|
|
7
|
+
accordingly; aware values are shown back in that timezone.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import functools
|
|
13
|
+
import types
|
|
14
|
+
from datetime import date, datetime, timezone, tzinfo
|
|
15
|
+
from typing import Annotated, Any, Literal, Union, get_args, get_origin
|
|
16
|
+
|
|
17
|
+
from pydantic import AwareDatetime, NaiveDatetime
|
|
18
|
+
|
|
19
|
+
DateTimeKind = Literal["aware", "naive"]
|
|
20
|
+
|
|
21
|
+
AUTO_NOW_MARKER = "__hyperadmin_auto_now__"
|
|
22
|
+
_NOW_NAMES = frozenset({"now", "utcnow"})
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def utc_now() -> datetime:
|
|
26
|
+
"""Return the current time as an aware UTC datetime."""
|
|
27
|
+
return datetime.now(timezone.utc)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
setattr(utc_now, AUTO_NOW_MARKER, True)
|
|
31
|
+
|
|
32
|
+
_KNOWN_NOW_FACTORIES: tuple[Any, ...] = (datetime.now, datetime.utcnow, utc_now)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def is_auto_now_factory(fn: Any) -> bool:
|
|
36
|
+
"""Return ``True`` when ``fn`` is a default factory that stamps "now".
|
|
37
|
+
|
|
38
|
+
Recognised: ``datetime.now``, ``datetime.utcnow``, :func:`utc_now`, partials of
|
|
39
|
+
those, callables marked with ``__hyperadmin_auto_now__ = True``, and lambdas
|
|
40
|
+
that reference ``now`` or ``utcnow``. A named function is deliberately not
|
|
41
|
+
inspected, so it is the escape hatch for an editable datetime default.
|
|
42
|
+
"""
|
|
43
|
+
if fn is None or not callable(fn):
|
|
44
|
+
return False
|
|
45
|
+
if isinstance(fn, functools.partial):
|
|
46
|
+
return is_auto_now_factory(fn.func)
|
|
47
|
+
if getattr(fn, AUTO_NOW_MARKER, False) is True:
|
|
48
|
+
return True
|
|
49
|
+
if any(fn == known for known in _KNOWN_NOW_FACTORIES):
|
|
50
|
+
return True
|
|
51
|
+
code = getattr(fn, "__code__", None)
|
|
52
|
+
if code is None or getattr(fn, "__name__", "") != "<lambda>":
|
|
53
|
+
return False
|
|
54
|
+
return bool(_NOW_NAMES.intersection(code.co_names))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def annotation_datetime_kind(annotation: Any) -> DateTimeKind | None:
|
|
58
|
+
"""Return the datetime kind a type annotation declares, or ``None``.
|
|
59
|
+
|
|
60
|
+
``AwareDatetime`` is ``"aware"``; ``NaiveDatetime``, ``datetime`` and its
|
|
61
|
+
subclasses are ``"naive"``. ``Annotated[...]`` is unwrapped, and an optional
|
|
62
|
+
union (``typing.Optional`` or PEP 604 ``X | None``) resolves to its single
|
|
63
|
+
datetime member. Anything else, including a union of two different kinds,
|
|
64
|
+
is ``None``.
|
|
65
|
+
"""
|
|
66
|
+
origin = get_origin(annotation)
|
|
67
|
+
if origin is Annotated:
|
|
68
|
+
return annotation_datetime_kind(get_args(annotation)[0])
|
|
69
|
+
if origin is Union or origin is types.UnionType:
|
|
70
|
+
kinds: set[DateTimeKind | None]
|
|
71
|
+
kinds = {annotation_datetime_kind(arg) for arg in get_args(annotation)}
|
|
72
|
+
kinds.discard(None)
|
|
73
|
+
return kinds.pop() if len(kinds) == 1 else None
|
|
74
|
+
if annotation is AwareDatetime:
|
|
75
|
+
return "aware"
|
|
76
|
+
if annotation is NaiveDatetime:
|
|
77
|
+
return "naive"
|
|
78
|
+
if isinstance(annotation, type) and issubclass(annotation, datetime):
|
|
79
|
+
return "naive"
|
|
80
|
+
return None
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _fromisoformat(raw: str) -> datetime:
|
|
84
|
+
text = raw.strip()
|
|
85
|
+
if text.endswith(("Z", "z")):
|
|
86
|
+
text = f"{text[:-1]}+00:00"
|
|
87
|
+
return datetime.fromisoformat(text)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def parse_datetime_input(raw: str, *, kind: DateTimeKind, tz: tzinfo) -> datetime:
|
|
91
|
+
"""Parse an ISO-8601 form value for a column of the given ``kind``.
|
|
92
|
+
|
|
93
|
+
- ``aware``: naive input is interpreted in ``tz`` (``fold=0`` in DST gaps and
|
|
94
|
+
overlaps) and returned as aware UTC; explicit offsets are respected.
|
|
95
|
+
- ``naive``: naive input is kept as entered; input with an offset is converted
|
|
96
|
+
to ``tz`` wall-clock time and returned naive.
|
|
97
|
+
|
|
98
|
+
Raises:
|
|
99
|
+
ValueError: When ``raw`` is not a valid ISO-8601 datetime, or converting it
|
|
100
|
+
between zones leaves the supported date range (year 1 to 9999).
|
|
101
|
+
"""
|
|
102
|
+
value = _fromisoformat(raw)
|
|
103
|
+
try:
|
|
104
|
+
if kind == "aware":
|
|
105
|
+
if value.tzinfo is None:
|
|
106
|
+
value = value.replace(tzinfo=tz, fold=0)
|
|
107
|
+
return value.astimezone(timezone.utc)
|
|
108
|
+
if value.tzinfo is not None:
|
|
109
|
+
return value.astimezone(tz).replace(tzinfo=None)
|
|
110
|
+
except OverflowError as exc:
|
|
111
|
+
msg = f"Datetime {raw!r} is out of range after timezone conversion"
|
|
112
|
+
raise ValueError(msg) from exc
|
|
113
|
+
return value
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def format_datetime_input(value: Any, tz: tzinfo) -> str:
|
|
117
|
+
"""Format a value for an ``<input type="datetime-local">`` field.
|
|
118
|
+
|
|
119
|
+
Aware datetimes are converted to ``tz``; the result has second precision and
|
|
120
|
+
no offset. ``None`` becomes ``""``; strings pass through unchanged.
|
|
121
|
+
"""
|
|
122
|
+
if value is None:
|
|
123
|
+
return ""
|
|
124
|
+
if isinstance(value, datetime):
|
|
125
|
+
if value.tzinfo is not None:
|
|
126
|
+
value = value.astimezone(tz).replace(tzinfo=None)
|
|
127
|
+
return value.isoformat(timespec="seconds")
|
|
128
|
+
if isinstance(value, date):
|
|
129
|
+
return value.isoformat()
|
|
130
|
+
return str(value)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def to_display(value: datetime, tz: tzinfo, fmt: str) -> str:
|
|
134
|
+
"""Format ``value`` with ``fmt``, converting only aware values to ``tz``."""
|
|
135
|
+
if value.tzinfo is not None:
|
|
136
|
+
value = value.astimezone(tz)
|
|
137
|
+
return value.strftime(fmt)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""File upload metadata for classify_field() integration."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class FileFieldMeta:
|
|
10
|
+
"""Metadata returned by ``classify_field()`` for file/image columns.
|
|
11
|
+
|
|
12
|
+
Attributes:
|
|
13
|
+
is_image: ``True`` when the column is an ``ImageType``.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
is_image: bool = False
|