Skip to content

Store version media availability #6278

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

Merged
merged 2 commits into from
Oct 14, 2019
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
3 changes: 3 additions & 0 deletions readthedocs/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class Meta:
'built',
'downloads',
'type',
'has_pdf',
'has_epub',
'has_htmlzip',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we add these to fields to APIv3 Version detail endpoint as well?

I'm not sure, since the download link will appear only if it exists. So, maybe it's redundant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These has_* fields feel like redundant fields for our API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it is a little awkward. These fields are used for writing by the build servers but not reading by the general public.

)


Expand Down
30 changes: 30 additions & 0 deletions readthedocs/builds/migrations/0011_version-media-availability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.23 on 2019-10-07 23:32
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('builds', '0010_add-description-field-to-automation-rule'),
]

operations = [
migrations.AddField(
model_name='version',
name='has_epub',
field=models.BooleanField(default=False, verbose_name='Has ePub'),
),
migrations.AddField(
model_name='version',
name='has_htmlzip',
field=models.BooleanField(default=False, verbose_name='Has HTML Zip'),
),
migrations.AddField(
model_name='version',
name='has_pdf',
field=models.BooleanField(default=False, verbose_name='Has PDF'),
),
]
5 changes: 5 additions & 0 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ class Version(models.Model):
)
machine = models.BooleanField(_('Machine Created'), default=False)

# Whether the latest successful build for this version contains certain media types
has_pdf = models.BooleanField(_('Has PDF'), default=False)
has_epub = models.BooleanField(_('Has ePub'), default=False)
has_htmlzip = models.BooleanField(_('Has HTML Zip'), default=False)

objects = VersionManager.from_queryset(VersionQuerySet)()
# Only include BRANCH, TAG, UNKNOWN type Versions.
internal = InternalVersionManager.from_queryset(VersionQuerySet)()
Expand Down
4 changes: 4 additions & 0 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,11 +904,15 @@ def update_app_instances(
downloads, and search. Tasks are broadcast to all web servers from here.
"""
# Update version if we have successfully built HTML output
# And store whether the build had other media types
try:
if html:
version = api_v2.version(self.version.pk)
version.patch({
'built': True,
'has_pdf': pdf,
'has_epub': epub,
'has_htmlzip': localmedia,
})
except HttpClientError:
log.exception(
Expand Down
22 changes: 22 additions & 0 deletions readthedocs/rtd_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,9 @@ def test_get_version_by_id(self):
'downloads': {},
'identifier': '2404a34eba4ee9c48cc8bc4055b99a48354f4950',
'slug': '0.8',
'has_epub': False,
'has_htmlzip': False,
'has_pdf': False,
}

self.assertDictEqual(
Expand Down Expand Up @@ -2213,6 +2216,25 @@ def test_get_active_versions(self):
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.data['count'], pip.versions.filter(active=False).count())

def test_modify_version(self):
pip = Project.objects.get(slug='pip')
version = pip.versions.get(slug='0.8')

data = {
'pk': version.pk,
}
resp = self.client.patch(
reverse('version-detail', kwargs=data),
data=json.dumps({'built': False, 'has_pdf': True}),
content_type='application/json',
HTTP_AUTHORIZATION='Basic {}'.format(eric_auth), # Eric is staff
)
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.data['built'], False)
self.assertEqual(resp.data['has_pdf'], True)
self.assertEqual(resp.data['has_epub'], False)
self.assertEqual(resp.data['has_htmlzip'], False)


class TaskViewsTests(TestCase):

Expand Down