From e6cfcdcb0422222364657ebf223ffb6c88a6d880 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 2 Mar 2011 13:01:28 -0500 Subject: [PATCH] Prettified results page. Added search results templates for grappelli and the normal admin. --- contrib/sobol/admin.py | 7 +++ contrib/sobol/models.py | 2 +- .../admin/sobol/search/grappelli_results.html | 35 +++++++++++--- .../templates/admin/sobol/search/results.html | 47 +++++++++++++++++++ 4 files changed, 83 insertions(+), 8 deletions(-) diff --git a/contrib/sobol/admin.py b/contrib/sobol/admin.py index 1ebbf5e..504cde2 100644 --- a/contrib/sobol/admin.py +++ b/contrib/sobol/admin.py @@ -7,6 +7,7 @@ from django.http import HttpResponseRedirect, Http404 from django.shortcuts import render_to_response from django.template import RequestContext from django.utils.functional import update_wrapper +from django.utils.translation import ugettext_lazy as _ from philo.admin import EntityAdmin from philo.contrib.sobol.models import Search, ResultURL, SearchView @@ -79,7 +80,13 @@ class SearchAdmin(admin.ModelAdmin): qs = self.queryset(request).filter(pk__in=object_ids) opts = self.model._meta + if len(object_ids) == 1: + title = _(u"Search results for %s" % qs[0]) + else: + title = _(u"Search results for multiple objects") + context = { + 'title': title, 'queryset': qs, 'opts': opts, 'root_path': self.admin_site.root_path, diff --git a/contrib/sobol/models.py b/contrib/sobol/models.py index 7e11882..e5852d7 100644 --- a/contrib/sobol/models.py +++ b/contrib/sobol/models.py @@ -63,7 +63,7 @@ class Search(models.Model): self._favored_results = [] for value, subresults in grouped_results.items(): - cost = error * sum([(value - result.weight)**2 for result in results]) + cost = error * sum([(value - result.weight)**2 for result in self._favored_results]) if value > cost: self._favored_results += subresults else: diff --git a/contrib/sobol/templates/admin/sobol/search/grappelli_results.html b/contrib/sobol/templates/admin/sobol/search/grappelli_results.html index 28d5af7..45135ff 100644 --- a/contrib/sobol/templates/admin/sobol/search/grappelli_results.html +++ b/contrib/sobol/templates/admin/sobol/search/grappelli_results.html @@ -3,13 +3,24 @@ {% load i18n %} + +{% block extrastyle %}{% endblock %} + {% block breadcrumbs %} {% endblock %} @@ -17,15 +28,25 @@ {% block content %}
{% for search in queryset %} -

{{ search.string }}

-
+ {% if not forloop.first and not forloop.last %}

{{ search.string }}

{% endif %} +

{% blocktrans %}Results{% endblocktrans %}

{% comment %}For the favored results, add a class?{% endcomment %} - {% for result in search.get_weighted_results %} -
-
{{ result.url }}
-
{{ result.weight }}
+
+
+
+
Weight
+
URL
+
+
+
+ {% for result in search.get_weighted_results %} +
+
{{ result.weight }}
+
{{ result.url }}
+
+ {% endfor %} +
- {% endfor %}
{% endfor %}
diff --git a/contrib/sobol/templates/admin/sobol/search/results.html b/contrib/sobol/templates/admin/sobol/search/results.html index e69de29..44d4e7c 100644 --- a/contrib/sobol/templates/admin/sobol/search/results.html +++ b/contrib/sobol/templates/admin/sobol/search/results.html @@ -0,0 +1,47 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} + +{% block extrastyle %}{% endblock %} + +{% block breadcrumbs %} + +{% endblock %} + + +{% block content %} + {% for search in queryset %} + {% if not forloop.first and not forloop.last %}

{{ search.string }}

{% endif %} +
+

{% blocktrans %}Results{% endblocktrans %}

{% comment %}For the favored results, add a class?{% endcomment %} + + + + + + + + + {% for result in search.get_weighted_results %} + + + + + {% endfor %} + +
WeightURL
{{ result.weight }}{{ result.url }}
+
+ {% endfor %} +{% endblock %} \ No newline at end of file -- 2.20.1