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]

This is 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]
add_subtree(contents: UnorderedList, nodes: Dict[str, 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_

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]
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]

This is a modal dialog that holds the sphinx_hosting.forms.ProjectCreateForm.

__init__(*args, **kwargs)[source]
class sphinx_hosting.wildewidgets.ProjectDetailWidget(*blocks, form: Optional[Form] = None, **kwargs)[source]

This widget 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]

This is 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]
class sphinx_hosting.wildewidgets.ProjectTableWidget(user: AbstractUser, **kwargs)[source]

This is 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]
class sphinx_hosting.wildewidgets.ProjectVersionsTableWidget(project_id: int, **kwargs)[source]

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

__init__(project_id: int, **kwargs)[source]
class sphinx_hosting.wildewidgets.ProjectTable(*args, actions: Optional[List[RowActionButton]] = None, button_size: Optional[str] = None, justify: Optional[str] = None, **kwargs)[source]

This widget 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, column: 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, column: 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, column: 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, column: 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.

alignment: Dict[str, str] = {'classifiers': 'left', 'description': 'left', 'latest_version': 'left', 'latest_version_date': 'left', 'machine_name': 'left', 'title': 'left'}
fields: 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: List[str] = ['classifiers', 'machine_name', 'latest_version_date']
page_length: int = 25
striped: bool = True
unsearchable: List[str] = ['lastest_version', 'latest_version_date']

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

verbose_names: 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]

This widget 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[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, column: 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, column: 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: Dict[str, str] = {'created': 'left', 'modified': 'left', 'num_images': 'right', 'num_pages': 'right', 'version': 'left'}
fields: 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

order_columns: List[str] = ['version']
page_length: int = 25
project_id: Optional[int]
sort_ascending: bool = False
striped: bool = True
unsearchable: List[str] = ['num_pages', 'num_images']

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

verbose_names: 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]

This widget 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]
class sphinx_hosting.wildewidgets.VersionSphinxPageTableWidget(version_id: int, **kwargs)[source]

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

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

This block 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]
css_class: str = 'my-3 border'
class sphinx_hosting.wildewidgets.VersionSphinxImageTableWidget(version_id: int, **kwargs)[source]

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

__init__(version_id: int, **kwargs)[source]
class sphinx_hosting.wildewidgets.VersionSphinxPageTable(*args, **kwargs)[source]

This widget 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: Dict[str, str] = {'relative_path': 'left', 'size': 'right', 'title': 'left'}

A mapping of field name to field alignment. Valid values are left, right, and

fields: List[str] = ['title', 'relative_path', 'size']

This is either None, the string __all__ or a list of column names to use in our table. For the list, entries can either be field names from our model, or names of computed fields that will be rendered with a render_FIELD_column method. If None, empty list

page_length: int = 25
striped: bool = True
version_id: Optional[int]
class sphinx_hosting.wildewidgets.VersionSphinxImageTable(*args, **kwargs)[source]

This widget 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, column: 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, column: 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: Dict[str, str] = {'file_path': 'left', 'orig_path': 'left', 'size': 'right'}

A mapping of field name to field alignment. Valid values are left, right, and

fields: List[str] = ['orig_path', 'file_path', 'size']

This is either None, the string __all__ or a list of column names to use in our table. For the list, entries can either be field names from our model, or names of computed fields that will be rendered with a render_FIELD_column method. If None, empty list

page_length: int = 25
striped: bool = True
version_id: Optional[int]

Sphinx Pages

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

This is 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]
class sphinx_hosting.wildewidgets.SphinxPagePagination(page: SphinxPage, **kwargs)[source]

This widget 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]
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]
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.SphinxPageBodyWidget(page: SphinxPage, **kwargs)[source]

This widget holds 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]
css_class: str = 'sphinxpage-body'
class sphinx_hosting.wildewidgets.SphinxPageTableOfContentsWidget(page: SphinxPage, **kwargs)[source]

This widget draws the in-page navigation – the header hierarchy.

Parameters

page – the SphinxPage we are rendering

__init__(page: SphinxPage, **kwargs)[source]
css_class: str = 'sphinxpage-toc'