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 inClassifierFilterBlock
.It allows the user to select a set of classifiers by which to filter the projects listing table.
- 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 checkboxesnodes (_type_) – _description_
- get_checkbox(node: ClassifierNode) HorizontalLayoutBlock [source]
Build and return the
wildewidgets.CheckboxInputBlock
for the classifiernode
.- Parameters
node – the classifier data
- Returns
A configured
wildewidgets.CheckboxInputBlock
- class sphinx_hosting.wildewidgets.ClassifierFilterBlock(table_name: str, column_number: int, **kwargs)[source]
A
wildewidgets.CardWidget
that contains theClassifierFilterForm
. This the right of thesphinx_hosting.wildewidgets.project.ProjectTable
. This widget is embedded insphinx_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
- class sphinx_hosting.wildewidgets.ProjectCreateModalWidget(*args, **kwargs)[source]
This is a modal dialog that holds the
sphinx_hosting.forms.ProjectCreateForm
.
- 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.
- class sphinx_hosting.wildewidgets.ProjectTableWidget(user: AbstractUser, **kwargs)[source]
This is a
wildewidgets.CardWidget
that gives ourProjectTable
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 ourProjectTable
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 ourProjectVersionTable
dataTable a nice header with a total version count.
- 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
.- filter_classifiers_column(qs: QuerySet, column: str, value: str) QuerySet [source]
Filter our results by the
value
, a comma separated list ofsphinx_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 renderingcolunn – 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 thesphinx_hosting.models.Version
that has the most recentsphinx_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 renderingcolunn – 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 thesphinx_hosting.models.Version
that has the most recentsphinx_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 renderingcolunn – 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 asrender_FIELD_NAME_column
methods
- class sphinx_hosting.wildewidgets.ProjectVersionTable(*args, **kwargs)[source]
This widget displays a dataTable of our
sphinx_hosting.models.Version
instances for a particularsphinx_hosting.models.Project
.It’s used as a the main widget in by
ProjectVersionTableWidget
.- __init__(*args, **kwargs) None [source]
One of our
kwargs
must beproject_id
, thepk
of thesphinx_hosting.models.Project
for which we want to listsphinx_hosting.models.Version
objects.This will get added to the
extra_data
dict in thekwargs
key, from which we reference it.
- get_initial_queryset() QuerySet [source]
Filter our
sphinx_hosting.models.Version
objects byproject_id
.- Returns
A filtered
QuerySet
onsphinx_hosting.models.Version
- render_num_images_column(row: Version, column: str) str [source]
Render our
num_images
column. This is the number ofsphinx_hosting.models.SphinxImage
objects imported for this version.- Parameters
row – the
Version
we are renderingcolunn – 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 ofsphinx_hosting.models.SphinxPage
objects imported for this version.- Parameters
row – the
Version
we are renderingcolunn – 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 namedActions
with a button nameddefault_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 asrender_FIELD_NAME_column
methods
Search
These widgets are used on the search results page.
- class sphinx_hosting.wildewidgets.GlobalSearchFormWidget(*args, **kwargs)[source]
This widget encapsulates the
sphinx_hosting.forms.GlobalSearchForm
.
- class sphinx_hosting.wildewidgets.PagedSearchLayout(results: SearchQuerySet, query: Optional[str] = None, facets: Optional[Dict[str, List[str]]] = None, **kwargs)[source]
This is the page layout for the entire search results page.
- Parameters
query – the text entered into the search form that got us to this results page
- Keyword Arguments
query – the text entered into the search form that got us to this results page
facets – the active facet filters. This will be a dict where the key is the facet name, and the value is a list of facet values to filter by.
- class sphinx_hosting.wildewidgets.SearchResultsPageHeader(query: Optional[str], facets: Optional[Dict[str, List[str]]] = None, **kwargs)[source]
The header for the entire search results page. This shows the search string that got us here, and any active facet filters, allowing the user to remove any active filter by clicking the “X” next to the filter name.
- Parameters
query – the text entered into the search form that got us to this results page
- Keyword Arguments
facets – the active facet filters. This will be a dict where the key is the facet name, and the value is a list of facet values to filter by.
- class sphinx_hosting.wildewidgets.FacetBlock(results: SearchQuerySet, query: Optional[str], **kwargs)[source]
This is a base class for blocks that appear to the right of the search results listing on the search results page that allows you to refine your results by a particular facet that is present in the result set.
Subclass this to create facet filtering blocks for specific facets. Any facet you want to filter by must be defined on your search index by adding
faceted=True
to the field definition.- Parameters
results – the Haystack search queryset containing our search results
query – the text entered into the search form that got us to this results page
- class sphinx_hosting.wildewidgets.SearchResultsClassifiersFacet(results: SearchQuerySet, query: Optional[str], **kwargs)[source]
A
FacetBlock
that allows the user to filter search results by classifier.- model
alias of
Classifier
- class sphinx_hosting.wildewidgets.SearchResultsProjectFacet(results: SearchQuerySet, query: Optional[str], **kwargs)[source]
A
FacetBlock
that allows the user to filter search results by project.
- class sphinx_hosting.wildewidgets.PagedSearchResultsBlock(results: SearchQuerySet, query: Optional[str], **kwargs)[source]
This is a paged listing of
SearchResultBlock
entries describing our search results.- model
alias of
SphinxPage
- model_widget
alias of
SearchResultBlock
- class sphinx_hosting.wildewidgets.SearchResultsHeader(results: SearchQuerySet, **kwargs)[source]
The header for the search results listing (not the page header – that is
SearchResultsPageHeader
).- Parameters
results – the Haystack search queryset containing our search results
- justify: str = 'between'
start
,center
,end
,between
,around
,evenly
. See Bootstrap: Flex, justify content. If not supplied here andjustify
isNone
, do whatever horizontal aligment Bootstrap does by default.
- class sphinx_hosting.wildewidgets.SearchResultBlock(object: Optional[SearchResult] = None, **kwargs)[source]
This is the block we use for rendering a particular search result on the search results page.
- Keyword Arguments
object – the
haystack.models.SearchResult
object to render
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
- class sphinx_hosting.wildewidgets.VersionSphinxPageTableWidget(version_id: int, **kwargs)[source]
This is a
wildewidgets.CardWidget
that gives ourVersionSphinxPageTable
dataTable a nice header with a total page count.
- 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.
- class sphinx_hosting.wildewidgets.VersionSphinxImageTableWidget(version_id: int, **kwargs)[source]
This is a
wildewidgets.CardWidget
that gives ourVersionSphinxImageTable
dataTable a nice header with a total image count.
- class sphinx_hosting.wildewidgets.VersionSphinxPageTable(*args, **kwargs)[source]
This widget displays a dataTable of our
sphinx_hosting.models.SphinxPage
instances for a particularsphinx_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 beversion_id
, thepk
of thesphinx_hosting.models.Version
for which we want to listsphinx_hosting.models.SphinxPage
objects.This will get added to the
extra_data
dict in thekwargs
key, from which we reference it.
- get_initial_queryset() QuerySet [source]
Filter our
sphinx_hosting.models.SphinxPage
objects byversion_id
.
- actions: bool = True
Per row action buttons. If not
False
, this will simply add a rightmost column namedActions
with a button nameddefault_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 ourmodel
, or names of computed fields that will be rendered with arender_FIELD_column
method. IfNone
, empty list
- class sphinx_hosting.wildewidgets.VersionSphinxImageTable(*args, **kwargs)[source]
This widget displays a dataTable of our
sphinx_hosting.models.SphinxImage
instances for a particularsphinx_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 beversion_id
, thepk
of thesphinx_hosting.models.Version
for which we want to listsphinx_hosting.models.SphinxPage
objects.This will get added to the
extra_data
dict in thekwargs
key, from which we reference it.
- get_initial_queryset() QuerySet [source]
Filter our
sphinx_hosting.models.SphinxPage
objects byversion_id
.
- render_file_path_column(row: Version, column: str) str [source]
Render our
file_path
column. This is the path to the file inMEDIA_ROOT
.- Parameters
row – the
Version
we are renderingcolunn – 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 thesphinx_hosting.models.SphinxImage.file
field.- Parameters
row – the
Version
we are renderingcolunn – 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 ourmodel
, or names of computed fields that will be rendered with arender_FIELD_column
method. IfNone
, empty list
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 awildewidgets.Menu
suitable for insertion into awildewidgets.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
.
- 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 sizedcol
.- __init__(page: SphinxPage, **kwargs)[source]
- 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]
- 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]
- 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]