Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Embed API where we expect it. #3356

Merged
merged 5 commits into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions readthedocs/projects/static-src/projects/js/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ function EmbedView (config) {
self.api_example = ko.observable(null);

self.show_help = function () {
var embed = new rtd.Embed();
var embed = new rtd.Embed(self.config);
embed.section(
'docs', 'latest', 'features/embed', 'Content Embedding',
_show_modal
);
};

self.show_embed = function () {
var embed = new rtd.Embed();
var embed = new rtd.Embed(self.config);
_show_modal(self.response());
};
}
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/projects/static/projects/js/tools.js

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,20 +757,17 @@ def fileify(version_pk, commit):
"""
Create ImportedFile objects for all of a version's files.

This is a prereq for indexing the docs for search.
It also causes celery-haystack to kick off an index of the file.
This is so we have an idea of what files we have in the database.
"""
version = Version.objects.get(pk=version_pk)
project = version.project

if not project.cdn_enabled:
return

if not commit:
log.info(LOG_TEMPLATE
.format(project=project.slug, version=version.slug,
msg=('Imported File not being built because no commit '
'information')))
return

path = project.rtd_build_path(version.slug)
if path:
Expand Down Expand Up @@ -819,12 +816,12 @@ def _manage_imported_files(version, path, commit):
version=version
).exclude(commit=commit).delete()
# Purge Cache
changed_files = [resolve_path(
version.project, filename=fname, version_slug=version.slug,
) for fname in changed_files]
cdn_ids = getattr(settings, 'CDN_IDS', None)
if cdn_ids:
if version.project.slug in cdn_ids:
changed_files = [resolve_path(
version.project, filename=fname, version_slug=version.slug,
) for fname in changed_files]
purge(cdn_ids[version.project.slug], changed_files)


Expand Down
5 changes: 5 additions & 0 deletions readthedocs/projects/urls/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
public.project_embed,
name='project_embed'),

# url((r'^(?P<project_slug>{project_slug})/tools/analytics/$'
# .format(**pattern_opts)),
# public.project_analytics,
# name='project_analytics'),

url(r'^(?P<project_slug>{project_slug})/search/$'.format(**pattern_opts),
public.elastic_project_search,
name='elastic_project_search'),
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/projects/views/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,15 @@ def project_embed(request, project_slug):
project = get_object_or_404(Project.objects.protected(request.user),
slug=project_slug)
version = project.versions.get(slug=LATEST)
files = version.imported_files.order_by('path')
files = version.imported_files.filter(name__endswith='.html').order_by('path')

return render_to_response(
'projects/project_embed.html',
{
'project': project,
'files': files,
'settings': {
'GROK_API_HOST': settings.GROK_API_HOST,
'PUBLIC_API_URL': settings.PUBLIC_API_URL,
'URI': request.build_absolute_uri(location='/').rstrip('/')
}
},
Expand Down
9 changes: 5 additions & 4 deletions readthedocs/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from readthedocs.core.settings import Settings

try:
import readthedocsext.donate # noqa
donate = True
import readthedocsext # noqa
ext = True
except ImportError:
donate = False
ext = False


_ = gettext = lambda s: s
Expand Down Expand Up @@ -110,9 +110,10 @@ def INSTALLED_APPS(self): # noqa
'allauth.socialaccount.providers.bitbucket',
'allauth.socialaccount.providers.bitbucket_oauth2',
]
if donate:
if ext:
apps.append('django_countries')
apps.append('readthedocsext.donate')
apps.append('readthedocsext.embed')
return apps

TEMPLATE_LOADERS = (
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/templates/projects/project_embed.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
var project_tools = require('projects/tools');
$(document).ready(function () {
project_tools.init_embed({
api_host: '{{ settings.GROK_API_HOST }}',
api_host: '{{ settings.PUBLIC_API_URL }}',
uri: '{{ settings.URI }}',
project: '{{ project.slug }}'
});
Expand Down
7 changes: 7 additions & 0 deletions readthedocs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@
groups.append([
url(r'^sustainability/', include('readthedocsext.donate.urls')),
])

if 'readthedocsext.embed' in settings.INSTALLED_APPS:
api_urls.insert(
0,
url(r'^api/v1/embed/', include('readthedocsext.embed.urls'))
)

if not getattr(settings, 'USE_SUBDOMAIN', False) or settings.DEBUG:
groups.insert(0, docs_urls)
if getattr(settings, 'ALLOW_ADMIN', True):
Expand Down