model_crud_component
django_spire.core.components.scroll.model_crud_component
ModelCrudScrollComponent
Bases: QuerySetScrollComponent, ABC
A :class:QuerySetScrollComponent with ready-made actions on its rows.
The template's createItem(), editItem(item) and deleteItem(item)
perform them, and each takes the item or its key.
item_form_options says how a row is created and edited: a
ModelCrudScrollComponent.FormOptions shows a form component in a
modal, and a ModelCrudScrollComponent.PageFormOptions sends the user
to a page. Left as None, the list has no create or edit.
item_delete_options says how a row is deleted: a
ModelCrudScrollComponent.DeleteOptions shows a confirmation component
in a modal, and a ModelCrudScrollComponent.PageDeleteOptions sends the
user to a page. The default is a confirmation that soft-deletes the row
with set_deleted(). Left as None, the list has no delete.
Only rows in get_queryset() can be edited or deleted. The browser
fetches the form and the confirmation with load_item_form() and
load_item_delete_confirmation(), which check the user's access and
that the row is in the list. Customise an action through the two settings
and get_queryset(), which keep those checks, and not by overriding the
callables.
DeleteOptions = delete_options.DeleteOptions
class-attribute
instance-attribute
PageDeleteOptions = delete_options.PageDeleteOptions
class-attribute
instance-attribute
FormOptions = form_options.FormOptions
class-attribute
instance-attribute
PageFormOptions = form_options.PageFormOptions
class-attribute
instance-attribute
template = 'django_spire/component/scroll/crud_scroll.html'
class-attribute
instance-attribute
item_delete_options = DeleteOptions()
class-attribute
item_form_options = None
class-attribute
can_create
property
Whether createItem() can open the form: a form page guards itself,
and a form component needs ADD access.
can_edit
property
Whether editItem() can open the form on a row: a form page guards
itself, and a form component needs CHANGE access. A list whose
rows are only ever created overrides it to False, and
load_item_form() then refuses a row.
can_delete
property
Whether deleteItem() can delete a row: a delete page guards itself,
and a confirmation needs DELETE access.
__init_subclass__
Source code in django_spire/core/components/scroll/model_crud_component.py
get_item_form_options
get_item_delete_options
load_item_delete_confirmation
Source code in django_spire/core/components/scroll/model_crud_component.py
load_item_form
The form that creates a row, or with pk edits one. ADD access
is the least that opens any form. The form then guards what it does:
it takes this list's access, and Glue's required_save_access lets
its fields and save change a saved row only at CHANGE. A form
component that mixes in Glue.ModelAccessRequiredMixin also refuses
to open for a user without that access. can_edit refuses a row
before any form is built: below CHANGE, and in a list whose rows
are never edited, which no access expresses.