Skip to content

Commit ddf5259

Browse files
authored
Merge branch 'master' into gsoc-19-pr-builder
2 parents f03d076 + e12f70d commit ddf5259

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

readthedocs/builds/admin.py

+45
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):

readthedocs/projects/models.py

-16
Original file line numberDiff line numberDiff line change
@@ -767,10 +767,6 @@ def conf_dir(self, version=LATEST):
767767
if conf_file:
768768
return os.path.dirname(conf_file)
769769

770-
@property
771-
def is_imported(self):
772-
return bool(self.repo)
773-
774770
@property
775771
def has_good_build(self):
776772
# Check if there is `_good_build` annotation in the Queryset.
@@ -779,14 +775,6 @@ def has_good_build(self):
779775
return self._good_build
780776
return self.builds(manager=INTERNAL).filter(success=True).exists()
781777

782-
@property
783-
def has_versions(self):
784-
return self.versions.exists()
785-
786-
@property
787-
def has_aliases(self):
788-
return self.aliases.exists()
789-
790778
def has_media(self, type_, version_slug=LATEST, version_type=None):
791779
path = self.get_production_media_path(
792780
type_=type_, version_slug=version_slug
@@ -825,10 +813,6 @@ def has_htmlzip(self, version_slug=LATEST, version_type=None):
825813
version_type=version_type
826814
)
827815

828-
@property
829-
def sponsored(self):
830-
return False
831-
832816
def vcs_repo(
833817
self, version=LATEST, environment=None,
834818
verbose_name=None, version_type=None

0 commit comments

Comments
 (0)