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,576 @@
|
|
|
1
|
+
"""Shared state plus permission, primary-key and relation helpers."""
|
|
2
|
+
|
|
3
|
+
import functools
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
from collections.abc import Callable, Generator
|
|
7
|
+
from contextlib import contextmanager
|
|
8
|
+
from types import SimpleNamespace
|
|
9
|
+
from typing import TYPE_CHECKING, Any, cast
|
|
10
|
+
|
|
11
|
+
from fastapi import HTTPException, Request
|
|
12
|
+
from fastapi.templating import Jinja2Templates
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from jinja2 import FileSystemLoader
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
from hyperadmin.adapters import SQLAlchemyAdapter, SQLModelAdapter
|
|
19
|
+
from hyperadmin.core.actions import ActionDef
|
|
20
|
+
from hyperadmin.core.adapters import (
|
|
21
|
+
queryset_scope,
|
|
22
|
+
)
|
|
23
|
+
from hyperadmin.core.choices import SelectFieldMeta
|
|
24
|
+
from hyperadmin.core.discovery import build_filter_metadata
|
|
25
|
+
from hyperadmin.core.display import humanize_class_name, pluralize
|
|
26
|
+
from hyperadmin.core.fields import classify_field
|
|
27
|
+
from hyperadmin.core.inlines import InlineModelSpec
|
|
28
|
+
from hyperadmin.core.options import AdminOptions
|
|
29
|
+
from hyperadmin.core.panels import PanelDef, resolve_panels
|
|
30
|
+
from hyperadmin.core.primary_key import InvalidPrimaryKey, PrimaryKeyInfo
|
|
31
|
+
from hyperadmin.core.registry import site
|
|
32
|
+
from hyperadmin.core.relation_loading import resolve_list_relations
|
|
33
|
+
from hyperadmin.core.schema import dump_instance, schema_for
|
|
34
|
+
from hyperadmin.core.sensitive import (
|
|
35
|
+
is_sensitive,
|
|
36
|
+
is_text_annotation,
|
|
37
|
+
sensitive_field_names,
|
|
38
|
+
sensitive_overrides_scope,
|
|
39
|
+
)
|
|
40
|
+
from hyperadmin.uploads.storage import is_remote_storage
|
|
41
|
+
from hyperadmin.views.forms import (
|
|
42
|
+
InlineFormset,
|
|
43
|
+
)
|
|
44
|
+
from hyperadmin.views.template_filters import TIMEZONE_GLOBAL, request_tz
|
|
45
|
+
from hyperadmin.views.urls import admin_url_for
|
|
46
|
+
|
|
47
|
+
logger = logging.getLogger(__name__)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class DynamicModelViewBase:
|
|
51
|
+
"""Shared state plus permission, primary-key and relation helpers."""
|
|
52
|
+
|
|
53
|
+
def __init__( # noqa: PLR0913, PLR0917
|
|
54
|
+
self,
|
|
55
|
+
adapter: SQLAlchemyAdapter | SQLModelAdapter,
|
|
56
|
+
options: AdminOptions,
|
|
57
|
+
templates: Jinja2Templates,
|
|
58
|
+
app_label: str | None,
|
|
59
|
+
form_include: list[str] | None = None,
|
|
60
|
+
form_create_exclude: list[str] | None = None,
|
|
61
|
+
column_list: list[str] | None = None,
|
|
62
|
+
permission_checker: Any = None,
|
|
63
|
+
actions: list[ActionDef] | None = None,
|
|
64
|
+
admin_instance: Any = None,
|
|
65
|
+
search_fields: list[str] | None = None,
|
|
66
|
+
field_labels: dict[str, str] | None = None,
|
|
67
|
+
storage: Any = None,
|
|
68
|
+
admin_lookup: Callable[[Any], Any] | None = None,
|
|
69
|
+
debug: bool = False,
|
|
70
|
+
occ_render_dialog: bool = True,
|
|
71
|
+
default_page_size: int = 10,
|
|
72
|
+
hook_dispatcher: Callable[..., None] | None = None,
|
|
73
|
+
) -> None:
|
|
74
|
+
self.adapter = adapter
|
|
75
|
+
# ``settings.items_per_page``: the list page size without a ``page_size`` query.
|
|
76
|
+
self.default_page_size = default_page_size
|
|
77
|
+
# ``Admin.dispatch_hook``: fires the app-level plugin lifecycle hooks.
|
|
78
|
+
self._hook_dispatcher = hook_dispatcher
|
|
79
|
+
# ``settings.debug``: list_view re-raises database errors instead of
|
|
80
|
+
# rendering the list-error banner (BYOA SDD D.2).
|
|
81
|
+
self.debug = debug
|
|
82
|
+
self.occ_render_dialog = occ_render_dialog
|
|
83
|
+
self.model = adapter.model
|
|
84
|
+
self.pk: PrimaryKeyInfo = adapter.pk
|
|
85
|
+
self.options = options
|
|
86
|
+
self.templates = templates
|
|
87
|
+
self.app_label = app_label
|
|
88
|
+
self.form_include = form_include
|
|
89
|
+
self.form_create_exclude = form_create_exclude or []
|
|
90
|
+
self.column_list = column_list or [self.pk.attr, "__str__"]
|
|
91
|
+
self.permission_checker = permission_checker
|
|
92
|
+
self._model_name_lower = self.model.__name__.lower()
|
|
93
|
+
self.actions: list[ActionDef] = actions or []
|
|
94
|
+
self._action_map: dict[str, ActionDef] = {a.name: a for a in self.actions}
|
|
95
|
+
self._admin_instance = admin_instance
|
|
96
|
+
self.search_fields = search_fields
|
|
97
|
+
self.field_labels = field_labels or {}
|
|
98
|
+
self.storage = storage
|
|
99
|
+
self._admin_lookup = admin_lookup
|
|
100
|
+
self._fallback_admins: dict[Any, Any] = {}
|
|
101
|
+
# Expose the live adapter on the admin instance so action handlers can use self.adapter
|
|
102
|
+
if admin_instance is not None:
|
|
103
|
+
admin_instance.adapter = self.adapter
|
|
104
|
+
# Detail-page panels (docs/specs/detail-panels.md): ``options.panels``
|
|
105
|
+
# merged with the admin's ``@panel`` methods, slugs checked for
|
|
106
|
+
# collisions and permission codenames filled in — so a duplicate slug
|
|
107
|
+
# fails here, at registration, not on the first request. Without an
|
|
108
|
+
# admin instance (a view built directly) only ``options.panels`` apply.
|
|
109
|
+
panel_source = (
|
|
110
|
+
admin_instance if admin_instance is not None else SimpleNamespace(options=options)
|
|
111
|
+
)
|
|
112
|
+
self.panels: list[PanelDef] = resolve_panels(panel_source, self.model)
|
|
113
|
+
self._panel_map: dict[str, PanelDef] = {p.slug: p for p in self.panels}
|
|
114
|
+
|
|
115
|
+
def _fire_hook(self, hook: str, **kwargs: Any) -> None:
|
|
116
|
+
"""Fire an app-level plugin hook for this view's model (no-op without an admin)."""
|
|
117
|
+
if self._hook_dispatcher is not None:
|
|
118
|
+
self._hook_dispatcher(hook, model=self.model, **kwargs)
|
|
119
|
+
|
|
120
|
+
def _fire_validation_error(self, form: Any) -> None:
|
|
121
|
+
"""Fire ``on_validation_error`` with pydantic error types only (never input values)."""
|
|
122
|
+
self._fire_hook("on_validation_error", field_errors=dict(form.error_types))
|
|
123
|
+
|
|
124
|
+
def _fire_permission_denied(self, request: Request) -> None:
|
|
125
|
+
"""Fire ``on_auth_event("permission_denied")`` for the request's user."""
|
|
126
|
+
user = getattr(request.state, "user", None)
|
|
127
|
+
self._fire_hook(
|
|
128
|
+
"on_auth_event",
|
|
129
|
+
event="permission_denied",
|
|
130
|
+
user=user,
|
|
131
|
+
username=getattr(user, "username", None),
|
|
132
|
+
request=request,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
def _verbose_labels(self) -> dict[str, str]:
|
|
136
|
+
"""Template context with the model's readable names.
|
|
137
|
+
|
|
138
|
+
``verbose_name`` / ``verbose_name_plural`` come from the ``ModelAdmin``; with no
|
|
139
|
+
``verbose_name`` set, the CamelCase class name is split into words. The
|
|
140
|
+
``_lower`` form keeps a leading acronym (``HTTP log``) and lowercases other
|
|
141
|
+
initials, for use inside a sentence ("Create journal line").
|
|
142
|
+
"""
|
|
143
|
+
model = self.model
|
|
144
|
+
admin = self._admin_instance
|
|
145
|
+
singular = humanize_class_name(model.__name__)
|
|
146
|
+
plural = pluralize(singular)
|
|
147
|
+
declared_name = False
|
|
148
|
+
if admin is not None and hasattr(admin, "get_verbose_name"):
|
|
149
|
+
declared = str(admin.get_verbose_name(model))
|
|
150
|
+
if getattr(admin, "verbose_name", None) is not None:
|
|
151
|
+
singular = declared
|
|
152
|
+
declared_name = True
|
|
153
|
+
plural = str(admin.get_verbose_name_plural(model))
|
|
154
|
+
first = singular.split(" ", 1)[0]
|
|
155
|
+
# A declared name is used as given ("Acme invoice", German nouns); only a
|
|
156
|
+
# name derived from the class gets its initial lowercased.
|
|
157
|
+
keep_case = declared_name or (len(first) > 1 and first.isupper())
|
|
158
|
+
lower = singular if keep_case else singular[:1].lower() + singular[1:]
|
|
159
|
+
return {
|
|
160
|
+
"verbose_name": singular,
|
|
161
|
+
"verbose_name_lower": lower,
|
|
162
|
+
"verbose_name_plural": plural,
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async def _has_permission(self, request: Request, codename: str) -> bool:
|
|
166
|
+
"""Return whether the request's user holds ``codename`` (always true without auth)."""
|
|
167
|
+
if self.permission_checker is None:
|
|
168
|
+
return True
|
|
169
|
+
user = getattr(request.state, "user", None)
|
|
170
|
+
if user is None:
|
|
171
|
+
raise HTTPException(status_code=403, detail="Authentication required")
|
|
172
|
+
return bool(await self.permission_checker.has_permission(user, codename))
|
|
173
|
+
|
|
174
|
+
async def _check_permission(
|
|
175
|
+
self, request: Request, action: str, *, model_name: str | None = None
|
|
176
|
+
) -> None:
|
|
177
|
+
"""Raise 403 if the user lacks the required permission.
|
|
178
|
+
|
|
179
|
+
``model_name`` defaults to this view's model; pass another lowercase model
|
|
180
|
+
name to check a related model (choices target, inline model).
|
|
181
|
+
|
|
182
|
+
Does nothing when ``permission_checker`` is ``None`` (auth disabled).
|
|
183
|
+
"""
|
|
184
|
+
codename = f"{action}_{model_name or self._model_name_lower}"
|
|
185
|
+
if not await self._has_permission(request, codename):
|
|
186
|
+
self._fire_permission_denied(request)
|
|
187
|
+
raise HTTPException(status_code=403, detail="Permission denied")
|
|
188
|
+
|
|
189
|
+
async def _check_any_permission(self, request: Request, actions: tuple[str, ...]) -> None:
|
|
190
|
+
"""Raise 403 unless the user holds at least one of ``actions`` on this model."""
|
|
191
|
+
for action in actions:
|
|
192
|
+
if await self._has_permission(request, f"{action}_{self._model_name_lower}"):
|
|
193
|
+
return
|
|
194
|
+
self._fire_permission_denied(request)
|
|
195
|
+
raise HTTPException(status_code=403, detail="Permission denied")
|
|
196
|
+
|
|
197
|
+
async def _record_actions(self, request: Request) -> dict[str, bool]:
|
|
198
|
+
"""Which record-page links this user gets: Edit, View and Delete (st-v059-list-02).
|
|
199
|
+
|
|
200
|
+
Gated like the list rows: the page option and the model-level
|
|
201
|
+
permission. The page each link opens still runs its own object check.
|
|
202
|
+
"""
|
|
203
|
+
model = self._model_name_lower
|
|
204
|
+
options = self.options
|
|
205
|
+
return {
|
|
206
|
+
"user_can_edit": options.can_edit
|
|
207
|
+
and await self._has_permission(request, f"change_{model}"),
|
|
208
|
+
"user_can_view": options.can_detail
|
|
209
|
+
and await self._has_permission(request, f"view_{model}"),
|
|
210
|
+
"user_can_delete": options.can_delete
|
|
211
|
+
and await self._has_permission(request, f"delete_{model}"),
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
def _admin_for_model(self, model: Any) -> Any:
|
|
215
|
+
"""Return the registered ``ModelAdmin`` instance for ``model`` (or ``None``)."""
|
|
216
|
+
if model is self.model:
|
|
217
|
+
return self._admin_instance
|
|
218
|
+
if self._admin_lookup is not None:
|
|
219
|
+
return self._admin_lookup(model)
|
|
220
|
+
if model not in self._fallback_admins:
|
|
221
|
+
admin_class = site._registry.get(model)
|
|
222
|
+
self._fallback_admins[model] = admin_class(model) if admin_class else None
|
|
223
|
+
return self._fallback_admins[model]
|
|
224
|
+
|
|
225
|
+
def _is_registered(self, model: Any) -> bool:
|
|
226
|
+
"""Return whether ``model`` has its own registered admin (and thus permission rows)."""
|
|
227
|
+
return model is self.model or self._admin_for_model(model) is not None
|
|
228
|
+
|
|
229
|
+
async def _may_view_related(self, request: Request, target_model: Any) -> bool:
|
|
230
|
+
"""Return whether rows of ``target_model`` may be disclosed to the request's user.
|
|
231
|
+
|
|
232
|
+
Single gate for every path that embeds related rows: the choices
|
|
233
|
+
endpoint, list-page FK filters and the create/edit relation widgets.
|
|
234
|
+
A registered target needs ``view_<target>``. An unregistered target has
|
|
235
|
+
no permission rows that could ever be granted, so it falls back to the
|
|
236
|
+
source model's permission, which every caller has already checked.
|
|
237
|
+
"""
|
|
238
|
+
if target_model is None or not self._is_registered(target_model):
|
|
239
|
+
return True
|
|
240
|
+
return await self._has_permission(request, f"view_{target_model.__name__.lower()}")
|
|
241
|
+
|
|
242
|
+
def _relation_target_for_field(self, name: str) -> Any:
|
|
243
|
+
"""Return the target class of the relation rendered for field ``name`` (or ``None``)."""
|
|
244
|
+
rel_name = self._fk_to_relation().get(name) or name
|
|
245
|
+
return self._relation_targets().get(rel_name)
|
|
246
|
+
|
|
247
|
+
def _queryset_filter_for(self, model: Any) -> Callable[[Any], dict[str, Any]] | None:
|
|
248
|
+
"""Return the ``get_queryset`` callable that scopes rows of ``model``."""
|
|
249
|
+
get_queryset = getattr(self._admin_for_model(model), "get_queryset", None)
|
|
250
|
+
if get_queryset is None:
|
|
251
|
+
return None
|
|
252
|
+
|
|
253
|
+
def _filter(req: Any) -> dict[str, Any]:
|
|
254
|
+
result = get_queryset(req)
|
|
255
|
+
return result if isinstance(result, dict) else {}
|
|
256
|
+
|
|
257
|
+
return _filter
|
|
258
|
+
|
|
259
|
+
@contextmanager
|
|
260
|
+
def _request_queryset_filter(self, request: Request) -> Generator[None, None, None]:
|
|
261
|
+
"""Activate this request's row scoping for every adapter call made inside the block.
|
|
262
|
+
|
|
263
|
+
Composes :meth:`hyperadmin.core.model.ModelAdmin.get_queryset` of this view's
|
|
264
|
+
model (and of related models, for the choices endpoint) into a
|
|
265
|
+
request-scoped :func:`hyperadmin.core.adapters.queryset_scope`. The scope is
|
|
266
|
+
held in a ``ContextVar``, never on the shared adapter instance, so
|
|
267
|
+
concurrent requests cannot observe each other's filters.
|
|
268
|
+
"""
|
|
269
|
+
with (
|
|
270
|
+
queryset_scope(request, self._queryset_filter_for),
|
|
271
|
+
sensitive_overrides_scope(self._sensitive_overrides_for),
|
|
272
|
+
):
|
|
273
|
+
yield
|
|
274
|
+
|
|
275
|
+
def _sensitive_overrides_for(self, model: Any) -> Any:
|
|
276
|
+
"""Return ``AdminOptions.sensitive_fields`` of the admin registered for ``model``."""
|
|
277
|
+
options = self.options if model is self.model else None
|
|
278
|
+
if options is None:
|
|
279
|
+
options = getattr(self._admin_for_model(model), "options", None)
|
|
280
|
+
return getattr(options, "sensitive_fields", None) or None
|
|
281
|
+
|
|
282
|
+
def _fk_to_relation(self) -> dict[str, str]:
|
|
283
|
+
"""Map each FK column on the model to the name of its ORM relationship."""
|
|
284
|
+
fk_to_rel: dict[str, str] = {}
|
|
285
|
+
inspector = getattr(self.adapter, "inspector", None)
|
|
286
|
+
if inspector:
|
|
287
|
+
for rel in inspector.relationships:
|
|
288
|
+
for col in getattr(rel, "local_columns", []):
|
|
289
|
+
col_key = getattr(col, "key", None) or getattr(col, "name", None)
|
|
290
|
+
if col_key:
|
|
291
|
+
fk_to_rel[col_key] = rel.key
|
|
292
|
+
return fk_to_rel
|
|
293
|
+
|
|
294
|
+
def _declared_cascade_keys(self, rel_name: str) -> set[str]:
|
|
295
|
+
"""Return the parent-field names a relation widget declares it depends on.
|
|
296
|
+
|
|
297
|
+
Sources: ``SelectFieldMeta.dependent_on``, ``AdminOptions.dependent_fields``
|
|
298
|
+
and ``AdminOptions.relation_filters``, keyed by the FK column (or the
|
|
299
|
+
relationship name) that renders the ``rel_name`` widget. Sensitive names
|
|
300
|
+
are never accepted.
|
|
301
|
+
"""
|
|
302
|
+
fk_to_rel = self._fk_to_relation()
|
|
303
|
+
owners = {name for name, rel in fk_to_rel.items() if rel == rel_name} | {rel_name}
|
|
304
|
+
dependent_fields = getattr(self.options, "dependent_fields", None) or {}
|
|
305
|
+
relation_filters = getattr(self.options, "relation_filters", None) or {}
|
|
306
|
+
model_fields = schema_for(self.model).model_fields
|
|
307
|
+
keys: set[str] = set()
|
|
308
|
+
for name in owners:
|
|
309
|
+
if dependent_fields.get(name):
|
|
310
|
+
keys.add(dependent_fields[name])
|
|
311
|
+
dependency = relation_filters.get(name)
|
|
312
|
+
if dependency is not None:
|
|
313
|
+
keys.add(dependency.depends_on)
|
|
314
|
+
field_info = model_fields.get(name)
|
|
315
|
+
if field_info is not None:
|
|
316
|
+
meta = classify_field(field_info, self.model)
|
|
317
|
+
if isinstance(meta, SelectFieldMeta) and meta.dependent_on:
|
|
318
|
+
keys.add(meta.dependent_on)
|
|
319
|
+
return {k for k in keys if k not in self._sensitive_fields and not is_sensitive(k)}
|
|
320
|
+
|
|
321
|
+
def _relation_targets(self) -> dict[str, Any]:
|
|
322
|
+
"""Map each ORM relationship name on the model to its target class (or ``None``)."""
|
|
323
|
+
inspector = getattr(self.adapter, "inspector", None)
|
|
324
|
+
if not inspector:
|
|
325
|
+
return {}
|
|
326
|
+
return {
|
|
327
|
+
rel.key: getattr(getattr(rel, "mapper", None), "class_", None)
|
|
328
|
+
for rel in inspector.relationships
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
def _resolve_pk(self, item_id: Any) -> Any:
|
|
332
|
+
"""Parse a raw ``item_id`` into this model's typed key, or raise 404."""
|
|
333
|
+
try:
|
|
334
|
+
return self.pk.parse(item_id)
|
|
335
|
+
except InvalidPrimaryKey as exc:
|
|
336
|
+
raise HTTPException(status_code=404, detail="Item not found") from exc
|
|
337
|
+
|
|
338
|
+
def _form_pk_kwargs(self, *, create: bool) -> dict[str, Any]:
|
|
339
|
+
"""``PydanticForm`` pk options: a natural (non-generated) key is an input on create only."""
|
|
340
|
+
return {"pk_attr": self.pk.attr, "pk_editable": create and not self.pk.generated}
|
|
341
|
+
|
|
342
|
+
@staticmethod
|
|
343
|
+
def _stored_values(item: Any) -> dict[str, Any]:
|
|
344
|
+
"""The stored field values of ``item`` (schema dump, else ``__dict__``)."""
|
|
345
|
+
try:
|
|
346
|
+
return dump_instance(item)
|
|
347
|
+
except TypeError: # not a model the schema registry knows (e.g. a plain record)
|
|
348
|
+
return dict(getattr(item, "__dict__", {}))
|
|
349
|
+
|
|
350
|
+
def _form_datetime_kwargs(self, request: Request) -> dict[str, Any]:
|
|
351
|
+
"""``PydanticForm`` datetime options: the request's display timezone and column kinds."""
|
|
352
|
+
default_tz = self.templates.env.globals.get(TIMEZONE_GLOBAL)
|
|
353
|
+
return {
|
|
354
|
+
"timezone": request_tz(request, default_tz),
|
|
355
|
+
"datetime_kind": self.adapter.datetime_kind,
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
def _inline_formset(self, spec: InlineModelSpec, **kwargs: Any) -> InlineFormset:
|
|
359
|
+
"""Build a formset that parses submitted child keys with the inline model's own codec."""
|
|
360
|
+
return InlineFormset(spec=spec, pk=self.adapter.for_model(spec.model).pk, **kwargs)
|
|
361
|
+
|
|
362
|
+
async def _get_or_404(self, item_id: Any) -> Any:
|
|
363
|
+
"""Load ``item_id`` under the active queryset scope or raise 404."""
|
|
364
|
+
detail_relations = getattr(self.options, "detail_select_related", None)
|
|
365
|
+
# Only passed when configured, so adapters that predate load_relations keep working.
|
|
366
|
+
load = {} if detail_relations is None else {"load_relations": detail_relations}
|
|
367
|
+
item = await self.adapter.get(pk=item_id, **load)
|
|
368
|
+
if not item:
|
|
369
|
+
raise HTTPException(status_code=404, detail="Item not found")
|
|
370
|
+
return item
|
|
371
|
+
|
|
372
|
+
def _list_load_kwargs(self) -> dict[str, Any]:
|
|
373
|
+
"""``load_relations`` for ``adapter.list()``, empty when no relation needs loading."""
|
|
374
|
+
relations = resolve_list_relations(
|
|
375
|
+
getattr(self.options, "list_select_related", None),
|
|
376
|
+
self.column_list,
|
|
377
|
+
self._relation_targets().keys(),
|
|
378
|
+
auto=getattr(self.options, "auto_select_related", True),
|
|
379
|
+
)
|
|
380
|
+
return {"load_relations": relations} if relations else {}
|
|
381
|
+
|
|
382
|
+
async def _check_object_permission(self, request: Request, obj: Any, action: str) -> None:
|
|
383
|
+
"""Raise 403 if ``obj`` fails the configured object-level permission check.
|
|
384
|
+
|
|
385
|
+
Does nothing when ``options.object_permission_checker`` is ``None``
|
|
386
|
+
(backward compatible — model-level :class:`PermissionChecker` enforcement
|
|
387
|
+
remains the only authz layer in that case).
|
|
388
|
+
|
|
389
|
+
Args:
|
|
390
|
+
request: The active request — its ``state.user`` is forwarded to the
|
|
391
|
+
checker.
|
|
392
|
+
obj: The object the user is attempting to act on.
|
|
393
|
+
action: One of ``"view"``, ``"add"``, ``"change"``, ``"delete"`` (or a
|
|
394
|
+
custom codename understood by the checker).
|
|
395
|
+
"""
|
|
396
|
+
checker = getattr(self.options, "object_permission_checker", None)
|
|
397
|
+
if checker is None:
|
|
398
|
+
return
|
|
399
|
+
user = getattr(request.state, "user", None)
|
|
400
|
+
if user is None:
|
|
401
|
+
raise HTTPException(status_code=403, detail="Authentication required")
|
|
402
|
+
if not await checker.has_object_permission(user, obj, action):
|
|
403
|
+
raise HTTPException(status_code=403, detail="Permission denied")
|
|
404
|
+
|
|
405
|
+
def _get_template_name(self, view_name: str) -> str:
|
|
406
|
+
model_name = self.model.__name__.lower()
|
|
407
|
+
|
|
408
|
+
potential_templates = []
|
|
409
|
+
if self.app_label:
|
|
410
|
+
potential_templates.extend(
|
|
411
|
+
[
|
|
412
|
+
f"{self.app_label}/{model_name}/{view_name}.html",
|
|
413
|
+
f"{self.app_label}/{model_name}/default.html",
|
|
414
|
+
f"{self.app_label}/{view_name}.html",
|
|
415
|
+
f"{self.app_label}/default.html",
|
|
416
|
+
]
|
|
417
|
+
)
|
|
418
|
+
potential_templates.extend(
|
|
419
|
+
[
|
|
420
|
+
f"{view_name}.html",
|
|
421
|
+
"default.html",
|
|
422
|
+
]
|
|
423
|
+
)
|
|
424
|
+
|
|
425
|
+
for template_path in potential_templates:
|
|
426
|
+
if self.templates.env.loader:
|
|
427
|
+
# Cast to FileSystemLoader to access the searchpath attribute
|
|
428
|
+
loader = cast("FileSystemLoader", self.templates.env.loader)
|
|
429
|
+
for search_path in loader.searchpath:
|
|
430
|
+
full_path = os.path.join(search_path, template_path)
|
|
431
|
+
if os.path.exists(full_path):
|
|
432
|
+
return template_path
|
|
433
|
+
|
|
434
|
+
return f"{view_name}.html"
|
|
435
|
+
|
|
436
|
+
async def _get_filter_metadata(self, request: Request) -> list[dict[str, Any]]:
|
|
437
|
+
"""Introspects list_filter fields to build metadata for filter UI.
|
|
438
|
+
|
|
439
|
+
A relation filter lists rows of the target model, so it is only built
|
|
440
|
+
when the user may view that model (see :meth:`_may_view_related`).
|
|
441
|
+
"""
|
|
442
|
+
allowed = self._filterable_fields()
|
|
443
|
+
fields = [
|
|
444
|
+
f
|
|
445
|
+
for f in (self.options.list_filter or [])
|
|
446
|
+
if isinstance(f, str)
|
|
447
|
+
and f in allowed
|
|
448
|
+
and await self._may_view_related(request, self._relation_target_for_field(f))
|
|
449
|
+
]
|
|
450
|
+
return await build_filter_metadata(
|
|
451
|
+
self.model, fields, self.adapter, self._applied_filter_values(request, fields)
|
|
452
|
+
)
|
|
453
|
+
|
|
454
|
+
@staticmethod
|
|
455
|
+
def _applied_filter_values(request: Request, fields: list[str]) -> dict[str, list[str]]:
|
|
456
|
+
"""Raw filter values in the query string, keyed by field (``filter_x`` and ``x__in``)."""
|
|
457
|
+
params = request.query_params
|
|
458
|
+
return {
|
|
459
|
+
f: [v for v in [*params.getlist(f"filter_{f}"), *params.getlist(f"{f}__in")] if v]
|
|
460
|
+
for f in fields
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
@functools.cached_property
|
|
464
|
+
def _sensitive_fields(self) -> frozenset[str]:
|
|
465
|
+
"""Names of the model's sensitive fields (see :mod:`hyperadmin.core.sensitive`)."""
|
|
466
|
+
overrides = getattr(self.options, "sensitive_fields", None) or None
|
|
467
|
+
return frozenset(sensitive_field_names(self.model, overrides))
|
|
468
|
+
|
|
469
|
+
def _without_sensitive(self, values: dict[str, Any]) -> dict[str, Any]:
|
|
470
|
+
"""Return ``values`` without sensitive keys (detail page, form initial values)."""
|
|
471
|
+
return {k: v for k, v in values.items() if k not in self._sensitive_fields}
|
|
472
|
+
|
|
473
|
+
@functools.cached_property
|
|
474
|
+
def _opaque_sensitive_fields(self) -> list[str]:
|
|
475
|
+
"""Sensitive fields that cannot be write-only inputs (booleans, enums, numbers...).
|
|
476
|
+
|
|
477
|
+
A blank text input can mean "keep the stored value"; a checkbox or a
|
|
478
|
+
select cannot, so these fields are left out of the edit form entirely
|
|
479
|
+
and always keep their stored value on update.
|
|
480
|
+
"""
|
|
481
|
+
model_fields = schema_for(self.model).model_fields
|
|
482
|
+
return sorted(
|
|
483
|
+
name
|
|
484
|
+
for name in self._sensitive_fields
|
|
485
|
+
if name in model_fields and not is_text_annotation(model_fields[name].annotation)
|
|
486
|
+
)
|
|
487
|
+
|
|
488
|
+
def _keep_stored_secrets(self, data: dict[str, Any], existing: Any) -> None:
|
|
489
|
+
"""Write-only semantics for sensitive fields on update.
|
|
490
|
+
|
|
491
|
+
An empty text input keeps the stored value. A non-text sensitive field
|
|
492
|
+
is not on the edit form, so its stored value is always kept.
|
|
493
|
+
"""
|
|
494
|
+
opaque = set(self._opaque_sensitive_fields)
|
|
495
|
+
for name in self._sensitive_fields:
|
|
496
|
+
if name not in schema_for(self.model).model_fields:
|
|
497
|
+
continue
|
|
498
|
+
if name in opaque or data.get(name) in (None, ""):
|
|
499
|
+
data[name] = getattr(existing, name, None)
|
|
500
|
+
|
|
501
|
+
def _filterable_fields(self) -> set[str]:
|
|
502
|
+
"""Fields a URL ``filter_<name>`` may target: ``list_filter`` strings, never sensitive.
|
|
503
|
+
|
|
504
|
+
Explicit :class:`FilterDef` entries read their own querystring keys
|
|
505
|
+
(see :meth:`_explicit_filters`) and are not part of this set.
|
|
506
|
+
"""
|
|
507
|
+
model_fields = schema_for(self.model).model_fields
|
|
508
|
+
return {
|
|
509
|
+
f
|
|
510
|
+
for f in (getattr(self.options, "list_filter", None) or [])
|
|
511
|
+
if isinstance(f, str) and f in model_fields and f not in self._sensitive_fields
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
def _sortable_fields(self) -> set[str]:
|
|
515
|
+
"""Fields ``sort_by`` may target: displayed, real, non-sensitive model fields."""
|
|
516
|
+
model_fields = schema_for(self.model).model_fields
|
|
517
|
+
return {
|
|
518
|
+
f for f in self.column_list if f in model_fields and f not in self._sensitive_fields
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
def _default_sort_field(self) -> str:
|
|
522
|
+
"""The first non-sensitive model field (the pk attribute when there is none)."""
|
|
523
|
+
model_fields = schema_for(self.model).model_fields
|
|
524
|
+
return next((f for f in model_fields if f not in self._sensitive_fields), self.pk.attr)
|
|
525
|
+
|
|
526
|
+
def _get_file_fields(self) -> set[str]:
|
|
527
|
+
"""Return the set of field names backed by FileType/ImageType columns."""
|
|
528
|
+
from hyperadmin.core.uploads import FileFieldMeta # noqa: PLC0415
|
|
529
|
+
|
|
530
|
+
result: set[str] = set()
|
|
531
|
+
for name, fi in schema_for(self.model).model_fields.items():
|
|
532
|
+
meta = classify_field(fi, self.model)
|
|
533
|
+
if isinstance(meta, FileFieldMeta):
|
|
534
|
+
result.add(name)
|
|
535
|
+
return result
|
|
536
|
+
|
|
537
|
+
def _get_image_fields(self) -> set[str]:
|
|
538
|
+
"""Return the set of field names backed by ``ImageType`` columns."""
|
|
539
|
+
from hyperadmin.core.uploads import FileFieldMeta # noqa: PLC0415
|
|
540
|
+
|
|
541
|
+
result: set[str] = set()
|
|
542
|
+
for name, fi in schema_for(self.model).model_fields.items():
|
|
543
|
+
meta = classify_field(fi, self.model)
|
|
544
|
+
if isinstance(meta, FileFieldMeta) and meta.is_image:
|
|
545
|
+
result.add(name)
|
|
546
|
+
return result
|
|
547
|
+
|
|
548
|
+
def _thumbnail_urls(
|
|
549
|
+
self,
|
|
550
|
+
request: Request,
|
|
551
|
+
item_id: Any,
|
|
552
|
+
item_data: dict[str, Any],
|
|
553
|
+
variant: str,
|
|
554
|
+
fields: set[str] | None = None,
|
|
555
|
+
) -> dict[str, str]:
|
|
556
|
+
"""Map each non-empty image field to its ``variant`` thumbnail URL.
|
|
557
|
+
|
|
558
|
+
Empty for a remote storage: thumbnails are cut from local files only.
|
|
559
|
+
"""
|
|
560
|
+
if not self.storage or is_remote_storage(self.storage):
|
|
561
|
+
return {}
|
|
562
|
+
route_name = f"{self._model_name_lower}-file"
|
|
563
|
+
image_fields = self._get_image_fields() if fields is None else fields
|
|
564
|
+
return {
|
|
565
|
+
name: str(
|
|
566
|
+
admin_url_for(
|
|
567
|
+
request, route_name, item_id=item_id, field_name=name
|
|
568
|
+
).include_query_params(thumb=variant)
|
|
569
|
+
)
|
|
570
|
+
for name in sorted(image_fields)
|
|
571
|
+
if item_data.get(name)
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
def _list_path(self, request: Request) -> str:
|
|
575
|
+
"""The list URL's path for this request (``root_path`` and mount prefix included)."""
|
|
576
|
+
return admin_url_for(request, f"{self._model_name_lower}-list").path
|