Prettified results page. Added search results templates for grappelli and the normal...
authorStephen Burrows <stephen.r.burrows@gmail.com>
Wed, 2 Mar 2011 18:01:28 +0000 (13:01 -0500)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Wed, 2 Mar 2011 18:02:25 +0000 (13:02 -0500)
contrib/sobol/admin.py
contrib/sobol/models.py
contrib/sobol/templates/admin/sobol/search/grappelli_results.html
contrib/sobol/templates/admin/sobol/search/results.html

index 1ebbf5e..504cde2 100644 (file)
@@ -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,
index 7e11882..e5852d7 100644 (file)
@@ -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:
index 28d5af7..45135ff 100644 (file)
@@ -3,13 +3,24 @@
 <!-- LOADING -->
 {% load i18n %}
 
+<!-- EXTRASTYLES -->
+{% block extrastyle %}<style type="text/css">.favored{font-weight:bold;}</style>{% endblock %}
+
 <!-- BREADCRUMBS -->
 {% block breadcrumbs %}
        <div id="breadcrumbs">
+               {% if queryset|length > 1 %}
                <a href="../../">{% trans "Home" %}</a> &rsaquo;
                <a href="../">{{ app_label|capfirst }}</a> &rsaquo;
                <a href="./">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
                {% trans 'Search results for multiple objects' %}
+               {% else %}
+               <a href="../../../../">{% trans "Home" %}</a> &rsaquo;
+               <a href="../../../">{{ app_label|capfirst }}</a> &rsaquo;
+               <a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
+               <a href="../">{{ queryset|first|truncatewords:"18" }}</a> &rsaquo;
+               {% trans 'Results' %}
+               {% endif %}
        </div>
 {% endblock %}
 
 {% block content %}
        <div class="container-grid delete-confirmation">
                {% for search in queryset %}
-               <h1>{{ search.string }}</h1>
-               <div class="module">
+               {% if not forloop.first and not forloop.last %}<h1>{{ search.string }}</h1>{% endif %}
+               <div class="group tabular">
                        <h2>{% blocktrans %}Results{% endblocktrans %}</h2>{% comment %}For the favored results, add a class?{% endcomment %}
-                       {% for result in search.get_weighted_results %}
-                       <div class="row cell-2">
-                               <div class="cell span-4">{{ result.url }}</div>
-                               <div class="cell span-flexible">{{ result.weight }}</div>
+                       <div class="module table">
+                               <div class="module thead">
+                                       <div class="tr">
+                                               <div class="th">Weight</div>
+                                               <div class="th">URL</div>
+                                       </div>
+                               </div>
+                               <div class="module tbody">
+                                       {% for result in search.get_weighted_results %}
+                                       <div class="tr{% if result in search.get_favored_results %} favored{% endif %}">
+                                               <div class="td">{{ result.weight }}</div>
+                                               <div class="td">{{ result.url }}</div>
+                                       </div>
+                                       {% endfor %}
+                               </div>
                        </div>
-                       {% endfor %}
                </div>
                {% endfor %}
        </div>
index e69de29..44d4e7c 100644 (file)
@@ -0,0 +1,47 @@
+{% extends "admin/base_site.html" %}
+{% load i18n %}
+
+{% block extrastyle %}<style type="text/css">.favored{font-weight:bold;}</style>{% endblock %}
+
+{% block breadcrumbs %}
+<div class="breadcrumbs">
+       {% if queryset|length > 1 %}
+       <a href="../../">{% trans "Home" %}</a> &rsaquo;
+       <a href="../">{{ app_label|capfirst }}</a> &rsaquo;
+       <a href="./">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
+       {% trans 'Search results for multiple objects' %}
+       {% else %}
+       <a href="../../../../">{% trans "Home" %}</a> &rsaquo;
+       <a href="../../../">{{ app_label|capfirst }}</a> &rsaquo; 
+       <a href="../../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
+       <a href="../">{{ queryset|first|truncatewords:"18" }}</a> &rsaquo;
+       {% trans 'Results' %}
+       {% endif %}
+</div>
+{% endblock %}
+
+
+{% block content %}
+               {% for search in queryset %}
+               {% if not forloop.first and not forloop.last %}<h1>{{ search.string }}</h1>{% endif %}
+                       <fieldset class="module">
+                               <h2>{% blocktrans %}Results{% endblocktrans %}</h2>{% comment %}For the favored results, add a class?{% endcomment %}
+                               <table>
+                                       <thead>
+                                               <tr>
+                                                       <th>Weight</th>
+                                                       <th>URL</th>
+                                               </tr>
+                                       </thead>
+                                       <tbody>
+                                               {% for result in search.get_weighted_results %}
+                                               <tr{% if result in search.favored_results %} class="favored"{% endif %}>
+                                                       <td>{{ result.weight }}</td>
+                                                       <td>{{ result.url }}</td>
+                                               </tr>
+                                               {% endfor %}
+                                       </tbody>
+                               </table>
+                       </fieldset>
+               {% endfor %}
+{% endblock %}
\ No newline at end of file