Skip to content

Commit c362733

Browse files
committed
Merge branch 'master' of github.com:rtfd/readthedocs.org into humitos/apiv3-split-tests
2 parents deeacfa + 519b198 commit c362733

16 files changed

+202
-77
lines changed

docs/guides/feature-flags.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ Available Flags
1414

1515
``PIP_ALWAYS_UPGRADE``: :featureflags:`PIP_ALWAYS_UPGRADE`
1616

17+
``UPDATE_CONDA_STARTUP``: :featureflags:`UPDATE_CONDA_STARTUP`
18+
19+
The version of ``conda`` used in the build process could not be the latest one.
20+
This is because we use Miniconda, which its release process is a little more slow than ``conda`` itself.
21+
In case you prefer to use the latest ``conda`` version available, this is the flag you need.
22+
1723
``DONT_OVERWRITE_SPHINX_CONTEXT``: :featureflags:`DONT_OVERWRITE_SPHINX_CONTEXT`
1824

1925
``DONT_SHALLOW_CLONE``: :featureflags:`DONT_SHALLOW_CLONE`
@@ -22,4 +28,4 @@ The ``DONT_SHALLOW_CLONE`` flag is useful if your code accesses old commits duri
2228
e.g. python-reno release notes manager is known to do that
2329
(error message line would probably include one of old Git commit id's).
2430

25-
``USE_TESTING_BUILD_IMAGE``: :featureflags:`USE_TESTING_BUILD_IMAGE`
31+
``USE_TESTING_BUILD_IMAGE``: :featureflags:`USE_TESTING_BUILD_IMAGE`

readthedocs/api/v3/serializers.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,26 @@ def get_name(self, programming_language):
301301
return 'Unknown'
302302

303303

304-
class ProjectURLsSerializer(serializers.Serializer):
304+
class ProjectURLsSerializer(BaseLinksSerializer, serializers.Serializer):
305+
306+
"""Serializer with all the user-facing URLs under Read the Docs."""
307+
305308
documentation = serializers.CharField(source='get_docs_url')
306-
project_homepage = serializers.SerializerMethodField()
309+
home = serializers.SerializerMethodField()
310+
builds = serializers.SerializerMethodField()
311+
versions = serializers.SerializerMethodField()
307312

308-
def get_project_homepage(self, obj):
309-
# Overridden only to return ``None`` when the description is ``''``
310-
return obj.project_url or None
313+
def get_home(self, obj):
314+
path = reverse('projects_detail', kwargs={'project_slug': obj.slug})
315+
return self._absolute_url(path)
316+
317+
def get_builds(self, obj):
318+
path = reverse('builds_project_list', kwargs={'project_slug': obj.slug})
319+
return self._absolute_url(path)
320+
321+
def get_versions(self, obj):
322+
path = reverse('project_version_list', kwargs={'project_slug': obj.slug})
323+
return self._absolute_url(path)
311324

312325

313326
class RepositorySerializer(serializers.Serializer):
@@ -419,6 +432,7 @@ class Meta:
419432

420433
class ProjectSerializer(FlexFieldsModelSerializer):
421434

435+
homepage = serializers.SerializerMethodField()
422436
language = LanguageSerializer()
423437
programming_language = ProgrammingLanguageSerializer()
424438
repository = RepositorySerializer(source='*')
@@ -430,8 +444,6 @@ class ProjectSerializer(FlexFieldsModelSerializer):
430444
tags = serializers.StringRelatedField(many=True)
431445
users = UserSerializer(many=True)
432446

433-
description = serializers.SerializerMethodField()
434-
435447
_links = ProjectLinksSerializer(source='*')
436448

437449
# TODO: adapt these fields with the proper names in the db and then remove
@@ -457,11 +469,11 @@ class Meta:
457469
'id',
458470
'name',
459471
'slug',
460-
'description',
461472
'created',
462473
'modified',
463474
'language',
464475
'programming_language',
476+
'homepage',
465477
'repository',
466478
'default_version',
467479
'default_branch',
@@ -480,9 +492,9 @@ class Meta:
480492
'_links',
481493
]
482494

483-
def get_description(self, obj):
484-
# Overridden only to return ``None`` when the description is ``''``
485-
return obj.description or None
495+
def get_homepage(self, obj):
496+
# Overridden only to return ``None`` when the project_url is ``''``
497+
return obj.project_url or None
486498

487499
def get_translation_of(self, obj):
488500
if obj.main_language_project:

readthedocs/api/v3/tests/responses/projects-detail.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"created": "2019-04-29T10:00:00Z",
5252
"default_branch": "master",
5353
"default_version": "latest",
54-
"description": "Project description",
5554
"id": 1,
5655
"language": {
5756
"code": "en",
@@ -77,6 +76,7 @@
7776
"code": "words",
7877
"name": "Only Words"
7978
},
79+
"homepage": "http://project.com",
8080
"repository": {
8181
"type": "git",
8282
"url": "https://github.com/rtfd/project"
@@ -90,8 +90,10 @@
9090
],
9191
"translation_of": null,
9292
"urls": {
93+
"builds": "https://readthedocs.org/projects/project/builds/",
9394
"documentation": "http://readthedocs.org/docs/project/en/latest/",
94-
"project_homepage": "http://project.com"
95+
"home": "https://readthedocs.org/projects/project/",
96+
"versions": "https://readthedocs.org/projects/project/versions/"
9597
},
9698
"users": [
9799
{

readthedocs/api/v3/tests/responses/projects-list.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"id": 1,
88
"name": "project",
99
"slug": "project",
10-
"description": "Project description",
1110
"created": "2019-04-29T10:00:00Z",
1211
"modified": "2019-04-29T12:00:00Z",
1312
"language": {
@@ -18,6 +17,7 @@
1817
"code": "words",
1918
"name": "Only Words"
2019
},
20+
"homepage": "http://project.com",
2121
"repository": {
2222
"url": "https://github.com/rtfd/project",
2323
"type": "git"
@@ -31,8 +31,10 @@
3131
"subproject_of": null,
3232
"translation_of": null,
3333
"urls": {
34+
"builds": "https://readthedocs.org/projects/project/builds/",
3435
"documentation": "http://readthedocs.org/docs/project/en/latest/",
35-
"project_homepage": "http://project.com"
36+
"home": "https://readthedocs.org/projects/project/",
37+
"versions": "https://readthedocs.org/projects/project/versions/"
3638
},
3739
"tags": [
3840
"tag",

readthedocs/api/v3/tests/responses/projects-subprojects-list.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"id": 2,
88
"name": "subproject",
99
"slug": "subproject",
10-
"description": "SubProject description",
1110
"created": "2019-04-29T10:00:00Z",
1211
"modified": "2019-04-29T12:00:00Z",
1312
"language": {
@@ -18,6 +17,7 @@
1817
"code": "words",
1918
"name": "Only Words"
2019
},
20+
"homepage": "http://subproject.com",
2121
"repository": {
2222
"url": "https://github.com/rtfd/subproject",
2323
"type": "git"
@@ -32,7 +32,6 @@
3232
"id": 1,
3333
"name": "project",
3434
"slug": "project",
35-
"description": "Project description",
3635
"created": "2019-04-29T10:00:00Z",
3736
"modified": "2019-04-29T12:00:00Z",
3837
"language": {
@@ -43,6 +42,7 @@
4342
"code": "words",
4443
"name": "Only Words"
4544
},
45+
"homepage": "http://project.com",
4646
"repository": {
4747
"url": "https://github.com/rtfd/project",
4848
"type": "git"
@@ -56,8 +56,10 @@
5656
"subproject_of": null,
5757
"translation_of": null,
5858
"urls": {
59+
"builds": "https://readthedocs.org/projects/project/builds/",
5960
"documentation": "http://readthedocs.org/docs/project/en/latest/",
60-
"project_homepage": "http://project.com"
61+
"home": "https://readthedocs.org/projects/project/",
62+
"versions": "https://readthedocs.org/projects/project/versions/"
6163
},
6264
"tags": [
6365
"tag",
@@ -83,8 +85,10 @@
8385
},
8486
"translation_of": null,
8587
"urls": {
88+
"builds": "https://readthedocs.org/projects/subproject/builds/",
8689
"documentation": "http://readthedocs.org/docs/project/projects/subproject/en/latest/",
87-
"project_homepage": "http://subproject.com"
90+
"home": "https://readthedocs.org/projects/subproject/",
91+
"versions": "https://readthedocs.org/projects/subproject/versions/"
8892
},
8993
"tags": [],
9094
"users": [],

readthedocs/api/v3/tests/responses/projects-superproject.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"created": "2019-04-29T10:00:00Z",
33
"default_branch": "master",
44
"default_version": "latest",
5-
"description": "Project description",
65
"id": 1,
76
"language": {
87
"code": "en",
@@ -28,6 +27,7 @@
2827
"code": "words",
2928
"name": "Only Words"
3029
},
30+
"homepage": "http://project.com",
3131
"repository": {
3232
"type": "git",
3333
"url": "https://github.com/rtfd/project"
@@ -41,8 +41,10 @@
4141
],
4242
"translation_of": null,
4343
"urls": {
44+
"builds": "https://readthedocs.org/projects/project/builds/",
4445
"documentation": "http://readthedocs.org/docs/project/en/latest/",
45-
"project_homepage": "http://project.com"
46+
"home": "https://readthedocs.org/projects/project/",
47+
"versions": "https://readthedocs.org/projects/project/versions/"
4648
},
4749
"users": [
4850
{

readthedocs/api/v3/tests/responses/projects-versions-builds-list_POST.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"created": "2019-04-29T10:00:00Z",
2424
"default_branch": "master",
2525
"default_version": "latest",
26-
"description": "Project description",
2726
"id": 1,
2827
"language": {
2928
"code": "en",
@@ -49,6 +48,7 @@
4948
"code": "words",
5049
"name": "Only Words"
5150
},
51+
"homepage": "http://project.com",
5252
"repository": {
5353
"type": "git",
5454
"url": "https://github.com/rtfd/project"
@@ -62,8 +62,10 @@
6262
],
6363
"translation_of": null,
6464
"urls": {
65+
"builds": "https://readthedocs.org/projects/project/builds/",
6566
"documentation": "http://readthedocs.org/docs/project/en/latest/",
66-
"project_homepage": "http://project.com"
67+
"home": "https://readthedocs.org/projects/project/",
68+
"versions": "https://readthedocs.org/projects/project/versions/"
6769
},
6870
"users": [
6971
{

readthedocs/builds/admin.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
"""Django admin interface for `~builds.models.Build` and related models."""
22

3+
import json
34
from django.contrib import admin, messages
5+
from django.utils.safestring import mark_safe
46
from polymorphic.admin import (
57
PolymorphicChildModelAdmin,
68
PolymorphicParentModelAdmin,
79
)
810

11+
from pygments import highlight
12+
from pygments.lexers import JsonLexer
13+
from pygments.formatters import HtmlFormatter
14+
915
from readthedocs.builds.models import (
1016
Build,
1117
BuildCommandResult,
@@ -19,6 +25,29 @@
1925
from readthedocs.search.utils import _indexing_helper
2026

2127

28+
def _pretty_config(instance):
29+
"""
30+
Function to display pretty version of our data.
31+
32+
Thanks to PyDanny: https://www.pydanny.com/pretty-formatting-json-django-admin.html
33+
"""
34+
35+
# Convert the data to sorted, indented JSON
36+
response = json.dumps(instance.config, sort_keys=True, indent=2)
37+
38+
# Get the Pygments formatter
39+
formatter = HtmlFormatter()
40+
41+
# Highlight the data
42+
response = highlight(response, JsonLexer(), formatter)
43+
44+
# Get the stylesheet
45+
style = "<style>" + formatter.get_style_defs() + "</style><br>"
46+
47+
# Safe the output
48+
return mark_safe(style + response)
49+
50+
2251
class BuildCommandResultInline(admin.TabularInline):
2352
model = BuildCommandResult
2453
fields = ('command', 'exit_code', 'output')
@@ -34,6 +63,10 @@ class BuildAdmin(admin.ModelAdmin):
3463
'success',
3564
'length',
3665
'cold_storage',
66+
'pretty_config',
67+
)
68+
readonly_fields = (
69+
'pretty_config', # required to be read-only becuase it's a @property
3770
)
3871
list_display = (
3972
'id',
@@ -54,6 +87,11 @@ class BuildAdmin(admin.ModelAdmin):
5487
def version_name(self, obj):
5588
return obj.version.verbose_name
5689

90+
def pretty_config(self, instance):
91+
return _pretty_config(instance)
92+
93+
pretty_config.short_description = 'Config File'
94+
5795

5896
class VersionAdmin(admin.ModelAdmin):
5997

@@ -65,6 +103,9 @@ class VersionAdmin(admin.ModelAdmin):
65103
'active',
66104
'built',
67105
)
106+
readonly_fields = (
107+
'pretty_config', # required to be read-only becuase it's a @property
108+
)
68109
list_filter = ('type', 'privacy_level', 'active', 'built')
69110
search_fields = ('slug', 'project__slug')
70111
raw_id_fields = ('project',)
@@ -83,6 +124,10 @@ def wipe_selected_versions(self, request, queryset):
83124
level=messages.SUCCESS
84125
)
85126

127+
def pretty_config(self, instance):
128+
return _pretty_config(instance)
129+
130+
pretty_config.short_description = 'Config File'
86131
wipe_selected_versions.short_description = 'Wipe selected versions'
87132

88133
def build_version(self, request, queryset):

0 commit comments

Comments
 (0)