Django administration interface for projects.models

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

alias of readthedocs.projects.models.Domain

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

alias of readthedocs.projects.models.Domain

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

alias of readthedocs.projects.forms.FeatureForm


alias of readthedocs.projects.models.Feature

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

Admin view for ImportedFile

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

Project model admin view.

ban_owner(request, queryset)

Ban project owner.

This will only ban single owners, because a malicious user could add a user as a co-owner of the project. We don’t want to induce and collatoral damage when flagging users.

delete_selected_and_artifacts(request, queryset)

Remove HTML/etc artifacts from application instances.

Prior to the query delete, broadcast tasks to delete HTML artifacts from application instances.


Return a dictionary mapping the names of all actions for this ModelAdmin to a tuple of (callable, name, description) for each action.

class readthedocs.projects.admin.ProjectOwnerBannedFilter(request, params, model, model_admin)

Filter for projects with banned owners.

There are problems adding users__profile__banned to the list_filter attribute, so we’ll create a basic filter to capture banned owners.

lookups(request, model_admin)

Must be overridden to return a list of tuples (value, verbose value)

queryset(request, queryset)

Returns the filtered queryset.

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

Project inline relationship view for ProjectAdmin


alias of readthedocs.projects.models.ProjectRelationship

class readthedocs.projects.admin.ProjectSendNotificationView(**kwargs)

Iterate over queryset objects and return User objects.

This allows for non-User querysets to pass back a list of Users to send to. By default, assume we’re working with User objects and just yield the single object.

For example, this could be made to return project owners with:

for owner in project.users.all():
    yield owner
Parameters:obj – object from queryset, type is dependent on model class
Return type:django.contrib.auth.models.User
class readthedocs.projects.admin.RedirectInline(parent_model, admin_site)

Redirect inline relationship view for ProjectAdmin


alias of readthedocs.redirects.models.Redirect

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

Version inline relationship view for ProjectAdmin


alias of readthedocs.builds.models.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.DomainForm(*args, **kwargs)

Form to configure a custom domain name for a project.

class Meta

alias of readthedocs.projects.models.Domain

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.FeatureForm(*args, **kwargs)

Project feature form for dynamic admin choices.

This form converts the CharField into a ChoiceField on display. The underlying driver won’t attempt to do validation on the choices, and so we can dynamically populate this list.

class Meta

alias of readthedocs.projects.models.Feature

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

Form to add an integration.

This limits the choices of the integration type to webhook integration types

class Meta

alias of readthedocs.integrations.models.Integration

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

Advanced project option form.

class Meta

alias of readthedocs.projects.models.Project

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

Project promotion opt-out form.

class Meta

alias of readthedocs.projects.models.Project

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 Meta

alias of readthedocs.projects.models.Project


Add remote repository relationship to the project instance.

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

Additional project information form.

class Meta

alias of readthedocs.projects.models.Project

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.ProjectRelationshipForm(*args, **kwargs)

Form to add/update project relationships.

class Meta

alias of readthedocs.projects.models.ProjectRelationship


Return scrubbed subproject choice queryset.

This removes projects that are either already a subproject of another project, or are a superproject, as neither case is supported.

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 Meta

alias of readthedocs.redirects.models.Redirect

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.APIProject(*args, **kwargs)

Project proxy model for API data deserialization.

This replaces the pattern where API data was deserialized into a mocked :py:cls:`Project` object. This pattern was confusing, as it was not explicit as to what form of object you were working with – API backed or database backed.

This model preserves the Project model methods, allowing for overrides on model field differences. This model pattern will generally only be used on builder instances, where we are interacting solely with API data.

exception DoesNotExist
exception MultipleObjectsReturned
class readthedocs.projects.models.Domain(*args, **kwargs)

A custom domain name for a project.

exception DoesNotExist
exception MultipleObjectsReturned
class readthedocs.projects.models.EmailHook(id, project, email)
exception DoesNotExist
exception MultipleObjectsReturned
class readthedocs.projects.models.Feature(*args, **kwargs)

Project feature flags.

Features should generally be added here as choices, however features may also be added dynamically from a signal in other packages. Features can be added by external packages with the use of signals:

@receiver(pre_init, sender=Feature)
def add_features(sender, **kwargs):
    sender.FEATURES += (('blah', 'BLAH'),)

The FeatureForm will grab the updated list on instantiation.

exception DoesNotExist
exception MultipleObjectsReturned

Implement display name field for fake ChoiceField.

Because the field is not a ChoiceField here, we need to manually implement this behavior.

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.

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

Project model.

exception DoesNotExist
exception MultipleObjectsReturned
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_feature_value(feature, positive, negative)

Look up project feature, return corresponding value.

If a project has a feature, return positive, otherwise return negative


Get latest build for project.

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

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


Does project have existing feature flag.

If the feature has a historical True value before the feature was added, we consider the project to have the flag. This is used for deprecating a feature or changing behavior for new projects


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.

vcs_repo(version='latest', environment=None)

Return a Backend object for this project able to handle VCS commands.

  • environment (doc_builder.environments.BuildEnvironment) – environment to run the commands
  • version (str) – version slug for the backend (LATEST by default)
class readthedocs.projects.models.ProjectRelationship(*args, **kwargs)

Project to project relationship.

This is used for subprojects

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


Project search indexes.

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.SyncRepositoryMixin

Mixin that handles the VCS sync/update.

static get_version(version_pk=None)

Retrieve version data from the API.


a data-complete version object

Return type:



Update the project’s repository and hit sync_versions API.

class readthedocs.projects.tasks.SyncRepositoryTask

Entry point to synchronize the VCS documentation.


Run the VCS synchronization.

Parameters:version_pk (int) – version pk to sync
Returns:whether or not the task ended successfully
Return type:bool
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, we created it or a webhook is received. Then it will sync the repository and build the html docs if needed.


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()

Retrieve build object from API.

Parameters:build_pk – Build primary key

Get bash environment variables used for all builder commands.

static get_project()

Get project from API.

run(pk, version_pk=None, build_pk=None, record=True, docker=False, search=True, force=False, localmedia=True, **__)

Run a documentation sync n’ build.

This is fully wrapped in exception handling to account for a number of failure cases. We first run a few commands in a local build environment, but do not report on environment success. This avoids a flicker on the build output page where the build is marked as finished in between the local environment steps and the docker build steps.

If a failure is raised, or the build is not successful, return False, otherwise, True.

Unhandled exceptions raise a generic user facing error, which directs the user to bug us. It is therefore a benefit to have as few unhandled errors as possible.

  • int (build_pk) – Project id
  • int – Project Version id (latest if None)
  • int – Build id (if None, commands are not recorded)
  • bool (localmedia) – record a build object in the database
  • bool – use docker to build the project
  • bool – update search
  • bool – force Sphinx build
  • bool – update localmedia

whether build was successful or not

Return type:


run_build(docker=False, record=True)

Build the docs in an environment.

If docker is True, or Docker is enabled by the settings.DOCKER_ENABLE setting, then build in a Docker environment. Otherwise build locally.


Run setup in the local environment.

Return True if successful.


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
update_app_instances(html=False, localmedia=False, search=False, pdf=False, epub=False)

Update application instances with build artifacts.

This triggers updates across application instances for html, pdf, epub, downloads, and search. Tasks are broadcast to all web servers from here.


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.

class readthedocs.projects.utils.DictObj

Recursively find matching file from the current working path.

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

Run one or more commands.

Each argument in commands can be passed as a string or as a list. Passing as a list is the preferred method, as space escaping is more explicit and it avoids the need for executing anything in a shell.

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



Public project views.

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

Display project onboard steps.


alias of readthedocs.projects.models.Project

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

List view of public Project instances.


alias of readthedocs.projects.models.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, **kwargs)

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.AliasList(**kwargs)

alias of readthedocs.builds.models.VersionAlias

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

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


alias of readthedocs.projects.forms.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.IntegrationMixin

Project external service mixin for listing webhook objects.


alias of readthedocs.projects.forms.IntegrationForm


Return project integration determined by url kwarg.


alias of readthedocs.integrations.models.Integration

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.PrivateViewMixin
class readthedocs.projects.views.private.ProjectAdvertisingUpdate(**kwargs)

alias of readthedocs.projects.forms.ProjectAdvertisingForm


Returns the base queryset for the view.

Either used as a list of objects to display, or as the queryset from which to perform the individual object lookup.


alias of readthedocs.projects.models.Project

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

Project dashboard.


alias of readthedocs.projects.models.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_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.