Django administration interface for projects.models

class readthedocs.projects.admin.ImportedFileAdmin(model, admin_site)

Admin view for ImportedFile

class readthedocs.projects.admin.ProjectAdmin(model, admin_site)

Project model admin view

class readthedocs.projects.admin.ProjectRelationshipInline(parent_model, admin_site)

Project inline relationship view for ProjectAdmin


alias of ProjectRelationship

class readthedocs.projects.admin.RedirectInline(parent_model, admin_site)

Redirect inline relationship view for ProjectAdmin


alias of Redirect

class readthedocs.projects.admin.VersionInline(parent_model, admin_site)

Version inline relationship view for ProjectAdmin


alias of Version


Project constants

Default values and other various configuration for projects, including available theme names and repository types.


Project forms

class readthedocs.projects.forms.BaseVersionsForm(data=None, files=None, auto_id=u'id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None)

Form for versions page


Save version if there has been a change, trigger a rebuild

class readthedocs.projects.forms.DualCheckboxWidget(version, attrs=None, check_test=<type 'bool'>)

Checkbox with link to the version’s built documentation

class readthedocs.projects.forms.EmailHookForm(*args, **kwargs)

Project email notification form

class readthedocs.projects.forms.ProjectAdvancedForm(*args, **kwargs)

Advanced project option form

class readthedocs.projects.forms.ProjectAdvertisingForm(*args, **kwargs)

Project promotion opt-out form

class readthedocs.projects.forms.ProjectBackendForm(data=None, files=None, auto_id=u'id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None)

Get the import backend

class readthedocs.projects.forms.ProjectBasicsForm(*args, **kwargs)

Form for basic project fields

class readthedocs.projects.forms.ProjectExtraForm(*args, **kwargs)

Additional project information form

class readthedocs.projects.forms.ProjectForm(*args, **kwargs)

Project form

Parameters:user – If provided, add this user as a project user on save
class readthedocs.projects.forms.ProjectTriggerBuildMixin

Mixin to trigger build on form save

This should be replaced with signals instead of calling trigger_build explicitly.


Trigger build on commit save

class readthedocs.projects.forms.RedirectForm(*args, **kwargs)

Form for project redirects

class readthedocs.projects.forms.SubprojectForm(*args, **kwargs)

Project subproject form


Normalize subproject field

Does lookup on against Project to ensure matching project exists. Return the Project object instead.

class readthedocs.projects.forms.TranslationForm(*args, **kwargs)

Project translation form

class readthedocs.projects.forms.UserForm(*args, **kwargs)

Project user association form

class readthedocs.projects.forms.WebHookForm(*args, **kwargs)

Project webhook form


Upload HTML form with list of versions to upload HTML for


Versions form with a list of versions and version privacy levels


Project models

class readthedocs.projects.models.Domain(id, project, domain, machine, cname, canonical, https, count)
class readthedocs.projects.models.EmailHook(id, project, email)
class readthedocs.projects.models.ImportedFile(*args, **kwargs)

Imported files model

This tracks files that are output from documentation builds, useful for things like CDN invalidation.

class readthedocs.projects.models.Project(*args, **kwargs)

Project model

add_comment(version_slug, page, content_hash, commit, user, text)

Add comment to node

  • version_slug – Version slug to use for node lookup
  • page – Page to attach comment to
  • content_hash – Hash of content to apply comment to
  • commit – Commit that updated comment
  • userUser instance that created comment
  • text – Comment text
add_node(content_hash, page, version, commit)

Add comment node

  • content_hash – Hash of node content
  • page – Doc page for node
  • version (str) – Slug for project version to apply node to
  • commit (str) – Commit that node was updated in

Get queryset with all active versions


This is a temporary workaround for activate_versions filtering out things that were active, but failed to build

Returns:Version queryset
artifact_path(type_, version='latest')

The path to the build html docs in the project


Find a file in the project checkout

find(filename, version)

Find files inside the project’s doc path

  • filename – Filename to search for in project checkout
  • version – Version instance to set version checkout path

The path to the build html docs in the project


The path to the build dash docs in the project


The path to the documentation root in the project


The path to the build epub docs in the project

full_find(filename, version)

Find files inside a project’s checkout path

  • filename – Filename to search for in project checkout
  • version – Version instance to set version checkout path

The path to the build json docs in the project


The path to the build LaTeX docs in the project


The path to the build man docs in the project


The path to the build singlehtml docs in the project


Get the version representing ‘latest’


Get the default version (slug).

Returns self.default_version if the version with that slug actually exists (is built and published). Otherwise returns ‘latest’.

get_docs_url(version_slug=None, lang_slug=None, private=None)

Return a url for the docs

Always use http for now, to avoid content warnings.


Get latest build for project

Return only builds that are in a finished state
get_production_media_path(type_, version_slug, include_file=True)

This is used to see if these files exist so we can offer them for download.

  • type – Media content type, ie - ‘pdf’, ‘zip’
  • version_slug – Project version slug for lookup
  • include_file (bool) – Include file name in return

Full path to media file or path

get_production_media_url(type_, version_slug, full_path=True)

Get the URL for downloading a specific media file.


List subproject URLs

This is used in search result linking


Is project type Mkdocs


Is project type Sphinx


Path to pip cache


The destination path where the built docs are copied


The path to the static metadata JSON settings file


Get project subdomain from resolver


Get the list of supported versions

Returns:List of version strings.

Path in the doc_path that we symlink translations


Returns the version that was promoted to be the new stable version

Return None if no update was mode or if there is no version on the project that can be considered stable.

class readthedocs.projects.models.ProjectRelationship(*args, **kwargs)

Project to project relationship

This is used for subprojects

class readthedocs.projects.models.WebHook(id, project, url)


Project search indexes

Deprecated since version Read: the Docs no longer uses Haystack in production and the core team does not maintain this code. Use at your own risk, this may go away soon.

class readthedocs.projects.search_indexes.ImportedFileIndex

Search index for imported files


Used when the entire index for model is updated


Prepare the text of the html file

This only works on machines that have the html files for the projects checked out.

class readthedocs.projects.search_indexes.ProjectIndex

Project search index


Used when the entire index for model is updated


Tasks related to projects

This includes fetching repository code, cleaning files, and rebuilding documentation.

class readthedocs.projects.tasks.UpdateDocsTask(build_env=None, python_env=None, config=None, force=False, search=True, localmedia=True, build=None, project=None, version=None)

The main entry point for updating documentation.

It handles all of the logic around whether a project is imported or we created it. Then it will build the html docs and other requested parts.

Primary key of the project to update
Whether or not to keep a record of the update in the database. Useful for preventing changes visible to the end-user when running commands from the shell, for example.

Wrapper to all build functions

Executes the necessary builds for this task and returns whether the build was successful or not.

Returns:Build outcomes with keys for html, search, localmedia, pdf, and epub
Return type:dict

Build docs with additional doc backends

These steps are not necessarily required for the build to halt, so we only raise a warning exception here. A hard error will halt the build process.


Build ePub docs


Build HTML docs


Get local media files with separate build


Build PDF docs

Build search data with separate build

static get_build(build_pk)

Retrieve build object from API

Parameters:build_pk – Build primary key

Get bash environment variables used for all builder commands.

static get_project(project_pk)

Get project from API

static get_version(project, version_pk)

Ensure we’re using a sane version


Send notifications on build failure


Mark on the project that it has been cloned properly.


Build the virtualenv and install the project into it.

Always build projects with a virtualenv.

Parameters:build_env – Build environment to pass commands and execution through.

Update the checkout of the repo to make sure it’s the latest.

This also syncs versions in the DB.

Parameters:build_env – Build environment

Force Sphinx for ‘auto’ documentation type

This used to determine the type and automatically set the documentation type to Sphinx for rST and Mkdocs for markdown. It now just forces Sphinx, due to markdown support.

readthedocs.projects.tasks.email_notification(version, build, email)

Send email notifications for build failure

  • versionVersion instance that failed
  • buildBuild instance that failed
  • email – Email recipient address
readthedocs.projects.tasks.webhook_notification(version, build, hook_url)

Send webhook notification for project webhook

  • version – Version instance to send hook for
  • build – Build instance that failed
  • hook_url – Hook URL to send to


Utility functions used by projects


Recursively find matching file from the current working path

Parameters:file – Filename to match
Returns:A list of matching filenames.

Make mock Project instance from API return


Make mock Version instance from API return*commands, **kwargs)

Run one or more commands

If more than one command is given, then this is equivalent to chaining them together with &&; if all commands succeed, then (status, out, err) will represent the last successful command. If one command failed, then (status, out, err) will represent the failed command.

Returns:(status, out, err)
readthedocs.projects.utils.safe_write(filename, contents)

Normalize and write to filename

Write contents to the given filename. If the filename’s directory does not exist, it is created. Contents are written as UTF-8, ignoring any characters that cannot be encoded as UTF-8.

  • filename – Filename to write to
  • contents – File contents to write to file

This is here to avoid circular imports in



Public project views

class readthedocs.projects.views.public.ProjectDetailView(**kwargs)

Display project onboard steps


alias of Project

class readthedocs.projects.views.public.ProjectIndex(**kwargs)

List view of public Project instances


alias of Project

Use elastic search to search in a project

readthedocs.projects.views.public.file_autocomplete(request, project_slug)

Return a json list of file names

readthedocs.projects.views.public.project_analytics(request, project_slug)

Have a analytics API placeholder

readthedocs.projects.views.public.project_badge(request, *args, **kw)

Return a sweet badge for the project

readthedocs.projects.views.public.project_download_media(request, project_slug, type_, version_slug)

Download a specific piece of media.

Perform an auth check if serving in private mode.


This is linked directly from the HTML pages. It should only care about the Version permissions, not the actual Project permissions.

readthedocs.projects.views.public.project_downloads(request, project_slug)

A detail view for a project with various dataz

readthedocs.projects.views.public.project_embed(request, project_slug)

Have a content API placeholder

readthedocs.projects.views.public.project_index(request, *args, **kwargs)

List view of public Project instances

readthedocs.projects.views.public.project_versions(request, project_slug)

Project version list view

Shows the available versions and lets the user choose which ones to build.


Return a json list of project names

readthedocs.projects.views.public.version_autocomplete(request, project_slug)

Return a json list of version names


Project views for authenticated users

class readthedocs.projects.views.private.ImportDemoView(**kwargs)

View to pass request on to import form to import demo project


alias of ProjectBasicsForm

get(request, *args, **kwargs)

Process link request as a form post to the project import form


Get form data to post to import form


Form kwargs passed in during instantiation

class readthedocs.projects.views.private.ImportView(**kwargs)

On GET, show the source an import view, on POST, mock out a wizard

If we are accepting POST data, use the fields to seed the initial data in ImportWizardView. The import templates will redirect the form to /dashboard/import

get(request, *args, **kwargs)

Display list of repositories to import

Adds a warning to the listing if any of the accounts connected for the user are not supported accounts.


alias of ImportWizardView

class readthedocs.projects.views.private.ImportWizardView(**kwargs)

Project import wizard

done(form_list, **kwargs)

Save form data as object instance

Don’t save form data directly, instead bypass documentation building and other side effects for now, by signalling a save without commit. Then, finish by added the members to the project and saving.


Get args to pass into form instantiation


Return template names based on step name


Determine if the user selected the show advanced field

class readthedocs.projects.views.private.IntegrationExchangeMixin

Project webhook exchange mixin for listing exchange objects


alias of HttpExchange

class readthedocs.projects.views.private.IntegrationMixin

Project external service mixin for listing webhook objects

This mixin will be used more once we have modeling around webhooks and external integrations.

class readthedocs.projects.views.private.IntegrationWebhookSync(**kwargs)

Resync a project webhook

The signal will add a success/failure message on the request.

class readthedocs.projects.views.private.ProjectDashboard(**kwargs)

Project dashboard


alias of Project

readthedocs.projects.views.private.edit_alias(request, *args, **kwargs)

Edit project alias form view

readthedocs.projects.views.private.project_delete(request, *args, **kwargs)

Project delete confirmation view

Make a project as deleted on POST, otherwise show a form asking for confirmation of delete.

readthedocs.projects.views.private.project_manage(request, *args, **kwargs)

Project management view

Where you will have links to edit the projects’ configuration, edit the files associated with that project, etc.

Now redirects to the normal /projects/<slug> view.

readthedocs.projects.views.private.project_notifications(request, *args, **kwargs)

Project notification view and form view

readthedocs.projects.views.private.project_notifications_delete(request, *args, **kwargs)

Project notifications delete confirmation view

readthedocs.projects.views.private.project_redirects(request, *args, **kwargs)

Project redirects view and form view

readthedocs.projects.views.private.project_redirects_delete(request, *args, **kwargs)

Project redirect delete view

readthedocs.projects.views.private.project_subprojects(request, *args, **kwargs)

Project subprojects view and form view

readthedocs.projects.views.private.project_translations(request, *args, **kwargs)

Project translations view and form view

readthedocs.projects.views.private.project_users(request, *args, **kwargs)

Project users view and form view

readthedocs.projects.views.private.project_version_delete_html(request, *args, **kwargs)

Project version ‘delete’ HTML

This marks a version as not built

readthedocs.projects.views.private.project_version_detail(request, *args, **kwargs)

Project version detail page

readthedocs.projects.views.private.project_versions(request, *args, **kwargs)

Project versions view

Shows the available versions and lets the user choose which ones he would like to have built.