Fix styling of AFE admin interface.
The change_list.html for tests used to be handled as a customized
template. The template failed to extend the original change_list.html,
so it didn't keep up to date. Additionally, the "white-space:pre" style
was applied to all <td> elements instead of just the description.
This restricts that style change to the description only, and also
maintains most of the default Django admin interface.
Signed-off-by: James Ren <jamesren@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@4247 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/frontend/afe/admin.py b/frontend/afe/admin.py
index 545ff04..df5d9a7 100644
--- a/frontend/afe/admin.py
+++ b/frontend/afe/admin.py
@@ -101,7 +101,7 @@
'test_time', 'sync_count', 'test_type', 'path',
'dependencies', 'experimental', 'run_verify',
'description')
- list_display = ('name', 'test_type', 'description', 'sync_count')
+ list_display = ('name', 'test_type', 'admin_description', 'sync_count')
search_fields = ('name',)
filter_horizontal = ('dependency_labels',)
diff --git a/frontend/afe/models.py b/frontend/afe/models.py
index 2c8807e..a208a97 100644
--- a/frontend/afe/models.py
+++ b/frontend/afe/models.py
@@ -1,6 +1,7 @@
import logging, os
from datetime import datetime
from django.db import models as dbmodels, connection
+from xml.sax import saxutils
import common
from autotest_lib.frontend.afe import model_logic
from autotest_lib.frontend import settings, thread_local
@@ -422,6 +423,12 @@
objects = model_logic.ExtendedManager()
+ def admin_description(self):
+ escaped_description = saxutils.escape(self.description)
+ return '<span style="white-space:pre">%s</span>' % escaped_description
+ admin_description.allow_tags = True
+
+
class Meta:
db_table = 'afe_autotests'
diff --git a/frontend/templates/admin/afe/test/change_list.html b/frontend/templates/admin/afe/test/change_list.html
deleted file mode 100644
index 7af4c5d..0000000
--- a/frontend/templates/admin/afe/test/change_list.html
+++ /dev/null
@@ -1,45 +0,0 @@
-{% extends "admin/base_site.html" %}
-{% load adminmedia admin_list i18n %}
-
-{% block stylesheet %}{% admin_media_prefix %}css/changelists.css{% endblock %}
-
-<!-- This file is a copy of django/contrib/admin/templates/admin/change_list.html with the following extrastyle added: -->
-{% block extrastyle %}
-<style type="text/css">
- table tbody td { white-space:pre; }
-</style>
-{% endblock %}
-
-{% block bodyclass %}change-list{% endblock %}
-
-{% if not is_popup %}{% block breadcrumbs %}<div class="breadcrumbs"><a href="../../">{% trans "Home" %}</a> › <a href="../">{{ app_label|capfirst }}</a> › {{ cl.opts.verbose_name_plural|capfirst }}</div>{% endblock %}{% endif %}
-
-{% block coltype %}flex{% endblock %}
-
-{% block content %}
-<div id="content-main">
-{% block object-tools %}
-{% if has_add_permission %}
-<ul class="object-tools"><li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}</a></li></ul>
-{% endif %}
-{% endblock %}
-<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
-{% block search %}{% search_form cl %}{% endblock %}
-{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
-
-{% block filters %}
-{% if cl.has_filters %}
-<div id="changelist-filter">
-<h2>{% trans 'Filter' %}</h2>
-{% for spec in cl.filter_specs %}
- {% admin_list_filter cl spec %}
-{% endfor %}
-</div>
-{% endif %}
-{% endblock %}
-
-{% block result_list %}{% result_list cl %}{% endblock %}
-{% block pagination %}{% pagination cl %}{% endblock %}
-</div>
-</div>
-{% endblock %}