scroll
django_spire.core.components.scroll
__all__ = ['BaseScrollComponent', 'ModelCrudScrollComponent', 'QuerySetScrollComponent', 'SearchAndSortScrollMixin']
module-attribute
BaseScrollComponent
Bases: Component, ABC
An infinite list of any kind of item.
Subclasses supply the items through get_items(), get_item() and
get_item_key(); this base owns paging and every client behaviour.
The server keeps no position: the client sends the number of items it
holds, and a render always shows the first batch.
item_template is the markup for one item. Each item is rendered on
the server, so the template must extend the scroll's item/item.html
or item/table_item.html.
A callable that changes an item fires item_added, item_changed or
item_removed with key=, and the list updates that one row.
Served by as_view(), the list fills spire's full page.
template = 'django_spire/component/scroll/scroll.html'
class-attribute
instance-attribute
view_template = 'django_spire/component/page/full_page.html'
class-attribute
instance-attribute
item_template = None
class-attribute
batch_size = 25
class-attribute
item_added = Glue.event()
class-attribute
instance-attribute
item_changed = Glue.event()
class-attribute
instance-attribute
item_removed = Glue.event()
class-attribute
instance-attribute
renders_items_on_server
property
first_batch
cached
property
get_items
abstractmethod
Return up to limit items starting at offset, in an order that
is the same on every call.
get_item
abstractmethod
Return the item with this key, or None when it no longer belongs in the list.
get_item_key
abstractmethod
introduce
Check, once per class, that its templates extend the scroll's own.
Source code in django_spire/core/components/scroll/base_component.py
load_items
Source code in django_spire/core/components/scroll/base_component.py
load_item
Source code in django_spire/core/components/scroll/base_component.py
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.
Source code in django_spire/core/components/scroll/model_crud_component.py
QuerySetScrollComponent
Bases: BaseScrollComponent, ABC
A :class:BaseScrollComponent whose items are the rows of a queryset.
Subclasses return the rows from get_queryset(). The primary key
identifies each row and is appended to the queryset's ordering, so that
the order is total; a queryset with no ordering is listed by primary key.
Each item is a model instance.
glue_items sends each row to the browser as the Glue model
get_glue_item() builds, in place of rendering it on the server, so
the row markup can call the model's Glue methods. The rows are drawn in
the browser: item_template is Alpine markup that reads item, drawn
by the scroll_item block of the component template, which a list may
fill in itself instead. The browser then loads rows with
load_glue_items() and load_glue_item(), and the other loads are
refused.
Glue rows never arrive with the render: a Glue child is not derived again
when its component refreshes, so every batch comes from
load_glue_items(). A batch holds up to batch_size rows, and a full
one means there may be more.
glue_items = False
class-attribute
model_name
cached
property
verbose_name
cached
property
verbose_name_plural
cached
property
renders_items_on_server
property
__init_subclass__
Source code in django_spire/core/components/scroll/queryset_component.py
get_queryset
abstractmethod
get_permission_model
Return the listed model, whose permissions Glue.ModelAccessMixin reads.
get_items
Source code in django_spire/core/components/scroll/queryset_component.py
get_item
get_item_key
get_instance
Return the row of get_queryset() with this primary key, for a
callable that acts on one row. A row that is not in the list is
reported as Glue's model_instance_not_found, a 404.
Source code in django_spire/core/components/scroll/queryset_component.py
get_glue_item
Return the Glue model the browser receives for item when
glue_items is set, built with name as its unique name and with
exactly the fields, access and form the row needs. A list that sets
glue_items must override it.
To edit a row in place, pass the row a form, bind the row's inputs
to item.form, and save with the form's own method, such as
item.form.save_model_obj(). That runs the form's validation and
whatever the application's save does. item.save() writes the model
directly instead.
Source code in django_spire/core/components/scroll/queryset_component.py
load_glue_item
Source code in django_spire/core/components/scroll/queryset_component.py
load_glue_items
Source code in django_spire/core/components/scroll/queryset_component.py
SearchAndSortScrollMixin
Adds search and optional sort :class:Glue.ComponentField
attributes to a scroll component without writing a boilerplate
FilterForm.
Declare default_sort as a Django Choices member (e.g.
SolutionSortChoices.NAME) and sort_choices is inferred from
type(default_sort) automatically. Or declare sort_choices alone to
default to its first choice. Omit both for a search-only list.