Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add modeling for intersphinx data (#5289)
* Remove old test references to intersphinx * Initial commit of domains app * Add initial domaindata modeling and API integration * Add indexing of DomainData to the builds. * Cleanup of some domain stuff * Add search to Domains 🎉 * Add initial search implementation to DomainData * Move project search to a subset of site search This removes the second entry point to site search, and unifies all our searching to use fancy facets and be nice. * Small cleanup around faceting * Limit resuts by DomainData type * Remove old domains app * Remove search changes * Missed a few * Missed a bit more * remove random bits that got merged in * Undo url fix * Fix linting issues * Fix tests and linting * Review feedback * Fix lint * Move sphinx to a runtime requirement. * Use timestamped model for standardized class names * Address review feedback * Fix API name * Fix test too * Update readthedocs/projects/tasks.py Co-Authored-By: ericholscher <25510+ericholscher@users.noreply.github.com>
- Loading branch information
1 parent
2c479ec
commit 1fd489c
Showing
10 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"""Domain Admin classes.""" | ||
from django.contrib import admin | ||
|
||
from .models import SphinxDomain | ||
|
||
|
||
class SphinxDomainAdmin(admin.ModelAdmin): | ||
list_filter = ('type', 'project') | ||
raw_id_fields = ('project', 'version') | ||
search_fields = ('doc_name', 'name') | ||
|
||
|
||
admin.site.register(SphinxDomain, SphinxDomainAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Domain API classes.""" | ||
|
||
from rest_framework import serializers | ||
|
||
from readthedocs.restapi.views.model_views import UserSelectViewSet | ||
|
||
from .models import SphinxDomain | ||
|
||
|
||
class SphinxDomainSerializer(serializers.ModelSerializer): | ||
project = serializers.SlugRelatedField(slug_field='slug', read_only=True) | ||
version = serializers.SlugRelatedField(slug_field='slug', read_only=True) | ||
|
||
class Meta: | ||
model = SphinxDomain | ||
fields = ( | ||
'project', | ||
'version', | ||
'name', | ||
'display_name', | ||
'role_name', | ||
'docs_url', | ||
) | ||
|
||
|
||
class SphinxDomainAdminSerializer(SphinxDomainSerializer): | ||
|
||
class Meta(SphinxDomainSerializer.Meta): | ||
fields = '__all__' | ||
|
||
|
||
class SphinxDomainAPIView(UserSelectViewSet): # pylint: disable=too-many-ancestors | ||
model = SphinxDomain | ||
serializer_class = SphinxDomainSerializer | ||
admin_serializer_class = SphinxDomainAdminSerializer | ||
filter_fields = ( | ||
'project__slug', | ||
'version__slug', | ||
'domain', | ||
'type', | ||
'doc_name', | ||
'name', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
""" | ||
Sphinx Domain modeling. | ||
http://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html | ||
""" | ||
|
||
from django.db import models | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from django_extensions.db.models import TimeStampedModel | ||
|
||
from readthedocs.builds.models import Version | ||
from readthedocs.core.resolver import resolve | ||
from readthedocs.projects.models import Project | ||
from readthedocs.projects.querysets import RelatedProjectQuerySet | ||
|
||
|
||
class SphinxDomain(TimeStampedModel): | ||
|
||
""" | ||
Information from a project about it's Sphinx domains. | ||
This captures data about API objects that exist in that codebase. | ||
""" | ||
|
||
project = models.ForeignKey( | ||
Project, | ||
related_name='sphinx_domains', | ||
) | ||
version = models.ForeignKey( | ||
Version, | ||
verbose_name=_('Version'), | ||
related_name='sphinx_domains', | ||
) | ||
commit = models.CharField(_('Commit'), max_length=255, null=True) | ||
|
||
domain = models.CharField( | ||
_('Domain'), | ||
max_length=255, | ||
) | ||
name = models.CharField( | ||
_('Name'), | ||
max_length=255, | ||
) | ||
display_name = models.CharField( | ||
_('Display Name'), | ||
max_length=255, | ||
) | ||
type = models.CharField( | ||
_('Type'), | ||
max_length=255, | ||
) | ||
doc_name = models.CharField( | ||
_('Doc Name'), | ||
max_length=255, | ||
) | ||
anchor = models.CharField( | ||
_('Anchor'), | ||
max_length=255, | ||
) | ||
objects = RelatedProjectQuerySet.as_manager() | ||
|
||
def __str__(self): | ||
return f''' | ||
SphinxDomain [{self.project.slug}:{self.version.slug}] | ||
[{self.domain}:{self.type}] {self.name} -> | ||
{self.doc_name}#{self.anchor} | ||
''' | ||
|
||
@property | ||
def role_name(self): | ||
return f'{self.domain}:{self.type}' | ||
|
||
@property | ||
def docs_url(self): | ||
path = self.doc_name | ||
if self.anchor: | ||
path += f'#{self.anchor}' | ||
full_url = resolve( | ||
project=self.project, | ||
version_slug=self.version.slug, | ||
filename=path, | ||
) | ||
return full_url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters