Skip to content

Commit cb56df4

Browse files
davidfischerhumitos
authored andcommitted
Store version media availability (readthedocs#6278)
* Store version media availability - Stored during the build process - Does a particular version have a PDF? ePub? etc. * Add tests for missing version formats Co-Authored-By: Manuel Kaufmann <[email protected]>
1 parent f21e6fa commit cb56df4

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

readthedocs/api/v2/serializers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ class Meta:
9090
'built',
9191
'downloads',
9292
'type',
93+
'has_pdf',
94+
'has_epub',
95+
'has_htmlzip',
9396
)
9497

9598

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.23 on 2019-10-07 23:32
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('builds', '0010_add-description-field-to-automation-rule'),
12+
]
13+
14+
operations = [
15+
migrations.AddField(
16+
model_name='version',
17+
name='has_epub',
18+
field=models.BooleanField(default=False, verbose_name='Has ePub'),
19+
),
20+
migrations.AddField(
21+
model_name='version',
22+
name='has_htmlzip',
23+
field=models.BooleanField(default=False, verbose_name='Has HTML Zip'),
24+
),
25+
migrations.AddField(
26+
model_name='version',
27+
name='has_pdf',
28+
field=models.BooleanField(default=False, verbose_name='Has PDF'),
29+
),
30+
]

readthedocs/builds/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ class Version(models.Model):
133133
)
134134
machine = models.BooleanField(_('Machine Created'), default=False)
135135

136+
# Whether the latest successful build for this version contains certain media types
137+
has_pdf = models.BooleanField(_('Has PDF'), default=False)
138+
has_epub = models.BooleanField(_('Has ePub'), default=False)
139+
has_htmlzip = models.BooleanField(_('Has HTML Zip'), default=False)
140+
136141
objects = VersionManager.from_queryset(VersionQuerySet)()
137142
# Only include BRANCH, TAG, UNKNOWN type Versions.
138143
internal = InternalVersionManager.from_queryset(VersionQuerySet)()

readthedocs/projects/tasks.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,11 +904,15 @@ def update_app_instances(
904904
downloads, and search. Tasks are broadcast to all web servers from here.
905905
"""
906906
# Update version if we have successfully built HTML output
907+
# And store whether the build had other media types
907908
try:
908909
if html:
909910
version = api_v2.version(self.version.pk)
910911
version.patch({
911912
'built': True,
913+
'has_pdf': pdf,
914+
'has_epub': epub,
915+
'has_htmlzip': localmedia,
912916
})
913917
except HttpClientError:
914918
log.exception(

readthedocs/rtd_tests/tests/test_api.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,9 @@ def test_get_version_by_id(self):
21732173
'downloads': {},
21742174
'identifier': '2404a34eba4ee9c48cc8bc4055b99a48354f4950',
21752175
'slug': '0.8',
2176+
'has_epub': False,
2177+
'has_htmlzip': False,
2178+
'has_pdf': False,
21762179
}
21772180

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

2219+
def test_modify_version(self):
2220+
pip = Project.objects.get(slug='pip')
2221+
version = pip.versions.get(slug='0.8')
2222+
2223+
data = {
2224+
'pk': version.pk,
2225+
}
2226+
resp = self.client.patch(
2227+
reverse('version-detail', kwargs=data),
2228+
data=json.dumps({'built': False, 'has_pdf': True}),
2229+
content_type='application/json',
2230+
HTTP_AUTHORIZATION='Basic {}'.format(eric_auth), # Eric is staff
2231+
)
2232+
self.assertEqual(resp.status_code, 200)
2233+
self.assertEqual(resp.data['built'], False)
2234+
self.assertEqual(resp.data['has_pdf'], True)
2235+
self.assertEqual(resp.data['has_epub'], False)
2236+
self.assertEqual(resp.data['has_htmlzip'], False)
2237+
22162238

22172239
class TaskViewsTests(TestCase):
22182240

0 commit comments

Comments
 (0)