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,239 @@
|
|
|
1
|
+
"""Build Pydantic schema classes from plain SQLAlchemy mapped classes.
|
|
2
|
+
|
|
3
|
+
SQLModel and Pydantic models are their own schema (identity in ``core.schema``). A
|
|
4
|
+
plain ``DeclarativeBase`` model has no ``model_fields``, so this module generates a
|
|
5
|
+
``pydantic.create_model`` class from its mapper: one field per single-column
|
|
6
|
+
``ColumnProperty``, with the annotation, optionality and defaults the views expect
|
|
7
|
+
(SDD ``docs/specs/sqlalchemy-field-metadata.md``). The builder is registered with
|
|
8
|
+
``schema_registry`` in :mod:`hyperadmin.adapters`.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import importlib
|
|
14
|
+
import inspect
|
|
15
|
+
import logging
|
|
16
|
+
import types
|
|
17
|
+
from typing import Annotated, Any, Literal, Union, get_args, get_origin, get_type_hints
|
|
18
|
+
|
|
19
|
+
from pydantic import BaseModel, ConfigDict, Field, create_model
|
|
20
|
+
from sqlalchemy import Column, ColumnDefault, Integer, String
|
|
21
|
+
from sqlalchemy.dialects import mysql
|
|
22
|
+
from sqlalchemy.inspection import inspect as sa_inspect
|
|
23
|
+
from sqlalchemy.orm import ColumnProperty, Mapped, Mapper
|
|
24
|
+
from sqlalchemy.sql.sqltypes import JSON
|
|
25
|
+
from sqlalchemy.sql.sqltypes import Enum as SAEnum
|
|
26
|
+
from sqlalchemy.types import TypeDecorator, TypeEngine
|
|
27
|
+
|
|
28
|
+
logger = logging.getLogger(__name__)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def is_sqlalchemy_mapped(model: object) -> bool:
|
|
32
|
+
"""Return ``True`` for a mapped SQLAlchemy class that is not a Pydantic model."""
|
|
33
|
+
if not isinstance(model, type) or issubclass(model, BaseModel):
|
|
34
|
+
return False
|
|
35
|
+
return isinstance(sa_inspect(model, raiseerr=False), Mapper)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _base_hints(base: type) -> dict[str, Any]:
|
|
39
|
+
"""Hints for one class: resolved when possible, else its non-string raw annotations."""
|
|
40
|
+
try:
|
|
41
|
+
return get_type_hints(base, include_extras=False)
|
|
42
|
+
except Exception:
|
|
43
|
+
try:
|
|
44
|
+
raw = inspect.get_annotations(base)
|
|
45
|
+
except NameError:
|
|
46
|
+
# Python 3.14 evaluates annotations lazily: a relationship typed with a class
|
|
47
|
+
# imported only under TYPE_CHECKING raises here instead of staying a string.
|
|
48
|
+
annotationlib = importlib.import_module("annotationlib") # exists on 3.14 only
|
|
49
|
+
raw = annotationlib.get_annotations(base, format=annotationlib.Format.FORWARDREF)
|
|
50
|
+
return {k: v for k, v in raw.items() if not isinstance(v, str)}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _mapped_hints(model: type) -> dict[str, Any]:
|
|
54
|
+
"""Resolve type hints for ``model``, tolerating unresolvable forward references."""
|
|
55
|
+
try:
|
|
56
|
+
return get_type_hints(model, include_extras=False)
|
|
57
|
+
except Exception:
|
|
58
|
+
hints: dict[str, Any] = {}
|
|
59
|
+
for base in reversed(model.__mro__):
|
|
60
|
+
hints.update(_base_hints(base))
|
|
61
|
+
return hints
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _strip_none(annotation: Any) -> Any:
|
|
65
|
+
"""Remove ``None`` from an optional union, leaving the other members."""
|
|
66
|
+
origin = get_origin(annotation)
|
|
67
|
+
if origin is Union or origin is types.UnionType:
|
|
68
|
+
members = tuple(arg for arg in get_args(annotation) if arg is not type(None))
|
|
69
|
+
if len(members) == 1:
|
|
70
|
+
return members[0]
|
|
71
|
+
return Union[members] # noqa: UP007 - built dynamically from a tuple
|
|
72
|
+
return annotation
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _is_optional(annotation: Any) -> bool:
|
|
76
|
+
origin = get_origin(annotation)
|
|
77
|
+
return (origin is Union or origin is types.UnionType) and type(None) in get_args(annotation)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _is_sa_type(annotation: Any) -> bool:
|
|
81
|
+
"""Whether ``annotation`` is a SQLAlchemy type class such as a ``TypeDecorator``."""
|
|
82
|
+
return isinstance(annotation, type) and issubclass(annotation, TypeEngine)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _prefer_column_scalar(annotation: Any, column: Column[Any]) -> Any:
|
|
86
|
+
"""Return ``annotation``, unless it says ``str`` over a bool, int or float column.
|
|
87
|
+
|
|
88
|
+
``Mapped[str | None] = mapped_column(Boolean)`` is a mis-annotation seen in real
|
|
89
|
+
apps. Trusting it makes the field text: searched with ``ILIKE`` (an error on
|
|
90
|
+
Postgres) and shown as a text input. A numeric or boolean column keeps its own type;
|
|
91
|
+
the caller applies nullability.
|
|
92
|
+
"""
|
|
93
|
+
if annotation is not str:
|
|
94
|
+
return annotation
|
|
95
|
+
try:
|
|
96
|
+
column_type = column.type.python_type
|
|
97
|
+
except NotImplementedError:
|
|
98
|
+
return annotation
|
|
99
|
+
if column_type not in (bool, int, float):
|
|
100
|
+
return annotation
|
|
101
|
+
return column_type
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _resolve_annotation(model: type, key: str, column: Column[Any], hints: dict[str, Any]) -> Any:
|
|
105
|
+
"""Pick the field annotation: ``Mapped[X]`` first, then the column's Python type."""
|
|
106
|
+
hint = hints.get(key)
|
|
107
|
+
if get_origin(hint) is Mapped:
|
|
108
|
+
args = get_args(hint)
|
|
109
|
+
# ``Mapped[GUID]`` names a SQLAlchemy type, not a Python one: use the column's.
|
|
110
|
+
# The unresolved-hints fallback keeps ``Annotated[T, mapped_column(...)]`` wrapped;
|
|
111
|
+
# ``get_type_hints`` strips it.
|
|
112
|
+
inner = _strip_none(args[0]) if args else None
|
|
113
|
+
if get_origin(inner) is Annotated:
|
|
114
|
+
inner = _strip_none(get_args(inner)[0])
|
|
115
|
+
if args and not isinstance(args[0], str) and not _is_sa_type(inner):
|
|
116
|
+
return _prefer_column_scalar(inner, column)
|
|
117
|
+
sa_type = column.type
|
|
118
|
+
if isinstance(sa_type, JSON):
|
|
119
|
+
return dict | list | Any
|
|
120
|
+
try:
|
|
121
|
+
return sa_type.python_type
|
|
122
|
+
except NotImplementedError:
|
|
123
|
+
pass
|
|
124
|
+
if isinstance(sa_type, TypeDecorator):
|
|
125
|
+
try:
|
|
126
|
+
return sa_type.impl_instance.python_type
|
|
127
|
+
except NotImplementedError:
|
|
128
|
+
pass
|
|
129
|
+
logger.debug("No Python type for %s.%s (%r); using Any", model.__name__, key, sa_type)
|
|
130
|
+
return Any
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _is_server_generated_pk(column: Column[Any], *, shared_pk: bool) -> bool:
|
|
134
|
+
if not column.primary_key:
|
|
135
|
+
return False
|
|
136
|
+
if shared_pk:
|
|
137
|
+
return True
|
|
138
|
+
return isinstance(column.type, Integer) and column.autoincrement in (True, "auto")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _default_kwargs(column: Column[Any], *, shared_pk: bool) -> dict[str, Any]:
|
|
142
|
+
"""Return ``default`` / ``default_factory`` kwargs, or ``{}`` when required."""
|
|
143
|
+
if column.server_default is not None or _is_server_generated_pk(column, shared_pk=shared_pk):
|
|
144
|
+
return {"default": None}
|
|
145
|
+
default = column.default
|
|
146
|
+
if isinstance(default, ColumnDefault):
|
|
147
|
+
if default.is_scalar:
|
|
148
|
+
return {"default": default.arg}
|
|
149
|
+
if default.is_callable:
|
|
150
|
+
# SQLAlchemy wraps context-free callables as ``lambda ctx: fn()`` and keeps
|
|
151
|
+
# the original on ``__wrapped__``. A callable that needs the context
|
|
152
|
+
# cannot run without a statement, so the ORM fills it in instead.
|
|
153
|
+
original = getattr(default.arg, "__wrapped__", None)
|
|
154
|
+
if original is not None:
|
|
155
|
+
return {"default_factory": original}
|
|
156
|
+
return {"default": None}
|
|
157
|
+
if default is not None or column.nullable:
|
|
158
|
+
return {"default": None}
|
|
159
|
+
return {}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _auto_now_hint(column: Column[Any]) -> dict[str, Any]:
|
|
163
|
+
kwargs: dict[str, Any] = {}
|
|
164
|
+
if column.server_default is not None:
|
|
165
|
+
kwargs["server_default"] = repr(getattr(column.server_default, "arg", None))
|
|
166
|
+
if column.onupdate is not None:
|
|
167
|
+
kwargs["onupdate"] = repr(getattr(column.onupdate, "arg", None))
|
|
168
|
+
return {"sa_column_kwargs": kwargs} if kwargs else {}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _column_for(prop: ColumnProperty[Any]) -> tuple[Column[Any], bool] | None:
|
|
172
|
+
"""Return ``(column, shared_pk)`` for a property that maps one editable column."""
|
|
173
|
+
columns = prop.columns
|
|
174
|
+
shared = len(columns) > 1 and all(getattr(c, "primary_key", False) for c in columns)
|
|
175
|
+
if shared:
|
|
176
|
+
# Joined-table inheritance: the subclass pk is the parent pk.
|
|
177
|
+
columns = columns[:1]
|
|
178
|
+
if len(columns) != 1 or not isinstance(columns[0], Column):
|
|
179
|
+
return None
|
|
180
|
+
return columns[0], shared
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def _bare_enum_annotation(column: Column[Any], annotation: Any) -> Any:
|
|
184
|
+
"""Type a string ``Enum`` column that has no Python class as a ``Literal`` of its members.
|
|
185
|
+
|
|
186
|
+
``mysql.ENUM("a", "b")`` and ``Enum("a", "b")`` annotate as ``str``, so the form would
|
|
187
|
+
take any text and leave the database to refuse it. ``Literal`` validates the value and
|
|
188
|
+
makes the form render a select.
|
|
189
|
+
"""
|
|
190
|
+
sa_type = column.type
|
|
191
|
+
if not isinstance(sa_type, SAEnum) or sa_type.enum_class is not None or not sa_type.enums:
|
|
192
|
+
return annotation
|
|
193
|
+
if annotation not in (str, str | None):
|
|
194
|
+
return annotation
|
|
195
|
+
literal: Any = Literal[tuple(sa_type.enums)] # type: ignore[valid-type]
|
|
196
|
+
return literal | None if _is_optional(annotation) else literal
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def build_sqlalchemy_schema(model: type) -> type[BaseModel]:
|
|
200
|
+
"""Generate a Pydantic class describing ``model``'s mapped columns."""
|
|
201
|
+
mapper: Mapper[Any] = sa_inspect(model)
|
|
202
|
+
hints = _mapped_hints(model)
|
|
203
|
+
discriminator = mapper.polymorphic_on
|
|
204
|
+
hide_discriminator = mapper.polymorphic_identity is not None and isinstance(
|
|
205
|
+
discriminator, Column
|
|
206
|
+
)
|
|
207
|
+
fields: dict[str, Any] = {}
|
|
208
|
+
for prop in mapper.column_attrs:
|
|
209
|
+
# Deferred columns are declared "not loaded by default" (search vectors, blobs): reading
|
|
210
|
+
# them on a row whose session has closed raises DetachedInstanceError.
|
|
211
|
+
if prop.key.startswith("_") or prop.deferred:
|
|
212
|
+
continue
|
|
213
|
+
resolved = _column_for(prop)
|
|
214
|
+
if resolved is None:
|
|
215
|
+
continue
|
|
216
|
+
column, shared_pk = resolved
|
|
217
|
+
if hide_discriminator and column is discriminator:
|
|
218
|
+
continue
|
|
219
|
+
annotation = _resolve_annotation(model, prop.key, column, hints)
|
|
220
|
+
annotation = _bare_enum_annotation(column, annotation)
|
|
221
|
+
kwargs = _default_kwargs(column, shared_pk=shared_pk)
|
|
222
|
+
if (column.nullable or kwargs.get("default", 0) is None) and not _is_optional(annotation):
|
|
223
|
+
annotation = annotation | None
|
|
224
|
+
if (
|
|
225
|
+
isinstance(column.type, String)
|
|
226
|
+
and not isinstance(column.type, (SAEnum, mysql.SET)) # their length is a member's
|
|
227
|
+
and column.type.length
|
|
228
|
+
and annotation in (str, str | None)
|
|
229
|
+
):
|
|
230
|
+
kwargs["max_length"] = column.type.length
|
|
231
|
+
extra = _auto_now_hint(column)
|
|
232
|
+
if extra:
|
|
233
|
+
kwargs["json_schema_extra"] = extra
|
|
234
|
+
fields[prop.key] = (annotation, Field(**kwargs))
|
|
235
|
+
return create_model( # type: ignore[call-overload,no-any-return]
|
|
236
|
+
f"{model.__name__}Schema",
|
|
237
|
+
__config__=ConfigDict(from_attributes=True, arbitrary_types_allowed=True),
|
|
238
|
+
**fields,
|
|
239
|
+
)
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import builtins
|
|
2
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
3
|
+
from typing import TYPE_CHECKING, Any
|
|
4
|
+
|
|
5
|
+
from sqlalchemy import and_, func, or_, select
|
|
6
|
+
from sqlalchemy.ext.asyncio import AsyncEngine
|
|
7
|
+
from sqlalchemy.inspection import inspect
|
|
8
|
+
from sqlalchemy.orm import selectinload
|
|
9
|
+
from sqlmodel import SQLModel
|
|
10
|
+
|
|
11
|
+
from hyperadmin.adapters._estimate import estimate_table_rows
|
|
12
|
+
from hyperadmin.adapters._occ import claim_version
|
|
13
|
+
from hyperadmin.adapters._relation_loading import relation_load_options
|
|
14
|
+
from hyperadmin.adapters._search import contains_clause, detect_search_columns
|
|
15
|
+
from hyperadmin.adapters.filtering import build_clauses
|
|
16
|
+
from hyperadmin.adapters.introspection import coerce_column_value, introspect_primary_key
|
|
17
|
+
from hyperadmin.adapters.introspection import datetime_kind as _introspect_datetime_kind
|
|
18
|
+
from hyperadmin.core.adapters import (
|
|
19
|
+
BaseAdapter,
|
|
20
|
+
SessionFactory,
|
|
21
|
+
run_save_hook,
|
|
22
|
+
scoped_queryset_filters,
|
|
23
|
+
)
|
|
24
|
+
from hyperadmin.core.choices import ChoiceItem
|
|
25
|
+
from hyperadmin.core.display import get_display_name
|
|
26
|
+
from hyperadmin.core.filtering import FilterCondition, normalize_filters
|
|
27
|
+
from hyperadmin.core.inlines import InlineModelSpec
|
|
28
|
+
from hyperadmin.core.primary_key import InvalidPrimaryKey
|
|
29
|
+
from hyperadmin.core.schema import schema_for
|
|
30
|
+
from hyperadmin.core.sensitive import effective_sensitive_field_names
|
|
31
|
+
|
|
32
|
+
if TYPE_CHECKING:
|
|
33
|
+
from hyperadmin.core.timezones import DateTimeKind
|
|
34
|
+
|
|
35
|
+
_MAX_CHOICES_LIMIT = 200
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class SQLAlchemyAdapter(BaseAdapter):
|
|
39
|
+
"""Data adapter for plain SQLAlchemy declarative models (async engine or session factory).
|
|
40
|
+
|
|
41
|
+
Cursor (keyset) pagination is not implemented here: a list request with a cursor is served
|
|
42
|
+
as a page-numbered ``OFFSET`` page and emits
|
|
43
|
+
:class:`~hyperadmin.core.adapters.KeysetFallbackWarning`. Only
|
|
44
|
+
:class:`~hyperadmin.adapters.sqlmodel.SQLModelAdapter` pages by keyset.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
def __init__(
|
|
48
|
+
self,
|
|
49
|
+
model: type[SQLModel],
|
|
50
|
+
engine: AsyncEngine | None = None,
|
|
51
|
+
*,
|
|
52
|
+
session_factory: SessionFactory | None = None,
|
|
53
|
+
) -> None:
|
|
54
|
+
super().__init__(model=model, engine=engine, session_factory=session_factory)
|
|
55
|
+
self.inspector = inspect(model)
|
|
56
|
+
if self.inspector is None:
|
|
57
|
+
raise ValueError("Could not inspect model. Is it a valid SQLAlchemy model?")
|
|
58
|
+
self.pk = introspect_primary_key(model)
|
|
59
|
+
|
|
60
|
+
def datetime_kind(self, field: str) -> "DateTimeKind | None":
|
|
61
|
+
"""Return the column-introspected datetime kind for ``field``.
|
|
62
|
+
|
|
63
|
+
Overrides :meth:`BaseAdapter.datetime_kind` (annotation-only) with the
|
|
64
|
+
full rule set in :func:`hyperadmin.adapters.introspection.datetime_kind`,
|
|
65
|
+
which also inspects the mapped column type.
|
|
66
|
+
"""
|
|
67
|
+
try:
|
|
68
|
+
return _introspect_datetime_kind(self.model, field)
|
|
69
|
+
except KeyError:
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
async def get(self, pk: Any, *, load_relations: builtins.list[str] | None = None) -> Any:
|
|
73
|
+
"""Retrieve an object by primary key, applying any ``get_queryset`` filters.
|
|
74
|
+
|
|
75
|
+
Filters returned by :meth:`get_queryset` are ANDed with the primary-key
|
|
76
|
+
predicate so excluded rows resolve to ``None`` (not raised). ``pk`` that
|
|
77
|
+
does not parse as this model's key type also resolves to ``None``.
|
|
78
|
+
|
|
79
|
+
``load_relations`` names relations to eager-load with ``selectinload``; ``None``
|
|
80
|
+
and ``[]`` load none, and an unknown name raises :class:`ValueError`.
|
|
81
|
+
|
|
82
|
+
Raises:
|
|
83
|
+
NotImplementedError: For a composite primary key.
|
|
84
|
+
"""
|
|
85
|
+
try:
|
|
86
|
+
parsed_pk = self.pk.parse(pk)
|
|
87
|
+
except InvalidPrimaryKey:
|
|
88
|
+
return None
|
|
89
|
+
queryset_filters = self._resolve_queryset_filters()
|
|
90
|
+
options = relation_load_options(self.model, load_relations) if load_relations else []
|
|
91
|
+
async with self._session() as session:
|
|
92
|
+
if not queryset_filters and not options:
|
|
93
|
+
return await session.get(self.model, parsed_pk)
|
|
94
|
+
pk_col = getattr(self.model, self.pk.attr)
|
|
95
|
+
conditions = [pk_col == parsed_pk]
|
|
96
|
+
for key, value in queryset_filters.items():
|
|
97
|
+
conditions.append(getattr(self.model, key) == value)
|
|
98
|
+
query = select(self.model).where(and_(*conditions)).options(*options)
|
|
99
|
+
result = await session.execute(query)
|
|
100
|
+
return result.unique().scalar_one_or_none()
|
|
101
|
+
|
|
102
|
+
async def list(
|
|
103
|
+
self,
|
|
104
|
+
page: int = 1,
|
|
105
|
+
page_size: int = 10,
|
|
106
|
+
search: str | None = None,
|
|
107
|
+
filters: Mapping[str, Any] | Sequence[FilterCondition] | None = None,
|
|
108
|
+
order_by: str | None = None,
|
|
109
|
+
search_fields: list[str] | None = None,
|
|
110
|
+
load_relations: builtins.list[str] | None = None,
|
|
111
|
+
) -> tuple[list[Any], int]:
|
|
112
|
+
"""Retrieve a paginated, filtered, searched and ordered list of objects.
|
|
113
|
+
|
|
114
|
+
``load_relations`` names the relations to eager-load with ``selectinload``;
|
|
115
|
+
``None`` and ``[]`` load none, and an unknown name raises :class:`ValueError`.
|
|
116
|
+
|
|
117
|
+
``filters`` accepts either the legacy ``{column: value}`` equality
|
|
118
|
+
mapping or a ``Sequence[FilterCondition]``; both are resolved through
|
|
119
|
+
:func:`hyperadmin.core.filtering.normalize_filters` and compiled to
|
|
120
|
+
clauses via :mod:`hyperadmin.adapters.filtering`, shared with
|
|
121
|
+
:class:`~hyperadmin.adapters.sqlmodel.SQLModelAdapter`.
|
|
122
|
+
"""
|
|
123
|
+
queryset_filters = self._resolve_queryset_filters()
|
|
124
|
+
where_conditions = [
|
|
125
|
+
getattr(self.model, key) == value for key, value in queryset_filters.items()
|
|
126
|
+
]
|
|
127
|
+
where_conditions.extend(build_clauses(self.model, normalize_filters(filters)))
|
|
128
|
+
|
|
129
|
+
if search and self.inspector:
|
|
130
|
+
# An explicit empty list disables search; None falls back to detection.
|
|
131
|
+
fields_to_search = (
|
|
132
|
+
search_fields
|
|
133
|
+
if search_fields is not None
|
|
134
|
+
else detect_search_columns(self.model, self.inspector)
|
|
135
|
+
)
|
|
136
|
+
search_clauses = [
|
|
137
|
+
contains_clause(getattr(self.model, name), search)
|
|
138
|
+
for name in fields_to_search
|
|
139
|
+
if getattr(self.model, name, None) is not None
|
|
140
|
+
]
|
|
141
|
+
if search_clauses:
|
|
142
|
+
where_conditions.append(or_(*search_clauses))
|
|
143
|
+
|
|
144
|
+
items_query = select(self.model)
|
|
145
|
+
if load_relations:
|
|
146
|
+
items_query = items_query.options(*relation_load_options(self.model, load_relations))
|
|
147
|
+
if where_conditions:
|
|
148
|
+
items_query = items_query.where(and_(*where_conditions))
|
|
149
|
+
|
|
150
|
+
count_query = select(func.count()).select_from(self.model)
|
|
151
|
+
if where_conditions:
|
|
152
|
+
count_query = count_query.where(and_(*where_conditions))
|
|
153
|
+
|
|
154
|
+
if order_by:
|
|
155
|
+
if order_by.startswith("-"):
|
|
156
|
+
items_query = items_query.order_by(getattr(self.model, order_by[1:]).desc())
|
|
157
|
+
else:
|
|
158
|
+
items_query = items_query.order_by(getattr(self.model, order_by).asc())
|
|
159
|
+
|
|
160
|
+
paginated_items_query = items_query.offset((page - 1) * page_size).limit(page_size)
|
|
161
|
+
|
|
162
|
+
async with self._session() as session:
|
|
163
|
+
|
|
164
|
+
async def compute_total() -> int:
|
|
165
|
+
return (await session.execute(count_query)).scalar_one()
|
|
166
|
+
|
|
167
|
+
total_count = await self._cached_count(
|
|
168
|
+
compute_total,
|
|
169
|
+
filters=normalize_filters(filters),
|
|
170
|
+
search=search,
|
|
171
|
+
search_fields=search_fields,
|
|
172
|
+
queryset_filters=queryset_filters,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
items_result = await session.execute(paginated_items_query)
|
|
176
|
+
items = items_result.unique().scalars().all()
|
|
177
|
+
|
|
178
|
+
return list(items), total_count
|
|
179
|
+
|
|
180
|
+
async def estimate_row_count(self) -> int:
|
|
181
|
+
"""Approximate whole-table row count; see :func:`estimate_table_rows`."""
|
|
182
|
+
async with self._session() as session:
|
|
183
|
+
rows, self.estimates_row_count = await estimate_table_rows(
|
|
184
|
+
session, self.model.__table__
|
|
185
|
+
)
|
|
186
|
+
return rows
|
|
187
|
+
|
|
188
|
+
async def create(self, data: dict[str, Any]) -> Any:
|
|
189
|
+
# SQLModel validates through its own class; plain mapped classes take the data as is
|
|
190
|
+
# (the form already validated it against the generated schema).
|
|
191
|
+
db_obj = (
|
|
192
|
+
schema_for(self.model).model_validate(data)
|
|
193
|
+
if issubclass(self.model, SQLModel)
|
|
194
|
+
else self.model(**data)
|
|
195
|
+
)
|
|
196
|
+
await run_save_hook(db_obj, "before_save")
|
|
197
|
+
async with self._session() as session:
|
|
198
|
+
session.add(db_obj)
|
|
199
|
+
await session.commit()
|
|
200
|
+
await self.invalidate_count_cache()
|
|
201
|
+
await session.refresh(db_obj)
|
|
202
|
+
await run_save_hook(db_obj, "after_save")
|
|
203
|
+
return db_obj
|
|
204
|
+
|
|
205
|
+
async def update(
|
|
206
|
+
self, pk: Any, data: dict[str, Any], *, expected_version: Any | None = None
|
|
207
|
+
) -> Any:
|
|
208
|
+
"""Update an existing object.
|
|
209
|
+
|
|
210
|
+
Primary-key attributes in ``data`` are dropped before assignment, so the
|
|
211
|
+
key is always immutable through this method.
|
|
212
|
+
|
|
213
|
+
Raises:
|
|
214
|
+
InvalidPrimaryKey: If ``pk`` does not parse as this model's key type.
|
|
215
|
+
NotImplementedError: For a composite primary key.
|
|
216
|
+
StaleRecordError: ``expected_version`` no longer matches the stored row.
|
|
217
|
+
"""
|
|
218
|
+
parsed_pk = self.pk.parse(pk)
|
|
219
|
+
data = {key: value for key, value in data.items() if key not in self.pk.attrs}
|
|
220
|
+
async with self._session() as session:
|
|
221
|
+
if expected_version is not None and self.version_field:
|
|
222
|
+
# Raises StaleRecordError before any other column is written.
|
|
223
|
+
db_obj = await claim_version(
|
|
224
|
+
session,
|
|
225
|
+
self.model,
|
|
226
|
+
self.pk.attr,
|
|
227
|
+
parsed_pk,
|
|
228
|
+
self.version_field,
|
|
229
|
+
expected_version,
|
|
230
|
+
)
|
|
231
|
+
data = {k: v for k, v in data.items() if k != self.version_field}
|
|
232
|
+
else:
|
|
233
|
+
db_obj = await session.get(self.model, parsed_pk)
|
|
234
|
+
if db_obj:
|
|
235
|
+
for key, value in data.items():
|
|
236
|
+
setattr(db_obj, key, value)
|
|
237
|
+
await run_save_hook(db_obj, "before_save")
|
|
238
|
+
session.add(db_obj)
|
|
239
|
+
await session.commit()
|
|
240
|
+
await self.invalidate_count_cache()
|
|
241
|
+
await session.refresh(db_obj)
|
|
242
|
+
await run_save_hook(db_obj, "after_save")
|
|
243
|
+
return db_obj
|
|
244
|
+
|
|
245
|
+
async def delete(self, pk: Any) -> None:
|
|
246
|
+
"""Delete an object by primary key.
|
|
247
|
+
|
|
248
|
+
Raises:
|
|
249
|
+
InvalidPrimaryKey: If ``pk`` does not parse as this model's key type.
|
|
250
|
+
NotImplementedError: For a composite primary key.
|
|
251
|
+
"""
|
|
252
|
+
parsed_pk = self.pk.parse(pk)
|
|
253
|
+
async with self._session() as session:
|
|
254
|
+
db_obj = await session.get(self.model, parsed_pk)
|
|
255
|
+
if db_obj:
|
|
256
|
+
await session.delete(db_obj)
|
|
257
|
+
await session.commit()
|
|
258
|
+
await self.invalidate_count_cache()
|
|
259
|
+
|
|
260
|
+
async def get_related(self, pk: Any, field: str) -> builtins.list[Any]:
|
|
261
|
+
"""Retrieve related objects for a given object and field.
|
|
262
|
+
|
|
263
|
+
Returns ``[]`` if not found, or if ``pk`` does not parse as this
|
|
264
|
+
model's key type.
|
|
265
|
+
|
|
266
|
+
Raises:
|
|
267
|
+
NotImplementedError: For a composite primary key.
|
|
268
|
+
"""
|
|
269
|
+
if not self.inspector or not hasattr(self.model, field):
|
|
270
|
+
return []
|
|
271
|
+
try:
|
|
272
|
+
parsed_pk = self.pk.parse(pk)
|
|
273
|
+
except InvalidPrimaryKey:
|
|
274
|
+
return []
|
|
275
|
+
queryset_filters = self._resolve_queryset_filters()
|
|
276
|
+
async with self._session() as session:
|
|
277
|
+
query = (
|
|
278
|
+
select(self.model)
|
|
279
|
+
.where(getattr(self.model, self.pk.attr) == parsed_pk)
|
|
280
|
+
.options(selectinload(getattr(self.model, field)))
|
|
281
|
+
)
|
|
282
|
+
for key, value in queryset_filters.items():
|
|
283
|
+
query = query.where(getattr(self.model, key) == value)
|
|
284
|
+
result = await session.execute(query)
|
|
285
|
+
db_obj = result.unique().scalar_one_or_none()
|
|
286
|
+
|
|
287
|
+
if not db_obj:
|
|
288
|
+
return []
|
|
289
|
+
|
|
290
|
+
try:
|
|
291
|
+
related = getattr(db_obj, field)
|
|
292
|
+
if related is None:
|
|
293
|
+
return []
|
|
294
|
+
if isinstance(related, list):
|
|
295
|
+
return list(related)
|
|
296
|
+
return [related]
|
|
297
|
+
except AttributeError:
|
|
298
|
+
return []
|
|
299
|
+
|
|
300
|
+
async def get_schema(self) -> dict[str, Any]:
|
|
301
|
+
return self.model.model_json_schema()
|
|
302
|
+
|
|
303
|
+
async def get_choices(
|
|
304
|
+
self,
|
|
305
|
+
field: str,
|
|
306
|
+
q: str = "",
|
|
307
|
+
limit: int = 50,
|
|
308
|
+
offset: int = 0,
|
|
309
|
+
label_fn: Callable[[Any], str] | None = None,
|
|
310
|
+
**filters: Any,
|
|
311
|
+
) -> builtins.list[ChoiceItem]:
|
|
312
|
+
"""Return paginated, searchable choices for a relation field.
|
|
313
|
+
|
|
314
|
+
Performs a single SELECT on the related model — no N+1.
|
|
315
|
+
"""
|
|
316
|
+
if limit > _MAX_CHOICES_LIMIT:
|
|
317
|
+
raise ValueError(f"limit {limit} exceeds maximum of {_MAX_CHOICES_LIMIT}")
|
|
318
|
+
|
|
319
|
+
if not self.inspector:
|
|
320
|
+
return []
|
|
321
|
+
|
|
322
|
+
target_model = None
|
|
323
|
+
for rel in self.inspector.relationships:
|
|
324
|
+
if rel.key == field:
|
|
325
|
+
target_model = rel.mapper.class_
|
|
326
|
+
break
|
|
327
|
+
|
|
328
|
+
if target_model is None:
|
|
329
|
+
return []
|
|
330
|
+
|
|
331
|
+
target_inspector = inspect(target_model)
|
|
332
|
+
if target_inspector is None: # Optional in SQLAlchemy < 2.0.2x type stubs
|
|
333
|
+
return []
|
|
334
|
+
target_pk = introspect_primary_key(target_model)
|
|
335
|
+
async with self._session() as session:
|
|
336
|
+
query = select(target_model)
|
|
337
|
+
|
|
338
|
+
if q:
|
|
339
|
+
# Never match on sensitive columns (q would be a substring oracle).
|
|
340
|
+
str_cols = [
|
|
341
|
+
getattr(target_model, name)
|
|
342
|
+
for name in detect_search_columns(target_model, target_inspector)
|
|
343
|
+
]
|
|
344
|
+
if str_cols:
|
|
345
|
+
query = query.where(or_(*[contains_clause(c, q) for c in str_cols[:3]]))
|
|
346
|
+
|
|
347
|
+
# Row scoping of the target model's admin (tenant / RLS) always applies.
|
|
348
|
+
for key, value in scoped_queryset_filters(target_model).items():
|
|
349
|
+
query = query.where(getattr(target_model, key) == value)
|
|
350
|
+
|
|
351
|
+
# Cascade filters: the view forwards only keys declared by the widget.
|
|
352
|
+
target_sensitive = effective_sensitive_field_names(target_model)
|
|
353
|
+
for key, value in filters.items():
|
|
354
|
+
if hasattr(target_model, key) and key not in target_sensitive:
|
|
355
|
+
try:
|
|
356
|
+
coerced = coerce_column_value(target_inspector, key, value)
|
|
357
|
+
except ValueError:
|
|
358
|
+
# An unparseable cascade value (e.g. '' or 'garbage' for a
|
|
359
|
+
# UUID FK) matches no row rather than raising a 500 — '' is
|
|
360
|
+
# what a dependent select sends while its parent is blank.
|
|
361
|
+
return []
|
|
362
|
+
query = query.where(getattr(target_model, key) == coerced)
|
|
363
|
+
|
|
364
|
+
query = query.offset(offset).limit(limit)
|
|
365
|
+
result = await session.execute(query)
|
|
366
|
+
items = result.unique().scalars().all()
|
|
367
|
+
|
|
368
|
+
return [
|
|
369
|
+
ChoiceItem(
|
|
370
|
+
# The target's own key codec, not a hardcoded "id": canonical for
|
|
371
|
+
# any key kind (UUIDs become lowercase, hyphenated strings).
|
|
372
|
+
value=target_pk.to_str(target_pk.value_of(item)),
|
|
373
|
+
# Never str(item): SQLModel's default __str__ prints every column.
|
|
374
|
+
label=label_fn(item) if label_fn else get_display_name(item),
|
|
375
|
+
selected=False,
|
|
376
|
+
)
|
|
377
|
+
for item in items
|
|
378
|
+
]
|
|
379
|
+
|
|
380
|
+
async def save_inline_rows(
|
|
381
|
+
self,
|
|
382
|
+
spec: InlineModelSpec,
|
|
383
|
+
rows: builtins.list[dict[str, Any]],
|
|
384
|
+
parent_pk: Any,
|
|
385
|
+
) -> None:
|
|
386
|
+
"""Persist validated inline rows — create, update, or delete as needed.
|
|
387
|
+
|
|
388
|
+
Args:
|
|
389
|
+
spec: The ``InlineModelSpec`` describing the related model and FK field.
|
|
390
|
+
rows: Validated row dicts, each optionally containing ``_pk`` (for
|
|
391
|
+
update/delete) and ``_delete`` (for deletion).
|
|
392
|
+
parent_pk: The primary key of the parent object to associate new rows with.
|
|
393
|
+
|
|
394
|
+
Raises:
|
|
395
|
+
InlineRowNotOwnedError: Before any write, when a submitted ``_pk`` is not an
|
|
396
|
+
existing child of ``parent_pk``.
|
|
397
|
+
"""
|
|
398
|
+
await self.ensure_inline_rows_owned(spec, rows, parent_pk)
|
|
399
|
+
inline_adapter = self.for_model(spec.model)
|
|
400
|
+
for row in rows:
|
|
401
|
+
row_pk = row.get("_pk")
|
|
402
|
+
if row.get("_delete") and row_pk is not None:
|
|
403
|
+
await inline_adapter.delete(pk=row_pk)
|
|
404
|
+
elif row_pk is not None:
|
|
405
|
+
# Keys are immutable and the row stays attached to its parent;
|
|
406
|
+
# inline_adapter.update() drops any pk attrs from row_data itself.
|
|
407
|
+
row_data = {
|
|
408
|
+
k: v for k, v in row.items() if k not in ("_pk", "_delete", spec.fk_field)
|
|
409
|
+
}
|
|
410
|
+
await inline_adapter.update(pk=row_pk, data=row_data)
|
|
411
|
+
elif not row.get("_delete"):
|
|
412
|
+
row_data = {k: v for k, v in row.items() if k not in ("_pk", "_delete")}
|
|
413
|
+
row_data[spec.fk_field] = parent_pk
|
|
414
|
+
await inline_adapter.create(data=row_data)
|
|
415
|
+
|
|
416
|
+
async def inline_child_pks(self, spec: InlineModelSpec, parent_pk: Any) -> set[Any]:
|
|
417
|
+
"""Return the primary keys of ``spec.model`` rows owned by ``parent_pk``."""
|
|
418
|
+
pk_col = inspect(spec.model).primary_key[0]
|
|
419
|
+
async with self._session() as session:
|
|
420
|
+
result = await session.execute(
|
|
421
|
+
select(pk_col).where(getattr(spec.model, spec.fk_field) == parent_pk)
|
|
422
|
+
)
|
|
423
|
+
return set(result.scalars().all())
|