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
hyperadmin/db.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""Engine helpers and DDL for HyperAdmin's own database access.
|
|
2
|
+
|
|
3
|
+
Importing this module creates **no** engine. Demo mode (``Admin(app)`` without
|
|
4
|
+
``engine=``) builds one lazily from ``HyperAdminSettings.database_url`` through
|
|
5
|
+
:func:`get_default_engine`. The ORM-specific table creation lives here rather
|
|
6
|
+
than in ``core/``.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import warnings
|
|
12
|
+
from typing import TYPE_CHECKING, Any, Literal
|
|
13
|
+
|
|
14
|
+
from sqlalchemy.engine import make_url
|
|
15
|
+
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncEngine, create_async_engine
|
|
16
|
+
from sqlmodel import SQLModel
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from collections.abc import Mapping, Sequence
|
|
20
|
+
|
|
21
|
+
from sqlalchemy import Table
|
|
22
|
+
from sqlalchemy.engine import URL, Connection
|
|
23
|
+
|
|
24
|
+
from hyperadmin.core.settings import HyperAdminSettings
|
|
25
|
+
|
|
26
|
+
sqlite_url = "sqlite+aiosqlite:///:memory:"
|
|
27
|
+
|
|
28
|
+
#: ``"hyperadmin"`` creates only the built-in ``hyperadmin_*`` tables; ``"all"`` creates
|
|
29
|
+
#: every table registered on ``SQLModel.metadata`` (the host's own models too). Used by
|
|
30
|
+
#: ``Admin.create_tables(scope=)`` and the ``hyperadmin init-db`` CLI (SDD C.2).
|
|
31
|
+
TableScope = Literal["hyperadmin", "all"]
|
|
32
|
+
|
|
33
|
+
#: Pool arguments an in-memory SQLite engine cannot take: its ``StaticPool`` rejects the
|
|
34
|
+
#: sizing ones, and recycling its single connection would drop the whole database.
|
|
35
|
+
_QUEUE_POOL_KWARGS = frozenset(
|
|
36
|
+
{"pool_size", "max_overflow", "pool_timeout", "pool_recycle", "pool_use_lifo"}
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
_default_engines: dict[tuple[str, tuple[tuple[str, Any], ...]], AsyncEngine] = {}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def build_engine(url: str | URL, engine_kwargs: Mapping[str, Any] | None = None) -> AsyncEngine:
|
|
43
|
+
"""Create an async engine for ``url``, forwarding ``engine_kwargs`` to SQLAlchemy.
|
|
44
|
+
|
|
45
|
+
Pool arguments (``pool_size``, ``max_overflow``, ``pool_timeout``, ``pool_recycle``,
|
|
46
|
+
``pool_use_lifo``) are dropped for an in-memory SQLite URL, whose ``StaticPool``
|
|
47
|
+
cannot take them, so one configuration works for tests and production alike.
|
|
48
|
+
Without ``engine_kwargs`` SQLAlchemy's own defaults apply (``pool_size=5``,
|
|
49
|
+
``max_overflow=10``, ``pool_timeout=30``). For a production PostgreSQL behind
|
|
50
|
+
several workers, a starting point is ``pool_size=20, max_overflow=40,
|
|
51
|
+
pool_timeout=30, pool_pre_ping=True``; keep ``workers * (pool_size +
|
|
52
|
+
max_overflow)`` below the server's ``max_connections``.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
url: The database URL.
|
|
56
|
+
engine_kwargs: Extra keyword arguments for ``create_async_engine``.
|
|
57
|
+
"""
|
|
58
|
+
kwargs = dict(engine_kwargs or {})
|
|
59
|
+
if is_sqlite_memory_url(url):
|
|
60
|
+
kwargs = {key: value for key, value in kwargs.items() if key not in _QUEUE_POOL_KWARGS}
|
|
61
|
+
return create_async_engine(url, **kwargs)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def get_default_engine(settings: HyperAdminSettings | None = None) -> AsyncEngine:
|
|
65
|
+
"""Return the demo-mode engine for ``settings.database_url``.
|
|
66
|
+
|
|
67
|
+
The engine is built by :func:`build_engine` with the ``database_pool_*`` settings
|
|
68
|
+
on first use and cached per URL and pool configuration, so every caller using
|
|
69
|
+
the same URL (including an in-memory SQLite database) shares it.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
settings: The settings to read ``database_url`` from. When ``None``, a
|
|
73
|
+
default ``HyperAdminSettings()`` is used (``HYPERADMIN_*`` env vars).
|
|
74
|
+
"""
|
|
75
|
+
if settings is None:
|
|
76
|
+
# Deferred: ``core`` depends on ``db``, never the other way round at import.
|
|
77
|
+
from hyperadmin.core.settings import HyperAdminSettings # noqa: PLC0415
|
|
78
|
+
|
|
79
|
+
settings = HyperAdminSettings()
|
|
80
|
+
url = settings.database_url
|
|
81
|
+
engine_kwargs = settings.database_engine_kwargs
|
|
82
|
+
key = (url, tuple(sorted(engine_kwargs.items())))
|
|
83
|
+
engine = _default_engines.get(key)
|
|
84
|
+
if engine is None:
|
|
85
|
+
engine = build_engine(url, {"echo": False, **engine_kwargs})
|
|
86
|
+
_default_engines[key] = engine
|
|
87
|
+
return engine
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def is_sqlite_url(url: str | URL) -> bool:
|
|
91
|
+
"""Return ``True`` when ``url`` points at a SQLite database (any driver)."""
|
|
92
|
+
return make_url(url).get_backend_name() == "sqlite"
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def is_sqlite_memory_url(url: str | URL) -> bool:
|
|
96
|
+
"""Return ``True`` when ``url`` points at an in-memory SQLite database."""
|
|
97
|
+
parsed = make_url(url)
|
|
98
|
+
if parsed.get_backend_name() != "sqlite":
|
|
99
|
+
return False
|
|
100
|
+
return parsed.database in (None, "", ":memory:") or parsed.query.get("mode") == "memory"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def resolve_bind(session_factory: Any) -> AsyncEngine | AsyncConnection:
|
|
104
|
+
"""Return the engine a session factory is bound to, for running DDL.
|
|
105
|
+
|
|
106
|
+
Works with ``async_sessionmaker(engine)`` (it reads ``session_factory.kw["bind"]``).
|
|
107
|
+
|
|
108
|
+
Raises:
|
|
109
|
+
ValueError: when the factory carries no async bind, explaining what to pass.
|
|
110
|
+
"""
|
|
111
|
+
kw = getattr(session_factory, "kw", None)
|
|
112
|
+
bind = kw.get("bind") if isinstance(kw, dict) else None
|
|
113
|
+
if isinstance(bind, (AsyncEngine, AsyncConnection)):
|
|
114
|
+
return bind
|
|
115
|
+
msg = (
|
|
116
|
+
"Cannot create tables: the session_factory has no async engine bound to it. "
|
|
117
|
+
"Pass engine= to Admin(...), or use async_sessionmaker(engine)."
|
|
118
|
+
)
|
|
119
|
+
raise ValueError(msg)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _create_some(sync_conn: Connection, tables: list[Table]) -> None:
|
|
123
|
+
SQLModel.metadata.create_all(sync_conn, tables=tables)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
async def _run_create(conn: AsyncConnection, tables: Sequence[Table] | None) -> None:
|
|
127
|
+
if tables is None:
|
|
128
|
+
await conn.run_sync(SQLModel.metadata.create_all)
|
|
129
|
+
else:
|
|
130
|
+
await conn.run_sync(_create_some, list(tables))
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
async def create_tables(
|
|
134
|
+
engine: AsyncEngine | AsyncConnection, tables: Sequence[Table] | None = None
|
|
135
|
+
) -> None:
|
|
136
|
+
"""Create ``tables`` (default: every table on ``SQLModel.metadata``) if missing."""
|
|
137
|
+
if isinstance(engine, AsyncConnection):
|
|
138
|
+
await _run_create(engine, tables)
|
|
139
|
+
return
|
|
140
|
+
async with engine.begin() as conn:
|
|
141
|
+
await _run_create(conn, tables)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
async def create_db_and_tables() -> None:
|
|
145
|
+
"""Create every ``SQLModel`` table on the default engine (legacy helper)."""
|
|
146
|
+
await create_tables(get_default_engine())
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def __getattr__(name: str) -> Any:
|
|
150
|
+
"""Keep ``from hyperadmin.db import engine`` working, with a deprecation warning."""
|
|
151
|
+
if name == "engine":
|
|
152
|
+
warnings.warn(
|
|
153
|
+
"hyperadmin.db.engine is deprecated and will be removed in 0.6; pass your "
|
|
154
|
+
"own engine to Admin(engine=...) or call hyperadmin.db.get_default_engine().",
|
|
155
|
+
DeprecationWarning,
|
|
156
|
+
stacklevel=2,
|
|
157
|
+
)
|
|
158
|
+
return get_default_engine()
|
|
159
|
+
msg = f"module {__name__!r} has no attribute {name!r}"
|
|
160
|
+
raise AttributeError(msg)
|
hyperadmin/discover.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides the auto-discovery mechanism for admin modules.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import importlib
|
|
6
|
+
import logging
|
|
7
|
+
import os
|
|
8
|
+
from contextvars import ContextVar
|
|
9
|
+
|
|
10
|
+
logger = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
app_label_var: ContextVar[str | None] = ContextVar("app_label", default=None)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def discover_admin_modules(app_modules: list[str]):
|
|
16
|
+
"""
|
|
17
|
+
Discovers and imports `admin.py` modules from a list of app modules.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
app_modules: A list of strings representing the app modules to scan.
|
|
21
|
+
"""
|
|
22
|
+
for app_module_str in app_modules:
|
|
23
|
+
try:
|
|
24
|
+
# Import the app module
|
|
25
|
+
app_module = importlib.import_module(app_module_str)
|
|
26
|
+
logger.info(f"Successfully imported app module: {app_module_str}")
|
|
27
|
+
|
|
28
|
+
# Get the directory of the app module
|
|
29
|
+
if app_module.__file__ is None:
|
|
30
|
+
logger.warning(f"Skipping {app_module_str} because it's a namespace package.")
|
|
31
|
+
continue
|
|
32
|
+
|
|
33
|
+
module_dir = os.path.dirname(app_module.__file__)
|
|
34
|
+
admin_py_path = os.path.join(module_dir, "admin.py")
|
|
35
|
+
|
|
36
|
+
# Check if admin.py exists
|
|
37
|
+
if os.path.exists(admin_py_path):
|
|
38
|
+
admin_module_str = f"{app_module_str}.admin"
|
|
39
|
+
token = app_label_var.set(app_module_str)
|
|
40
|
+
try:
|
|
41
|
+
# Import the admin.py module
|
|
42
|
+
importlib.import_module(admin_module_str)
|
|
43
|
+
logger.info(
|
|
44
|
+
f"Successfully discovered and imported admin module: {admin_module_str}"
|
|
45
|
+
)
|
|
46
|
+
except ImportError as e:
|
|
47
|
+
logger.error(f"Failed to import admin module {admin_module_str}: {e}")
|
|
48
|
+
finally:
|
|
49
|
+
app_label_var.reset(token)
|
|
50
|
+
else:
|
|
51
|
+
logger.debug(f"No admin.py file found in {app_module_str}")
|
|
52
|
+
|
|
53
|
+
except ImportError as e:
|
|
54
|
+
logger.error(f"Failed to import app module {app_module_str}: {e}")
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Filter library: declarative list filters for ``AdminOptions.list_filter``.
|
|
2
|
+
|
|
3
|
+
Example:
|
|
4
|
+
```python
|
|
5
|
+
from hyperadmin.filters import DateRangeFilter, IsOwnerFilter
|
|
6
|
+
|
|
7
|
+
filters = [DateRangeFilter(field="created_at"), IsOwnerFilter(owner_fields="created_by")]
|
|
8
|
+
```
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from hyperadmin.filters.base import FilterBinding, FilterDef, FilterRenderContext
|
|
12
|
+
from hyperadmin.filters.boolean import BooleanFilter, IsOwnerFilter
|
|
13
|
+
from hyperadmin.filters.choice import MultiChoiceFilter
|
|
14
|
+
from hyperadmin.filters.date import PRESETS, CurrentPeriodDefault, DateRangeFilter, period_bounds
|
|
15
|
+
from hyperadmin.filters.relation import MultiFKFilter
|
|
16
|
+
from hyperadmin.filters.saved_views import (
|
|
17
|
+
SavedView,
|
|
18
|
+
SavedViewNameTakenError,
|
|
19
|
+
SavedViewService,
|
|
20
|
+
normalize_querystring,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"PRESETS",
|
|
25
|
+
"BooleanFilter",
|
|
26
|
+
"CurrentPeriodDefault",
|
|
27
|
+
"DateRangeFilter",
|
|
28
|
+
"FilterBinding",
|
|
29
|
+
"FilterDef",
|
|
30
|
+
"FilterRenderContext",
|
|
31
|
+
"IsOwnerFilter",
|
|
32
|
+
"MultiChoiceFilter",
|
|
33
|
+
"MultiFKFilter",
|
|
34
|
+
"SavedView",
|
|
35
|
+
"SavedViewNameTakenError",
|
|
36
|
+
"SavedViewService",
|
|
37
|
+
"normalize_querystring",
|
|
38
|
+
"period_bounds",
|
|
39
|
+
]
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"""``FilterDef``: the contract every list filter implements (filter library SDD).
|
|
2
|
+
|
|
3
|
+
A filter is a small, immutable declaration bound to one model field. It knows
|
|
4
|
+
three things: which querystring keys it reads (:meth:`FilterDef.parse`), how
|
|
5
|
+
the parsed values become typed :class:`~hyperadmin.core.filtering.FilterCondition`
|
|
6
|
+
objects (:meth:`FilterDef.compile`), and how it renders in the filter sidebar
|
|
7
|
+
(:meth:`FilterDef.render`). Compiling goes through
|
|
8
|
+
:func:`hyperadmin.core.filtering.parse_filter_params`, so a filter never builds
|
|
9
|
+
SQL and the v0.5.8 whitelist stays the only path from user input to the query.
|
|
10
|
+
|
|
11
|
+
Per-request facts (the model, the display timezone, today's date, the current
|
|
12
|
+
user) travel in a :class:`FilterBinding`; what the sidebar needs on top of that
|
|
13
|
+
(the querystring, prefetched choices, a template environment) travels in a
|
|
14
|
+
:class:`FilterRenderContext`.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import functools
|
|
20
|
+
from abc import ABC, abstractmethod
|
|
21
|
+
from collections.abc import Mapping, Sequence
|
|
22
|
+
from dataclasses import dataclass, field
|
|
23
|
+
from datetime import date, datetime, timezone, tzinfo
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
from typing import TYPE_CHECKING, Any, ClassVar
|
|
26
|
+
from urllib.parse import urlencode
|
|
27
|
+
|
|
28
|
+
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
|
29
|
+
|
|
30
|
+
from hyperadmin.core.filtering import FILTER_PARAM_PREFIX, parse_filter_params
|
|
31
|
+
from hyperadmin.core.schema import schema_for
|
|
32
|
+
|
|
33
|
+
if TYPE_CHECKING:
|
|
34
|
+
from hyperadmin.core.choices import ChoiceItem
|
|
35
|
+
from hyperadmin.core.filtering import DateTimeKindResolver, FilterCondition
|
|
36
|
+
|
|
37
|
+
_TEMPLATES_DIR = Path(__file__).resolve().parent.parent / "templates"
|
|
38
|
+
_TRUE = frozenset({"1", "true", "yes", "on"})
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def query_values(qs: Any, key: str) -> list[str]:
|
|
42
|
+
"""Return every non-blank value of ``key`` in ``qs``, stripped, in order.
|
|
43
|
+
|
|
44
|
+
``qs`` may be a Starlette ``QueryParams`` (``getlist``), a mapping whose
|
|
45
|
+
values are strings or lists of strings, or ``None``.
|
|
46
|
+
"""
|
|
47
|
+
if qs is None:
|
|
48
|
+
return []
|
|
49
|
+
if hasattr(qs, "getlist"):
|
|
50
|
+
raws: Any = qs.getlist(key)
|
|
51
|
+
elif isinstance(qs, Mapping):
|
|
52
|
+
value = qs.get(key)
|
|
53
|
+
raws = [] if value is None else value if isinstance(value, (list, tuple)) else [value]
|
|
54
|
+
else:
|
|
55
|
+
raws = []
|
|
56
|
+
return [text for text in (str(raw).strip() for raw in raws) if text]
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def query_value(qs: Any, key: str) -> str | None:
|
|
60
|
+
"""Return the last non-blank value of ``key`` in ``qs``, or ``None``."""
|
|
61
|
+
values = query_values(qs, key)
|
|
62
|
+
return values[-1] if values else None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def is_truthy(raw: str | None) -> bool:
|
|
66
|
+
"""``True`` for ``1``/``true``/``yes``/``on`` (case-insensitive)."""
|
|
67
|
+
return raw is not None and raw.strip().lower() in _TRUE
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def query_pairs(qs: Any) -> list[tuple[str, str]]:
|
|
71
|
+
"""``qs`` flattened to ``(key, value)`` pairs, repeated keys kept in order."""
|
|
72
|
+
if qs is None:
|
|
73
|
+
return []
|
|
74
|
+
if hasattr(qs, "multi_items"):
|
|
75
|
+
return [(str(k), str(v)) for k, v in qs.multi_items()]
|
|
76
|
+
pairs: list[tuple[str, str]] = []
|
|
77
|
+
if isinstance(qs, Mapping):
|
|
78
|
+
for key, value in qs.items():
|
|
79
|
+
values = value if isinstance(value, (list, tuple)) else [value]
|
|
80
|
+
pairs.extend((str(key), str(v)) for v in values if v is not None)
|
|
81
|
+
return pairs
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def clear_href(qs: Any, keys: Sequence[str], extra: Mapping[str, str] | None = None) -> str:
|
|
85
|
+
"""A relative ``?...`` href that drops ``keys`` (and ``page``) from ``qs``, adds ``extra``."""
|
|
86
|
+
pairs = [(k, v) for k, v in query_pairs(qs) if k not in keys and k != "page"]
|
|
87
|
+
pairs.extend((extra or {}).items())
|
|
88
|
+
return f"?{urlencode(pairs)}"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@functools.lru_cache(maxsize=1)
|
|
92
|
+
def default_environment() -> Environment:
|
|
93
|
+
"""A Jinja environment over the package templates, used when no admin env is given."""
|
|
94
|
+
from hyperadmin.i18n import install_jinja_i18n # noqa: PLC0415 — keep the import light
|
|
95
|
+
|
|
96
|
+
env = Environment(
|
|
97
|
+
loader=FileSystemLoader(str(_TEMPLATES_DIR)),
|
|
98
|
+
autoescape=select_autoescape(["html"]),
|
|
99
|
+
)
|
|
100
|
+
install_jinja_i18n(env)
|
|
101
|
+
return env
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@dataclass(frozen=True, kw_only=True)
|
|
105
|
+
class FilterBinding:
|
|
106
|
+
"""Per-request facts a filter needs to compile and to resolve defaults.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
model: The admin model; its annotations type the compiled values. ``None``
|
|
110
|
+
falls back to each filter's own ``value_type``.
|
|
111
|
+
tz: Display timezone: date bounds on aware columns are local days in it.
|
|
112
|
+
today: "Today" for presets and period defaults; defaults to today in ``tz``.
|
|
113
|
+
datetime_kind: Resolves a field to ``"aware"``/``"naive"`` (``adapter.datetime_kind``).
|
|
114
|
+
user: The current user, or ``None`` when anonymous.
|
|
115
|
+
user_key: ``request.state.user_key`` — what owner columns are compared to.
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
model: Any = None
|
|
119
|
+
tz: tzinfo = timezone.utc
|
|
120
|
+
today: date | None = None
|
|
121
|
+
datetime_kind: DateTimeKindResolver | None = None
|
|
122
|
+
user: Any = None
|
|
123
|
+
user_key: Any = None
|
|
124
|
+
|
|
125
|
+
@property
|
|
126
|
+
def today_date(self) -> date:
|
|
127
|
+
"""``today`` when given, else the current date in ``tz``."""
|
|
128
|
+
return self.today or datetime.now(self.tz).date()
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
@dataclass(frozen=True, kw_only=True)
|
|
132
|
+
class FilterRenderContext:
|
|
133
|
+
"""What :meth:`FilterDef.render` needs beyond the filter itself.
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
query: The request querystring (``QueryParams`` or a mapping).
|
|
137
|
+
binding: Per-request facts (see :class:`FilterBinding`).
|
|
138
|
+
choices: Prefetched options for relation/choice filters (``ChoiceItem`` dicts).
|
|
139
|
+
more: Number of further options not in ``choices`` ("Show N more" link).
|
|
140
|
+
templates: The admin's Jinja environment; defaults to the package templates.
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
query: Any = None
|
|
144
|
+
binding: FilterBinding = field(default_factory=FilterBinding)
|
|
145
|
+
choices: Sequence[ChoiceItem] = ()
|
|
146
|
+
more: int = 0
|
|
147
|
+
templates: Environment | None = None
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@dataclass(frozen=True, kw_only=True)
|
|
151
|
+
class FilterDef(ABC):
|
|
152
|
+
"""Base class for every list filter.
|
|
153
|
+
|
|
154
|
+
Subclasses declare ``template`` (a partial under ``components/filters/``),
|
|
155
|
+
``value_type`` (the Python type raw values coerce to when the model does not
|
|
156
|
+
declare the field) and implement :meth:`parse` and :meth:`compile`.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
field: The model column the filter binds to.
|
|
160
|
+
label: Sidebar heading; defaults to the field name, title-cased.
|
|
161
|
+
"""
|
|
162
|
+
|
|
163
|
+
template: ClassVar[str]
|
|
164
|
+
value_type: ClassVar[Any] = str
|
|
165
|
+
|
|
166
|
+
field: str
|
|
167
|
+
label: str | None = None
|
|
168
|
+
|
|
169
|
+
@property
|
|
170
|
+
def slug(self) -> str:
|
|
171
|
+
"""URL-safe key naming this filter in test ids and errors; defaults to ``field``."""
|
|
172
|
+
return self.field
|
|
173
|
+
|
|
174
|
+
@property
|
|
175
|
+
def title(self) -> str:
|
|
176
|
+
"""The label to show, with a title-cased fallback from ``field``."""
|
|
177
|
+
return self.label or self.field.replace("_", " ").title()
|
|
178
|
+
|
|
179
|
+
@property
|
|
180
|
+
def query_keys(self) -> tuple[str, ...]:
|
|
181
|
+
"""Querystring keys this filter reads (and a "Clear" link drops)."""
|
|
182
|
+
return (self.field,)
|
|
183
|
+
|
|
184
|
+
@abstractmethod
|
|
185
|
+
def parse(self, qs: Any) -> dict[str, Any]:
|
|
186
|
+
"""Extract this filter's values from the querystring; ``{}`` when inactive or invalid."""
|
|
187
|
+
|
|
188
|
+
@abstractmethod
|
|
189
|
+
def compile(
|
|
190
|
+
self, parsed: dict[str, Any], binding: FilterBinding | None = None
|
|
191
|
+
) -> list[FilterCondition]:
|
|
192
|
+
"""Turn :meth:`parse` output into typed conditions for the adapter."""
|
|
193
|
+
|
|
194
|
+
def error(self, qs: Any) -> str | None: # noqa: ARG002 — hook; most filters never fail
|
|
195
|
+
"""A message for invalid input in ``qs``, or ``None``."""
|
|
196
|
+
return None
|
|
197
|
+
|
|
198
|
+
def describe(self, parsed: dict[str, Any]) -> str | None: # noqa: ARG002 — hook
|
|
199
|
+
"""Chip text for the applied filter, or ``None`` when inactive."""
|
|
200
|
+
return None
|
|
201
|
+
|
|
202
|
+
def context(self, ctx: FilterRenderContext) -> dict[str, Any]:
|
|
203
|
+
"""Template variables for :attr:`template`; subclasses extend this."""
|
|
204
|
+
parsed = self.parse(ctx.query)
|
|
205
|
+
return {
|
|
206
|
+
"filter": self,
|
|
207
|
+
"parsed": parsed,
|
|
208
|
+
"active": bool(parsed),
|
|
209
|
+
"error": self.error(ctx.query),
|
|
210
|
+
"clear_href": clear_href(ctx.query, self.query_keys),
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
def render(self, ctx: FilterRenderContext) -> str:
|
|
214
|
+
"""Render the sidebar group for this filter."""
|
|
215
|
+
env = ctx.templates or default_environment()
|
|
216
|
+
return env.get_template(self.template).render(**self.context(ctx))
|
|
217
|
+
|
|
218
|
+
def typed_conditions(
|
|
219
|
+
self,
|
|
220
|
+
binding: FilterBinding | None,
|
|
221
|
+
params: Mapping[str, str | Sequence[str]],
|
|
222
|
+
) -> list[FilterCondition]:
|
|
223
|
+
"""Coerce ``params`` through the typed pipeline for :attr:`field`.
|
|
224
|
+
|
|
225
|
+
``params`` maps an operator suffix (``""`` for exact, ``"gte"``,
|
|
226
|
+
``"lte"``, ``"in"``) to the raw value(s). The model's annotation types
|
|
227
|
+
the values; without one the filter's ``value_type`` does. Values that
|
|
228
|
+
fail to coerce are dropped, like any other bad querystring input.
|
|
229
|
+
"""
|
|
230
|
+
binding = binding or FilterBinding()
|
|
231
|
+
try:
|
|
232
|
+
declared = self.field in schema_for(binding.model).model_fields
|
|
233
|
+
except TypeError: # no model bound, or a class the registry has no schema for
|
|
234
|
+
declared = False
|
|
235
|
+
raw_params = {
|
|
236
|
+
f"{FILTER_PARAM_PREFIX}{self.field}{'__' + suffix if suffix else ''}": value
|
|
237
|
+
for suffix, value in params.items()
|
|
238
|
+
}
|
|
239
|
+
return parse_filter_params(
|
|
240
|
+
binding.model,
|
|
241
|
+
raw_params,
|
|
242
|
+
[self.field],
|
|
243
|
+
tz=binding.tz,
|
|
244
|
+
datetime_kind=binding.datetime_kind,
|
|
245
|
+
annotation_of=None if declared else (lambda _name: self.value_type),
|
|
246
|
+
).conditions
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""Boolean filters: a tri-state ``Any/Yes/No`` and the "Mine only" owner switch."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import TYPE_CHECKING, Any, ClassVar
|
|
7
|
+
|
|
8
|
+
from hyperadmin.core.filtering import FilterCondition
|
|
9
|
+
from hyperadmin.filters.base import FilterBinding, FilterDef, is_truthy, query_value
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from hyperadmin.filters.base import FilterRenderContext
|
|
13
|
+
|
|
14
|
+
_FALSE = frozenset({"0", "false", "no", "off"})
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(frozen=True, kw_only=True)
|
|
18
|
+
class BooleanFilter(FilterDef):
|
|
19
|
+
"""Tri-state radio on a boolean column: ``{field}=`` (any), ``1`` (yes) or ``0`` (no)."""
|
|
20
|
+
|
|
21
|
+
template: ClassVar[str] = "components/filters/boolean.html"
|
|
22
|
+
value_type: ClassVar[Any] = bool
|
|
23
|
+
|
|
24
|
+
def parse(self, qs: Any) -> dict[str, Any]:
|
|
25
|
+
raw = query_value(qs, self.field)
|
|
26
|
+
if is_truthy(raw):
|
|
27
|
+
return {"value": True}
|
|
28
|
+
if raw is not None and raw.lower() in _FALSE:
|
|
29
|
+
return {"value": False}
|
|
30
|
+
return {}
|
|
31
|
+
|
|
32
|
+
def compile(
|
|
33
|
+
self, parsed: dict[str, Any], binding: FilterBinding | None = None
|
|
34
|
+
) -> list[FilterCondition]:
|
|
35
|
+
if "value" not in parsed:
|
|
36
|
+
return []
|
|
37
|
+
return self.typed_conditions(binding, {"": "true" if parsed["value"] else "false"})
|
|
38
|
+
|
|
39
|
+
def describe(self, parsed: dict[str, Any]) -> str | None:
|
|
40
|
+
if "value" not in parsed:
|
|
41
|
+
return None
|
|
42
|
+
return "Yes" if parsed["value"] else "No"
|
|
43
|
+
|
|
44
|
+
def context(self, ctx: FilterRenderContext) -> dict[str, Any]:
|
|
45
|
+
base = super().context(ctx)
|
|
46
|
+
value = base["parsed"].get("value")
|
|
47
|
+
base["state"] = "" if value is None else ("1" if value else "0")
|
|
48
|
+
return base
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(frozen=True, kw_only=True)
|
|
52
|
+
class IsOwnerFilter(FilterDef):
|
|
53
|
+
"""The "Mine only" switch (``is_owner=1``): rows an owner column assigns to the current user.
|
|
54
|
+
|
|
55
|
+
Compares each of ``owner_fields`` to ``binding.user_key`` (what the v0.5.8
|
|
56
|
+
auth pipeline sets as ``request.state.user_key``). One field compiles to an
|
|
57
|
+
``exact`` condition; several compile to one ``any_of`` condition (created
|
|
58
|
+
*or* assigned to me). With no user key (anonymous) nothing is applied, so
|
|
59
|
+
the filter can never widen a result.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
owner_fields: One column name, or several to OR together.
|
|
63
|
+
help_text: Sidebar hint saying what "mine" means for this model.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
template: ClassVar[str] = "components/filters/is_owner.html"
|
|
67
|
+
|
|
68
|
+
owner_fields: tuple[str, ...] | list[str] | str
|
|
69
|
+
label: str | None = "Mine only"
|
|
70
|
+
help_text: str | None = None
|
|
71
|
+
field: str = field(init=False, default="")
|
|
72
|
+
|
|
73
|
+
def __post_init__(self) -> None:
|
|
74
|
+
names = (self.owner_fields,) if isinstance(self.owner_fields, str) else self.owner_fields
|
|
75
|
+
cleaned = tuple(dict.fromkeys(name.strip() for name in names if name and name.strip()))
|
|
76
|
+
if not cleaned:
|
|
77
|
+
msg = "IsOwnerFilter needs at least one owner field"
|
|
78
|
+
raise ValueError(msg)
|
|
79
|
+
object.__setattr__(self, "owner_fields", cleaned)
|
|
80
|
+
object.__setattr__(self, "field", cleaned[0])
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def slug(self) -> str:
|
|
84
|
+
return "is_owner"
|
|
85
|
+
|
|
86
|
+
@property
|
|
87
|
+
def query_keys(self) -> tuple[str, ...]:
|
|
88
|
+
return ("is_owner",)
|
|
89
|
+
|
|
90
|
+
def parse(self, qs: Any) -> dict[str, Any]:
|
|
91
|
+
return {"is_owner": True} if is_truthy(query_value(qs, "is_owner")) else {}
|
|
92
|
+
|
|
93
|
+
def compile(
|
|
94
|
+
self, parsed: dict[str, Any], binding: FilterBinding | None = None
|
|
95
|
+
) -> list[FilterCondition]:
|
|
96
|
+
user_key = binding.user_key if binding is not None else None
|
|
97
|
+
if not parsed.get("is_owner") or user_key is None:
|
|
98
|
+
return []
|
|
99
|
+
fields = tuple(self.owner_fields)
|
|
100
|
+
if len(fields) == 1:
|
|
101
|
+
return [FilterCondition(fields[0], "exact", user_key)]
|
|
102
|
+
return [FilterCondition(fields[0], "any_of", tuple((name, user_key) for name in fields))]
|
|
103
|
+
|
|
104
|
+
def describe(self, parsed: dict[str, Any]) -> str | None:
|
|
105
|
+
return self.title if parsed.get("is_owner") else None
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""``MultiChoiceFilter``: pick several values of an enum or a fixed choice list."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from enum import Enum
|
|
7
|
+
from typing import TYPE_CHECKING, Any, ClassVar
|
|
8
|
+
|
|
9
|
+
from hyperadmin.core.display import get_enum_label
|
|
10
|
+
from hyperadmin.filters.base import FilterBinding, FilterDef, FilterRenderContext
|
|
11
|
+
from hyperadmin.filters.relation import parse_membership
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from collections.abc import Sequence
|
|
15
|
+
|
|
16
|
+
from hyperadmin.core.filtering import FilterCondition
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True, kw_only=True)
|
|
20
|
+
class MultiChoiceFilter(FilterDef):
|
|
21
|
+
"""``{field}__in`` membership over a known set of values.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
choices: An ``Enum`` class, or ``(value, label)`` pairs. When given,
|
|
25
|
+
unknown querystring values are dropped; when ``None``, the view
|
|
26
|
+
supplies ``ctx.choices`` and any value is passed to the typed pipeline.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
template: ClassVar[str] = "components/filters/multi_choice.html"
|
|
30
|
+
|
|
31
|
+
choices: type[Enum] | Sequence[tuple[str, str]] | None = None
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def query_keys(self) -> tuple[str, ...]:
|
|
35
|
+
return (f"{self.field}__in",)
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def options(self) -> list[tuple[str, str]]:
|
|
39
|
+
"""The declared choices as ``(value, label)`` pairs (``[]`` when undeclared)."""
|
|
40
|
+
if self.choices is None:
|
|
41
|
+
return []
|
|
42
|
+
if isinstance(self.choices, type) and issubclass(self.choices, Enum):
|
|
43
|
+
return [(str(member.value), get_enum_label(member)) for member in self.choices]
|
|
44
|
+
return [(str(value), str(label)) for value, label in self.choices]
|
|
45
|
+
|
|
46
|
+
def parse(self, qs: Any) -> dict[str, Any]:
|
|
47
|
+
values = parse_membership(qs, f"{self.field}__in")
|
|
48
|
+
if self.choices is not None:
|
|
49
|
+
known = {value for value, _label in self.options}
|
|
50
|
+
values = [value for value in values if value in known]
|
|
51
|
+
return {"in": values} if values else {}
|
|
52
|
+
|
|
53
|
+
def compile(
|
|
54
|
+
self, parsed: dict[str, Any], binding: FilterBinding | None = None
|
|
55
|
+
) -> list[FilterCondition]:
|
|
56
|
+
values = parsed.get("in")
|
|
57
|
+
return self.typed_conditions(binding, {"in": values}) if values else []
|
|
58
|
+
|
|
59
|
+
def describe(self, parsed: dict[str, Any]) -> str | None:
|
|
60
|
+
values: list[str] = parsed.get("in") or []
|
|
61
|
+
if not values:
|
|
62
|
+
return None
|
|
63
|
+
labels = dict(self.options)
|
|
64
|
+
return ", ".join(labels.get(value, value) for value in values)
|
|
65
|
+
|
|
66
|
+
def context(self, ctx: FilterRenderContext) -> dict[str, Any]:
|
|
67
|
+
base = super().context(ctx)
|
|
68
|
+
selected = set(base["parsed"].get("in", ()))
|
|
69
|
+
options = self.options or [(str(c["value"]), str(c["label"])) for c in ctx.choices]
|
|
70
|
+
base["choices"] = [
|
|
71
|
+
{"value": value, "label": label, "selected": value in selected}
|
|
72
|
+
for value, label in options
|
|
73
|
+
]
|
|
74
|
+
return base
|