Models
Fields
- class sphinx_hosting.fields.MachineNameField(*args, max_length=50, db_index=True, allow_unicode=False, **kwargs)[source]
A
django.forms.SlugFieldthat also allows “.” characters. “.” is not uncommon in some project names, especially if the project is named after the website domain it hosts.
Managers
- class sphinx_hosting.models.ClassifierManager(*args, **kwargs)[source]
Manager for
Classifiermodels.- tree() Dict[str, ClassifierNode][source]
Given our classifiers, which are
::separated lists of terms like:Section :: Subsection :: Name Section :: Subsection :: Name2 Section :: Subsection :: Name3 Section :: Subsection
Return a tree-like data structure that looks like:
{ 'Section': ClassifierNode( title='Section' items={ 'Subsection': ClassifierNode( title='Subsection', classifier=Classifier(name="Section :: Subsection"), items: { 'Name': ClassifierNode( title='Name', classifier=Classifier( name='Section :: Subsection :: Name' ) ), ... } ) } ) }
Models
- class sphinx_hosting.models.Classifier(*args, **kwargs)[source]
Database table:
sphinxhostingcore_classifierA
Projectcan be tagged with one or moreClassifiertags. This allows you to group projects by ecosystem, or type, for example.Use PyPI classifiers as an example of how to use a single field for classifying across many dimensions.
Examples:
Ecosystem :: CMS Language :: Python Owner :: DevOps :: AWS
- Parameters:
Reverse relationships:
- Parameters:
projects (Reverse
ManyToManyFieldfromProject) – All projects of this classifier (related name ofclassifiers)
- exception DoesNotExist
- exception MultipleObjectsReturned
- exception NotUpdated
- save(*args, **kwargs) None[source]
Overrides
django.db.models.Model.save.Override save to create any missing classifiers in our chain. For example, if we want to create this classifier:
Foo :: Bar :: Baz
But
Foo :: Bardoes not yet exist in the database, create that before creatingFoo :: Bar :: Baz. We do this so that when we filter our projects by classifier, we can filter byFoo :: BarandFoo :: Bar :: Baz.- Parameters:
args – the arguments to pass to
django.db.models.Model.savekwargs – the keyword arguments to pass to
django.db.models.Model.save
- id
Type:
AutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- name: Field
Type:
CharFieldClassifier Name. The classifier spec for this classifier, e.g. “Language :: Python”
A wrapper for a deferred-loading field. When the value is read from this
- objects = <sphinx_hosting.models.ClassifierManager object>
- projects
Type: Reverse
ManyToManyFieldfromProjectAll projects of this classifier (related name of
classifiers)Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppingsandTopping.pizzasareManyToManyDescriptorinstances.Most of the implementation is delegated to a dynamically defined manager
- class sphinx_hosting.models.Project(*args, **kwargs)[source]
Database table:
sphinxhostingcore_projectA Project is what a set of Sphinx docs describes: an application, a library, etc.
Projects have versions (
Version) and versions have Sphinx pages (SphinxPage).- Parameters:
id (AutoField) – Primary key: ID
created (CreationDateTimeField) – Created
modified (ModificationDateTimeField) – Modified
title (CharField) –
Project Name. The human name for this project
The page title
description (CharField) – Brief Description. A brief description of this project
machine_name (MachineNameField) – Machine Name. Must be unique. Set this to the slugified value of “project” in Sphinx’s. conf.py
Relationship fields:
- Parameters:
latest_version (
ForeignKeytoVersion) – Latest version. The latest version of this project. This is the version that will be shown when you click “Read Docs” on the project page. (related name:+)permission_groups (
ManyToManyFieldtoProjectPermissionGroup) – Permission groups (related name:projects)classifiers (
ManyToManyFieldtoClassifier) – Classifiers (related name:projects)
Reverse relationships:
- Parameters:
versions (Reverse
ForeignKeyfromVersion) – All versions of this project (related name ofproject)related_links (Reverse
ForeignKeyfromProjectRelatedLink) – All related links of this project (related name ofproject)
- exception DoesNotExist
- exception MultipleObjectsReturned
- exception NotUpdated
- get_absolute_url() str[source]
Return the standard URL for viewing/editing this instance of this model.
- Returns:
The update URL for this instance.
- get_next_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
Finds next instance based on
created. Seeget_next_by_FOOfor more information.
- get_next_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
Finds next instance based on
modified. Seeget_next_by_FOOfor more information.
- get_previous_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
Finds previous instance based on
created. Seeget_previous_by_FOOfor more information.
- get_previous_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
Finds previous instance based on
modified. Seeget_previous_by_FOOfor more information.
- get_update_url() str[source]
Return a URL suitable for POSTing to to update this instance of this model.
- Returns:
The update URL for this instance.
- classifiers: ManyToManyField
Type:
ManyToManyFieldtoClassifierClassifiers (related name:
projects)Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppingsandTopping.pizzasareManyToManyDescriptorinstances.Most of the implementation is delegated to a dynamically defined manager
- created
Type:
CreationDateTimeFieldCreated
A wrapper for a deferred-loading field. When the value is read from this
- description: Field
Type:
CharFieldBrief Description. A brief description of this project
A wrapper for a deferred-loading field. When the value is read from this
- id
Type:
AutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- latest_version: ForeignKey
Type:
ForeignKeytoVersionLatest version. The latest version of this project. This is the version that will be shown when you click “Read Docs” on the project page. (related name:
+)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- latest_version_id
Internal field, use
latest_versioninstead.
- machine_name: Field
Type:
MachineNameFieldMachine Name. Must be unique. Set this to the slugified value of “project” in Sphinx’s. conf.py
A wrapper for a deferred-loading field. When the value is read from this
- modified
Type:
ModificationDateTimeFieldModified
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
- permission_groups: ManyToManyField
Type:
ManyToManyFieldtoProjectPermissionGroupPermission groups (related name:
projects)Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppingsandTopping.pizzasareManyToManyDescriptorinstances.Most of the implementation is delegated to a dynamically defined manager
Type: Reverse
ForeignKeyfromProjectRelatedLinkAll related links of this project (related name of
project)Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
- title: Field
Type:
CharFieldProject Name. The human name for this project
A wrapper for a deferred-loading field. When the value is read from this
- versions
Type: Reverse
ForeignKeyfromVersionAll versions of this project (related name of
project)Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
- class sphinx_hosting.models.ProjectRelatedLink(*args, **kwargs)[source]
Database table:
sphinxhostingcore_projectrelatedlinkA
ProjectRelatedLinkis a link to an external resource that is related to aProject.- Parameters:
Relationship fields:
- Parameters:
project (
ForeignKeytoProject) – Project. The project to which this link is related (related name:related_links)
- exception DoesNotExist
- exception MultipleObjectsReturned
- exception NotUpdated
- get_next_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
Finds next instance based on
created. Seeget_next_by_FOOfor more information.
- get_next_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
Finds next instance based on
modified. Seeget_next_by_FOOfor more information.
- get_previous_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
Finds previous instance based on
created. Seeget_previous_by_FOOfor more information.
- get_previous_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
Finds previous instance based on
modified. Seeget_previous_by_FOOfor more information.
- created
Type:
CreationDateTimeFieldCreated
A wrapper for a deferred-loading field. When the value is read from this
- id
Type:
AutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- modified
Type:
ModificationDateTimeFieldModified
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
- project: ForeignKey
Type:
ForeignKeytoProjectProject. The project to which this link is related (related name:
related_links)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- class sphinx_hosting.models.Version(*args, **kwargs)[source]
Database table:
sphinxhostingcore_versionA
Versionis a specific version of aProject. Versions ownSphinxPageobjects.- Parameters:
id (AutoField) – Primary key: ID
created (CreationDateTimeField) – Created
modified (ModificationDateTimeField) – Modified
version (CharField) –
Version. The version number for this release of the Project
The
Versionthat this tree examinessphinx_version (CharField) – Sphinx Version. The version of Sphinx used to create this documentation set
archived (BooleanField) – Archived?. Whether this version should be excluded from search indexes
Relationship fields:
- Parameters:
project (
ForeignKeytoProject) – Project. The Project to which this Version belongs (related name:versions)head (
OneToOneFieldtoSphinxPage) –Head. The top page of the documentation set for this version of our project (related name:
+)The top page in the page hierarchy
Reverse relationships:
- Parameters:
pages (Reverse
ForeignKeyfromSphinxPage) – All pages of this version (related name ofversion)images (Reverse
ForeignKeyfromSphinxImage) – All images of this version (related name ofversion)documents (Reverse
ForeignKeyfromSphinxDocument) – All documents of this version (related name ofversion)
- exception DoesNotExist
- exception MultipleObjectsReturned
- exception NotUpdated
- get_next_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
Finds next instance based on
created. Seeget_next_by_FOOfor more information.
- get_next_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
Finds next instance based on
modified. Seeget_next_by_FOOfor more information.
- get_previous_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
Finds previous instance based on
created. Seeget_previous_by_FOOfor more information.
- get_previous_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
Finds previous instance based on
modified. Seeget_previous_by_FOOfor more information.
- mark_searchable_pages() None[source]
Set the
SphinxPage.searchableflag on the searchable pages in this version.Searchable pages are ones that:
Are not in
SphinxPage.SPECIAL_PAGESDo not have a part of their relative path that starts with
_.
Go through the pages in this version, and set
SphinxPage.searchabletoTruefor all those which meet the above requirements,Falseotherwise.
- save(*args, **kwargs)[source]
Overriding
django.db.models.Model.savehere so that we can purge our cached global table of contents.
- archived: Field
Type:
BooleanFieldArchived?. Whether this version should be excluded from search indexes
A wrapper for a deferred-loading field. When the value is read from this
- created
Type:
CreationDateTimeFieldCreated
A wrapper for a deferred-loading field. When the value is read from this
- documents
Type: Reverse
ForeignKeyfromSphinxDocumentAll documents of this version (related name of
version)Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
- globaltoc
Build a struct that looks like this:
{ items: [ {'text': 'foo'}, {'text': 'bar', 'url': '/foo', 'icon': None} {'text': 'bar', 'url': '/foo', 'icon': None, items: [{'text': 'blah' ...} ...]} ... ] }
suitable for constructing a
sphinx_hosting.wildewidgets.SphinxPageGlobalTableOfContentsMenu
- head: ForeignKey
Type:
OneToOneFieldtoSphinxPageHead. The top page of the documentation set for this version of our project (related name:
+)Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
- id
Type:
AutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- images
Type: Reverse
ForeignKeyfromSphinxImageAll images of this version (related name of
version)Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
- modified
Type:
ModificationDateTimeFieldModified
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
- property page_tree: SphinxPageTree
Return the page hierarchy for the set of
SphinxPagepages in this version.The page hierarchy is build by traversing the pages in the set, starting with
head.- Returns:
The page hierarchy for this version.
- pages
Type: Reverse
ForeignKeyfromSphinxPageAll pages of this version (related name of
version)Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
- project: ForeignKey
Type:
ForeignKeytoProjectProject. The Project to which this Version belongs (related name:
versions)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- class sphinx_hosting.models.SphinxPage(*args, **kwargs)[source]
Database table:
sphinxhostingcore_sphinxpageA
SphinxPageis a single page of a set of Sphinx documentation.SphinxPageobjects are owned byVersionobjects, which are in turn owned byProjectobjects.- Parameters:
id (AutoField) – Primary key: ID
created (CreationDateTimeField) – Created
modified (ModificationDateTimeField) – Modified
relative_path (CharField) – Relative page path. The path to the page under our top slug
content (TextField) – Content. The full JSON payload for the page
title (CharField) –
Title. Just the title for the page, extracted from the page JSON
The page title
orig_body (TextField) – Body (Original). The original body for the page, extracted from the page JSON. Some pages have no body. We save this here in case we need to reprocess the body at some later date.
body (TextField) – Body. The body for the page, extracted from the page JSON, and modified to suit us. Some pages have no body. The body is actually stored as a Django template.
orig_local_toc (TextField) – Local Table of Contents (original). The original table of contents for headings in this page.We save this here in case we need to reprocess the table of contents at some later date.
local_toc (TextField) – Local Table of Contents. Table of Contents for headings in this page, modified to work in our templates
orig_global_toc (TextField) – Global Table of Contents (original). The original global table of contents HTML attached to this page, if any. This will only be present if you had “sphinxcontrib-jsonglobaltoc”installed in your “extensions” in the Sphinx conf.py
searchable (BooleanField) – Searchable. Should this page be included in the search index?
Relationship fields:
- Parameters:
version (
ForeignKeytoVersion) –Version. The Version to which this page belongs (related name:
pages)The
Versionthat this tree examinesparent (
ForeignKeytoSphinxPage) –Parent. The parent page of this page (related name:
children)The
SphinxPagethat is this page’s parentnext_page (
ForeignKeytoSphinxPage) – Next page. The next page in the documentation set (related name:previous_page)
Reverse relationships:
- Parameters:
children (Reverse
ForeignKeyfromSphinxPage) –All children of this sphinx page (related name of
parent)The
TreeNodeobjects that are this page’s childrenprevious_page (Reverse
ForeignKeyfromSphinxPage) – All previous page of this sphinx page (related name ofnext_page)
- exception DoesNotExist
- exception MultipleObjectsReturned
- exception NotUpdated
- get_next_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
Finds next instance based on
created. Seeget_next_by_FOOfor more information.
- get_next_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
Finds next instance based on
modified. Seeget_next_by_FOOfor more information.
- get_permalink() str[source]
Return the permalink for this page. This is the URL for the page with the version number replaced with “latest”.
- Returns:
The permalink for this page.
- get_previous_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
Finds previous instance based on
created. Seeget_previous_by_FOOfor more information.
- get_previous_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
Finds previous instance based on
modified. Seeget_previous_by_FOOfor more information.
- SPECIAL_PAGES: Final[Dict[str, str]] = {'_modules/index': 'Module code', 'genindex': 'General Index', 'np-modindex': 'Module Index', 'py-modindex': 'Module Index', 'search': 'Search'}
This is a mapping between filename and title that identifies the special pages that Sphinx produces on its own and gives them reasonable titles. These pages have no
titlekey in their
- body: Field
Type:
TextFieldBody. The body for the page, extracted from the page JSON, and modified to suit us. Some pages have no body. The body is actually stored as a Django template.
A wrapper for a deferred-loading field. When the value is read from this
- children
Type: Reverse
ForeignKeyfromSphinxPageAll children of this sphinx page (related name of
parent)Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
- content: Field
Type:
TextFieldContent. The full JSON payload for the page
A wrapper for a deferred-loading field. When the value is read from this
- created
Type:
CreationDateTimeFieldCreated
A wrapper for a deferred-loading field. When the value is read from this
- id
Type:
AutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- local_toc: Field
Type:
TextFieldLocal Table of Contents. Table of Contents for headings in this page, modified to work in our templates
A wrapper for a deferred-loading field. When the value is read from this
- modified
Type:
ModificationDateTimeFieldModified
A wrapper for a deferred-loading field. When the value is read from this
- next_page: ForeignKey
Type:
ForeignKeytoSphinxPageNext page. The next page in the documentation set (related name:
previous_page)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- objects = <django.db.models.Manager object>
- orig_body: Field
Type:
TextFieldBody (Original). The original body for the page, extracted from the page JSON. Some pages have no body. We save this here in case we need to reprocess the body at some later date.
A wrapper for a deferred-loading field. When the value is read from this
- orig_global_toc: Field
Type:
TextFieldGlobal Table of Contents (original). The original global table of contents HTML attached to this page, if any. This will only be present if you had “sphinxcontrib-jsonglobaltoc”installed in your “extensions” in the Sphinx conf.py
A wrapper for a deferred-loading field. When the value is read from this
- orig_local_toc: Field
Type:
TextFieldLocal Table of Contents (original). The original table of contents for headings in this page.We save this here in case we need to reprocess the table of contents at some later date.
A wrapper for a deferred-loading field. When the value is read from this
- parent: ForeignKey
Type:
ForeignKeytoSphinxPageParent. The parent page of this page (related name:
children)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- previous_page
Type: Reverse
ForeignKeyfromSphinxPageAll previous page of this sphinx page (related name of
next_page)Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager
- relative_path: Field
Type:
CharFieldRelative page path. The path to the page under our top slug
A wrapper for a deferred-loading field. When the value is read from this
- searchable: Field
Type:
BooleanFieldSearchable. Should this page be included in the search index?
A wrapper for a deferred-loading field. When the value is read from this
- title: Field
Type:
CharFieldTitle. Just the title for the page, extracted from the page JSON
A wrapper for a deferred-loading field. When the value is read from this
- version: ForeignKey
Type:
ForeignKeytoVersionVersion. The Version to which this page belongs (related name:
pages)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
- class sphinx_hosting.models.SphinxImage(*args, **kwargs)[source]
Database table:
sphinxhostingcore_sphinximageA
SphinxImageis an image file referenced in a Sphinx document. When importing documenation packages, we extract all images from the package, upload them into Django storage and update the Sphinx HTML inSphinxPage.bodyto reference the URL for the uploaded image instead of its original url.- Parameters:
Relationship fields:
- Parameters:
version (
ForeignKeytoVersion) –Version. The version of our project documentation with which this image is associated (related name:
images)The
Versionthat this tree examines
- exception DoesNotExist
- exception MultipleObjectsReturned
- exception NotUpdated
- get_next_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
Finds next instance based on
created. Seeget_next_by_FOOfor more information.
- get_next_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
Finds next instance based on
modified. Seeget_next_by_FOOfor more information.
- get_previous_by_created(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
Finds previous instance based on
created. Seeget_previous_by_FOOfor more information.
- get_previous_by_modified(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
Finds previous instance based on
modified. Seeget_previous_by_FOOfor more information.
- created
Type:
CreationDateTimeFieldCreated
A wrapper for a deferred-loading field. When the value is read from this
- file: Field
Type:
FileFieldAn image file. The actual image file
The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:
>>> from myapp.models import MyModel >>> instance = MyModel.objects.get(pk=1) >>> instance.file.size
Assign a file object on assignment so you can do:
>>> with open('/path/to/hello.world') as f:
- id
Type:
AutoFieldPrimary key: ID
A wrapper for a deferred-loading field. When the value is read from this
- modified
Type:
ModificationDateTimeFieldModified
A wrapper for a deferred-loading field. When the value is read from this
- objects = <django.db.models.Manager object>
- orig_path: Field
Type:
CharFieldOriginal Path. The original path to this file in the Sphinx documentation package
A wrapper for a deferred-loading field. When the value is read from this
- version: ForeignKey
Type:
ForeignKeytoVersionVersion. The version of our project documentation with which this image is associated (related name:
images)Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Utility functions
- sphinx_hosting.models.sphinx_image_upload_to(instance: SphinxImage, filename: str) str[source]
Set the upload path within our
MEDIA_ROOTfor any images used by our Sphinx documentation to be:{project machine_name}/{version}/images/{image basename}
- Parameters:
instance – the
SphinxImageobjectfilename – the original path to the file
- Returns:
The properly formatted path to the file
Utility classes used by models
- class sphinx_hosting.models.SphinxPageTree(version: Version)[source]
A class that holds the page hierarchy for the set of
SphinxPagepages in aVersion.as a linked set ofTreeNodeobjects.The page heirarchy is built by starting at
Version.headand following the page linkages by looking atSphinxPage.next_page, stopping the traversal when we find aSphinxPage.next_pagethat isNone.As we traverse, if a
SphinxPage.parentis notNone, find theTreeNodefor that parent, and add the page toTreeNode.children.For pages who have no
SpinxPage.parent, assume they are top level children of the set, and make them children ofVersion.head.Load it like so:
>>> project = Project.objects.get(machine_name='my-project') >>> version = project.versions.get(version='1.0.0') >>> tree = SphinxPageTree(version)
You can then traverse the built hierarchy by starting at
SphinxPageTree.head, looking at its children, then looking at their children, etc..- Parameters:
version – the
Versionto build the tree for
- traverse() list[sphinx_hosting.models.SphinxPage][source]
Return a list of the pages represented in this tree.
- class sphinx_hosting.models.SphinxPageTreeProcessor[source]
- build(items: List[Dict[str, Any]], node: TreeNode) None[source]
Build a
wildewdigets.MenuItemcompatible dict representingnode, and append it toitems.if
nodehas children, recurse into those children, building out our submenus.- Parameters:
items – the current list of
MenuItemcompatible dicts for the current level of the menunode – the current node in our page tree
- build_item(node: TreeNode) Dict[str, Any][source]
Build a
wildewdigets.MenuItemcompatible dict representingnode.- Parameters:
node – the current node in our page tree
- Returns:
A dict suitable for loading into a
wildewidgets.MenuItem.
- run(version: Version) List[Dict[str, Any]][source]
Parse the
Version.page_treeand return a struct that works withsphinx_hosting.wildewidgets.SphinxPageGlobalTableOfContentsMenu.parse_objThe returned struct should look something like this:
[ {'text': 'foo'}, {'text': 'bar', 'url': '/foo', 'icon': None} {'text': 'bar', 'url': '/foo', 'icon': None, items: [{'text': 'blah' ...} ...]} ... ]
- Parameters:
version – the version whose global table of contents we are parsing
- Returns:
A list of dicts representing the global menu structure
- class sphinx_hosting.models.SphinxGlobalTOCHTMLProcessor(max_level: int = 2)[source]
Usage:
SphinxGlobalTOCHTMLProcessor().run(version, globaltoc_html)`This importer is used to parse the
globaltockey in JSON output of Sphinx pages built with the sphinxcontrib-jsonglobaltoc extension.Sphinx uses your
.. toctree:declarations in your.rstfiles to build site navigation for your document tree, andsphinxcontrib-jsonglobaltocsaves the Sphinx HTML produced by those..toctreeas theglobaltockey in the .fjson output.Note
Sphinx
.. toctree:are ad-hoc – they’re up to how the author wants to organize their content, and may not reflect how files are filled out in the filesystem.- parse_globaltoc(html: HtmlElement) List[Dict[str, Any]][source]
Parse our global table of contents HTML blob and return a list of
sphinx_hosting.wildewidgets.MenuItemobjects.Add a first node that points to the root doc, also. The root doc can’t add itself to its
toctreeblocks, so we need to do it ourselves.How our mapping works:
Multiple top level
<ul>tags separated by<p class="caption">tags will be merged into a single list.<p class="caption ...">CONTENTS</p>becomes{'text': 'CONTENTS'}`Any
hrefwill be converted to its fulldjango-sphinx-hostingpath
- Parameters:
version – the version whose global table of contents we are parsing
html – the lxml parsed HTML of the global table of contents from Sphinx
- parse_ul(html: HtmlElement, level: int = 1) List[Dict[str, Any]][source]
Process
html, anlxmlparsed set of elements representing the contents of a<ul>from a Sphinx table of contents and return a list ofsphinx_hosting.wildewidgets.MenuItemobjects.Any
hrefin links found will be converted to its fulldjango-sphinx-hostingpath.If we find another
<ul>insidehtml, process it by passing its contents toparse_ulagain, incrementing the menu level.If
levelis greater thanmax_level, return an empty list, stopping our recursion.- Parameters:
html – the list of elements that are the contents of the parent
<ul>- Keyword Arguments:
level – the current menu level
- Returns:
The
<ul>contents as a list of dicts
- run(version: Version, verbose: bool = False) List[Dict[str, Any]][source]
Parse the global table of contents found as
version.head.orig_global_tocinto a data struct suitable for use withsphinx_hosting.wildewidgets.SphinxPageGlobalTableOfContentsMenu.parse_objand return it.How our mapping works:
Multiple top level
<ul>tags separated by<p class="caption">tags will be merged into a single list.<p class="caption ...">CONTENTS</p>becomes{'text': 'CONTENTS'}`Any
hreffor links found will be converted to its fulldjango-sphinx-hostingpath
The returned struct should look something like this:
[ {'text': 'foo'}, {'text': 'bar', 'url': '/project/version/foo', 'icon': None} {'text': 'bar', 'url': '/project/version/bar', 'icon': None, items: [{'text': 'blah' ...} ...]} ... ]
- Parameters:
version – the version whose global table of contents we are parsing
- Keyword Arguments:
verbose – if
True, pretty print the HTML of the globaltoc- Returns:
A list of dicts representing the global menu structure
- class sphinx_hosting.models.TreeNode(title: str, page: ~sphinx_hosting.models.SphinxPage | None = None, prev: ~sphinx_hosting.models.SphinxPage | None = None, next: ~sphinx_hosting.models.SphinxPage | None = None, parent: ~sphinx_hosting.models.SphinxPage | None = None, children: list[sphinx_hosting.models.TreeNode] = <factory>)[source]
A
dataclassthat we use withSphinxPageTreeto build out the global navigation structure for a set of documentation for aVersion.- __init__(title: str, page: ~sphinx_hosting.models.SphinxPage | None = None, prev: ~sphinx_hosting.models.SphinxPage | None = None, next: ~sphinx_hosting.models.SphinxPage | None = None, parent: ~sphinx_hosting.models.SphinxPage | None = None, children: list[sphinx_hosting.models.TreeNode] = <factory>) None
- classmethod from_page(page: SphinxPage) TreeNode[source]
Build a
TreeNodefrompage.Note
This does not populate
children;SphinxPageTreewill populate it as appropriate as it ingests pages.- Parameters:
page – the
SphinxPagefrom which to build a node- Returns:
A configured node.
- children: list[sphinx_hosting.models.TreeNode]
- next: SphinxPage | None = None
- page: SphinxPage | None = None
- parent: SphinxPage | None = None
- prev: SphinxPage | None = None