Widgets

This part of the documentation covers all the reusable django-wildewidgets widgets provided by django-sphinx-hosting.

Projects

These widgets are used on the project listing and details pages.

class sphinx_hosting.wildewidgets.ClassifierFilterForm(table_name: str, column_number: int, **kwargs)[source]

The tree-like classifier filter form that appears to the right of the sphinx_hosting.wildewidgets.project.ProjectTable. It is embedded in ClassifierFilterBlock.

It allows the user to select a set of classifiers by which to filter the projects listing table.

__init__(table_name: str, column_number: int, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

add_subtree(contents: UnorderedList, nodes: dict[str, sphinx_hosting.models.ClassifierNode]) None[source]

Add a subtree of classifier checkboxes.

Parameters:
  • contents – the <ul> block to which to add our list of classifier checkboxes nodes (_type_): _description_

  • nodes – the classifier nodes to add to the list. The key is the classifier id, and the value is the ClassifierNode instance.

get_checkbox(node: ClassifierNode) HorizontalLayoutBlock[source]

Build and return the wildewidgets.CheckboxInputBlock for the classifier node.

Parameters:

node – the classifier data

Returns:

A configured wildewidgets.CheckboxInputBlock

block: str = 'classifiers__filter__form'

block is the official wildewidgets name of the block; it can’t be changed

tag: str = 'form'
class sphinx_hosting.wildewidgets.ClassifierFilterBlock(table_name: str, column_number: int, **kwargs)[source]

A wildewidgets.CardWidget that contains the ClassifierFilterForm. This the right of the sphinx_hosting.wildewidgets.project.ProjectTable. This widget is embedded in sphinx_hosting.wildewdigets.project.ProjectTableWidget

Parameters:
  • table_name – the name of the dataTables table to control

  • column_number – the number of the column in the dataTable that contains classifier names

__init__(table_name: str, column_number: int, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

name: str = 'classifiers__filter'

The CSS class that will be added to this element to as an identifier for

class sphinx_hosting.wildewidgets.ProjectCreateModalWidget(*args, **kwargs)[source]

A modal dialog that holds the sphinx_hosting.forms.ProjectCreateForm.

Parameters:

args – the arguments to pass to the modal widget

Keyword Arguments:

kwargs – the keyword arguments to pass to the modal widget

__init__(*args, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

modal_id: str = 'project__create'
modal_title: str = 'Add Project'
class sphinx_hosting.wildewidgets.ProjectDetailWidget(*blocks: Any, form: Form | None = None, **kwargs: Any)[source]

Renders an update form for a sphinx_hosting.models.Project.

Use directly it like so:

>>> project = Project.objects.get(pk=1)
>>> form = ProjectUpdateForm(instance=project)
>>> widget = ProjectDetailWidget(form=form)

Or you can simply add the form to your view context and ProjectDetailWidget will pick it up automatically.

css_class: str = ' p-4'
modifier: str = 'general'

If specified, also add a class named {name}--{modifier} to the CSS

name: str = 'project-detail__section'

The CSS class that will be added to this element to as an identifier for

class sphinx_hosting.wildewidgets.ProjectTableWidget(user: AbstractUser, **kwargs)[source]

A wildewidgets.CardWidget that gives our ProjectTable dataTable a nice header with a total book count and an “Add Project” button that opens a modal dialog.

__init__(user: AbstractUser, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

get_title(user: AbstractUser) WidgetListLayoutHeader[source]

Retrieve the widget’s title.

Returns:

The widget’s title string, widget object, or None if no title is set.

class sphinx_hosting.wildewidgets.ProjectVersionsTableWidget(project_id: int, **kwargs)[source]

A wildewidgets.CardWidget that gives our ProjectVersionTable dataTable a nice header with a total version count.

__init__(project_id: int, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

get_title() WidgetListLayoutHeader[source]

Retrieve the widget’s title.

Returns:

The widget’s title string, widget object, or None if no title is set.

class sphinx_hosting.wildewidgets.ProjectTable(*args, actions: list[wildewidgets.widgets.tables.actions.RowActionButton] | None = None, button_size: str | None = None, justify: Literal['start', 'center', 'end'] | None = None, **kwargs)[source]

Displays a dataTable of our sphinx_hosting.models.Project instances.

It’s used as a the main widget in by ProjectTableWidget.

model

alias of Project

filter_classifiers_column(qs: QuerySet, _: str, value: str) QuerySet[source]

Filter our results by the value, a comma separated list of sphinx_hosting.models.Classifier names.

Parameters:
  • qs – the current QuerySet

  • colunn – the name of the column to filter on

  • value – a comma-separated list of classifier names

Returns:

A QuerySet filtered for rows that contain the selected classifiers.

render_classifiers_column(row: Project, _: str) str[source]

Render our classifiers column.

Parameters:
  • row – the Project we are rendering

  • colunn – the name of the column to render

Returns:

A <br> separated list of classifier names

render_latest_version_column(row: Project, _: str) str[source]

Render our latest_version column. This is the version string of the sphinx_hosting.models.Version that has the most recent sphinx_hosting.models.Version.modified timestamp.

If there are not yet any sphinx_hosting.models.Version instances for this project, return empty string.

Parameters:
  • row – the Project we are rendering

  • colunn – the name of the column to render

Returns:

The version string of the most recently published version, or empty string.

render_latest_version_date_column(row: Project, _: str) str[source]

Render our latest_version_date column. This is the last modified date of the sphinx_hosting.models.Version that has the most recent sphinx_hosting.models.Version.modified timestamp.

If there are not yet any sphinx_hosting.models.Version instances for this project, return empty string.

Parameters:
  • row – the Project we are rendering

  • colunn – the name of the column to render

Returns:

The of the most recently published version, or empty string.

actions: Final[list[RowActionButton]] = [<sphinx_hosting.wildewidgets.project.LatestVersionButton object>, <wildewidgets.widgets.tables.actions.RowModelUrlButton object>, <wildewidgets.widgets.tables.actions.RowEditButton object>]

A list of RowActionButton subclasses to display in the

alignment: Final[dict[str, str]] = {'classifiers': 'left', 'description': 'left', 'latest_version': 'left', 'latest_version_date': 'left', 'machine_name': 'left', 'title': 'left'}
fields: Final[list[str]] = ['title', 'machine_name', 'classifiers', 'latest_version', 'description', 'latest_version_date']

A list of fields that we will list as columns. These are either fields on our model, or defined as render_FIELD_NAME_column methods

hidden: Final[list[str]] = ['classifiers', 'machine_name', 'latest_version_date']
page_length: int = 25
striped: bool = True
unsearchable: Final[list[str]] = ['classifiers', 'latest_version', 'latest_version_date']

A list of names of columns that will will not be searched when doing a

unsortable: Final[list[str]] = ['latest_version', 'latest_version_date']

A list of names of columns that will will not be sortable

verbose_names: Final[dict[str, str]] = {'latest_version': 'Latest Version', 'latest_version_date': 'Import Date', 'machine_name': 'Machine Name', 'title': 'Project Name'}

A dict of column name to column label. We use it to override the

class sphinx_hosting.wildewidgets.ProjectVersionTable(*args, **kwargs)[source]

Displays a dataTable of our sphinx_hosting.models.Version instances for a particular sphinx_hosting.models.Project.

It’s used as a the main widget in by ProjectVersionTableWidget.

model

alias of Version

__init__(*args, **kwargs) None[source]

One of our kwargs must be project_id, the pk of the sphinx_hosting.models.Project for which we want to list sphinx_hosting.models.Version objects.

This will get added to the extra_data dict in the kwargs key, from which we reference it.

get_initial_queryset() QuerySet[Version][source]

Filter our sphinx_hosting.models.Version objects by project_id.

Returns:

A filtered QuerySet on sphinx_hosting.models.Version

render_num_images_column(row: Version, _: str) str[source]

Render our num_images column. This is the number of sphinx_hosting.models.SphinxImage objects imported for this version.

Parameters:
  • row – the Version we are rendering

  • colunn – the name of the column to render

Returns:

The number of images for this version.

render_num_pages_column(row: Version, _: str) str[source]

Render our num_pages column. This is the number of sphinx_hosting.models.SphinxPage objects imported for this version.

Parameters:
  • row – the Version we are rendering

  • colunn – the name of the column to render

Returns:

The number of pages for this version.

actions: bool = True

Per row action buttons. If not False, this will simply add a rightmost column named Actions with a button named default_action_button_label which when clicked will take the

alignment: Final[dict[str, str]] = {'created': 'left', 'modified': 'left', 'num_images': 'right', 'num_pages': 'right', 'version': 'left'}
fields: Final[list[str]] = ['version', 'num_pages', 'num_images', 'created', 'modified']

A list of fields that we will list as columns. These are either fields on our model, or defined as render_FIELD_NAME_column methods

page_length: int = 25
project_id: int | None

The pk of the sphinx_hosting.models.Project for which to

sort_ascending: bool = False
striped: bool = True
unsearchable: Final[list[str]] = ['num_pages', 'num_images', 'created', 'modified']

A list of names of columns that will will not be searched when doing a

unsortable: Final[list[str]] = ['num_pages', 'num_images']
verbose_names: Final[dict[str, str]] = {'num_images': '# Images', 'num_pages': '# Pages', 'title': 'Version'}

A dict of column name to column label. We use it to override the

Versions

class sphinx_hosting.wildewidgets.VersionInfoWidget(version: Version, **kwargs)[source]

Gives a wildewidget.Datagrid type overview of information about this version:

  • A link to the project that owns this sphinx_hosting.models.Version

  • Create and last modified timestamps

  • What version of Sphinx was used to generate the pages

Parameters:

version – the Version object we’re describing

__init__(version: Version, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

class sphinx_hosting.wildewidgets.VersionSphinxPageTableWidget(version_id: int, **kwargs)[source]

A wildewidgets.CardWidget that gives our VersionSphinxPageTable dataTable a nice header with a total page count.

__init__(version_id: int, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

get_title() WidgetListLayoutHeader[source]

Retrieve the widget’s title.

Returns:

The widget’s title string, widget object, or None if no title is set.

class sphinx_hosting.wildewidgets.VersionUploadBlock(*blocks, form=None, **kwargs)[source]

Holds the upload form for uploading documentation tarballs. Once uploaded, the tarball will be run through sphinx_hosting.importers.SphinxPackageImporter to actually import it into the database.

__init__(*blocks, form=None, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

css_class: str = 'my-3 border'
class sphinx_hosting.wildewidgets.VersionSphinxImageTableWidget(version_id: int, **kwargs)[source]

A wildewidgets.CardWidget that gives our VersionSphinxImageTable dataTable a nice header with a total image count.

__init__(version_id: int, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

get_title() WidgetListLayoutHeader[source]

Retrieve the widget’s title.

Returns:

The widget’s title string, widget object, or None if no title is set.

class sphinx_hosting.wildewidgets.VersionSphinxPageTable(*args, **kwargs)[source]

Displays a dataTable of our sphinx_hosting.models.SphinxPage instances for a particular sphinx_hosting.models.Version.

It’s used as a the main widget in by VersionSphinxPageTableWidget.

model

alias of SphinxPage

__init__(*args, **kwargs) None[source]

One of our kwargs must be version_id, the pk of the sphinx_hosting.models.Version for which we want to list sphinx_hosting.models.SphinxPage objects.

This will get added to the extra_data dict in the kwargs key, from which we reference it.

get_initial_queryset() QuerySet[source]

Filter our sphinx_hosting.models.SphinxPage objects by version_id.

actions: bool = True

Per row action buttons. If not False, this will simply add a rightmost column named Actions with a button named default_action_button_label which when clicked will take the

alignment: Final[dict[str, str]] = {'relative_path': 'left', 'size': 'right', 'title': 'left'}
fields: Final[list[str]] = ['title', 'relative_path', 'size']

These are the fields on our model (or which are computed) that we will

page_length: int = 25
striped: bool = True
version_id: int | None

The pk of the sphinx_hosting.models.Version for which to

class sphinx_hosting.wildewidgets.VersionSphinxImageTable(*args, **kwargs)[source]

Displays a dataTable of our sphinx_hosting.models.SphinxImage instances for a particular sphinx_hosting.models.Version.

It’s used as a the main widget in by VersionSphinxImageTableWidget.

model

alias of SphinxImage

__init__(*args, **kwargs) None[source]

One of our kwargs must be version_id, the pk of the sphinx_hosting.models.Version for which we want to list sphinx_hosting.models.SphinxPage objects.

This will get added to the extra_data dict in the kwargs key, from which we reference it.

get_initial_queryset() QuerySet[source]

Filter our sphinx_hosting.models.SphinxPage objects by version_id.

render_file_path_column(row: Version, _: str) str[source]

Render our file_path column. This is the path to the file in MEDIA_ROOT.

Parameters:
  • row – the Version we are rendering

  • colunn – the name of the column to render

Returns:

The size in bytes of the uploaded file.

render_size_column(row: Version, _: str) str[source]

Render our size column. This is the size in bytes of the sphinx_hosting.models.SphinxImage.file field.

Parameters:
  • row – the Version we are rendering

  • colunn – the name of the column to render

Returns:

The size in bytes of the uploaded file.

alignment: Final[dict[str, str]] = {'file_path': 'left', 'orig_path': 'left', 'size': 'right'}
fields: Final[list[str]] = ['orig_path', 'file_path', 'size']

These are the fields on our model (or which are computed) that we will

page_length: int = 25
striped: bool = True
version_id: int | None

The pk of the sphinx_hosting.models.Version for which to

Sphinx Pages

class sphinx_hosting.wildewidgets.SphinxPageGlobalTableOfContentsMenu(*items: MenuItem, title: str | None = None, title_tag: str | None = None, title_css_classes: str | None = None, **kwargs)[source]

The version-specific navigation menu that gets inserted into the page sidebar when viewing the documentation for a sphinx_hosting.models.Version. It will appear on all pages for that version.

classmethod parse_obj(version: Version) SphinxPageGlobalTableOfContentsMenu[source]

Parse the globaltoc of a sphinx_hosting.models.Version into a wildewidgets.Menu suitable for insertion into a wildewidgets.Navbar

The sphinx_hosting.models.Version.globaltoc is a dict that looks like this:

{
    items: [
        {'text': 'foo'},
        {'text': 'bar', 'url': '/foo', 'icon': 'blah'}
        {'text': 'bar', 'url': '/foo', 'icon': 'blah', items: [{'text': 'blah' ...} ...]}
        ...
    ]
}
Parameters:

version – the Version for which we are building the menu

Returns:

A configured SphinxPageGlobalTableOfContentsMenu.

css_class: str = 'mt-4'
title_css_classes: str = 'mt-3'
class sphinx_hosting.wildewidgets.SphinxPageLayout(page: SphinxPage, **kwargs)[source]

The page layout for a single sphinx_hosting.models.SphinxPage. It consists of a two column layout with the page’s table of contents in the left column, and the content of the page in the right column.

Parameters:

page – the SphinxPage to render

__init__(page: SphinxPage, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

class sphinx_hosting.wildewidgets.SphinxPagePagination(page: SphinxPage, **kwargs)[source]

Draws the “Previous Page”, Parent Page and Next Page buttons that are found at the top of each sphinx_hosting.views.SphinxPageDetailView.

It is built out of a Tabler/Bootstrap row, with each of the buttons in an equal sized col.

__init__(page: SphinxPage, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

name: str = 'sphinxpage-pagination'

The CSS class that will be added to this element to as an identifier for

class sphinx_hosting.wildewidgets.SphinxPageTitle(page: SphinxPage, **kwargs)[source]

The title block for a sphinx_hosting.models.SphinxPage page.

Parameters:

page – the SphinxPage to render

__init__(page: SphinxPage, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

block: str = 'sphinxpage-title'

block is the official wildewidgets name of the block; it can’t be changed

css_class: str = 'mb-5'
class sphinx_hosting.wildewidgets.SphinxPagePermalinkWidget(page: SphinxPage, **kwargs)[source]

Draws the “Permalink” button that is found at the top of the right-hand column of each sphinx_hosting.views.SphinxPageDetailView.

Parameters:

page – the SphinxPage we are rendering

__init__(page: SphinxPage, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

get_script() str | None[source]

Return the Javascript that will be executed when the “Permalink” button is clicked. This will copy the permalink to the browser clipboard.

Returns:

The javascript for this block.

class sphinx_hosting.wildewidgets.SphinxPageBodyWidget(page: SphinxPage, **kwargs)[source]

The body of the page. The body as stored in the model is actually a Django template, so we retrieve the body, run it through the Django template engine, and display the results.

Parameters:

page – the SphinxPage we are rendering

__init__(page: SphinxPage, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

css_class: str = 'sphinxpage-body'
class sphinx_hosting.wildewidgets.SphinxPageTableOfContentsWidget(page: SphinxPage, **kwargs)[source]

Draws the in-page navigation – the header hierarchy.

Parameters:

page – the SphinxPage we are rendering

__init__(page: SphinxPage, **kwargs)[source]

Initialize a new Widget instance.

Parameters:

*args – Variable length argument list passed to parent.

Keyword Arguments:
  • title – Optional title to display with the widget.

  • icon – Optional icon identifier to use for this widget.

  • **kwargs – Arbitrary keyword arguments passed to parent.

css_class: str = 'sphinxpage-toc'