Embed dashboard iframe on experiment status page fixes #110

This commit is contained in:
Jared Kerim 2017-06-28 14:55:01 -04:00 коммит произвёл Jared Kerim
Родитель 24a4e54e9d
Коммит c09261dcab
4 изменённых файлов: 74 добавлений и 8 удалений

Просмотреть файл

@ -35,6 +35,20 @@ class BaseVariantInlineAdmin(SlugPrepopulatedMixin, admin.StackedInline):
def has_delete_permission(self, request, obj=None):
return False
def get_fieldsets(self, request, obj=None):
fieldsets = super().get_fieldsets(request, obj=obj)
if obj is not None and obj.is_begun:
fieldsets = (
(None, {
'fields': (
self.get_readonly_fields(request, obj=obj),
),
}),
)
return fieldsets
class ControlVariantModelForm(forms.ModelForm):
@ -105,13 +119,20 @@ class ExperimentAdmin(SlugPrepopulatedMixin, admin.ModelAdmin):
fieldsets = super().get_fieldsets(request, obj=obj)
if obj is not None:
fieldsets = (('Status', {
'fields': (
'status',
('created_date', 'start_date', 'end_date'),
'show_dashboard_url',
),
}),) + fieldsets
fieldsets = (
('Status', {
'fields': (
('status', 'project', 'name', 'slug'),
('created_date', 'start_date', 'end_date'),
'addon_versions',
),
}),
('Notes', {
'fields': (
('objectives', 'success_criteria', 'analysis'),
),
}),
)
return fieldsets
@ -126,7 +147,7 @@ class ExperimentAdmin(SlugPrepopulatedMixin, admin.ModelAdmin):
if db_obj.is_begun:
readonly_fields += (
'project', 'name', 'slug', 'addon_versions')
'project', 'name', 'slug')
return readonly_fields

Просмотреть файл

@ -78,6 +78,26 @@ class BaseVariantInlineAdminTest(TestCase):
mock.Mock(), obj=experiment)
self.assertEqual(set(readonly_fields), set(inline_admin.fields))
def test_get_fieldsets_return_fields_when_experiment_not_started(self):
experiment = ExperimentFactory.create_with_variants()
inline_admin = BaseVariantInlineAdmin(mock.Mock(), mock.Mock())
inline_admin.fields = ('a', 'b', 'c')
fieldsets = inline_admin.get_fieldsets(mock.Mock(), obj=experiment)
self.assertEqual(fieldsets, [(None, {'fields': ('a', 'b', 'c')})])
def test_get_fieldsets_return_one_row_when_experiment_started(self):
experiment = ExperimentFactory.create_with_variants()
experiment.status = experiment.EXPERIMENT_STARTED
experiment.save()
inline_admin = BaseVariantInlineAdmin(mock.Mock(), mock.Mock())
inline_admin.fields = ('a', 'b', 'c')
fieldsets = inline_admin.get_fieldsets(mock.Mock(), obj=experiment)
self.assertEqual(fieldsets, ((None, {'fields': (('a', 'b', 'c'),)}),))
class ControlVariantModelFormTests(TestCase):

Просмотреть файл

@ -38,3 +38,16 @@ div.breadcrumbs {
a:link, a:visited {
color: #535353;
}
.aligned label {
width: 180px;
}
.aligned label + p, .aligned label + div.help, .aligned label + div.readonly {
margin-left: 0px;
}
#id_addon_versions {
height: 20px;
width: 400px;
}

Просмотреть файл

@ -0,0 +1,12 @@
{% extends "admin/change_form.html" %}
{% block content %}
{{ block.super }}
<script>
function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}
</script>
<iframe src="{{ original.dashboard_url }}" frameborder="0" scrolling="no" width="100%" height="9000px" onload="resizeIframe(this)" />
{% endblock %}