Removed results action from SearchAdmin. Added support for vanilla django result...
authorStephen Burrows <stephen.r.burrows@gmail.com>
Fri, 10 Jun 2011 17:52:10 +0000 (13:52 -0400)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Fri, 10 Jun 2011 17:52:10 +0000 (13:52 -0400)
philo/contrib/sobol/admin.py
philo/contrib/sobol/templates/admin/sobol/search/change_form.html
philo/contrib/sobol/templates/admin/sobol/search/grappelli_change_form.html [new file with mode: 0644]
philo/contrib/sobol/templates/admin/sobol/search/results.html [deleted file]

index f4636e7..6af7e4d 100644 (file)
@@ -29,25 +29,7 @@ class SearchAdmin(admin.ModelAdmin):
        search_fields = ['string', 'result_urls__url']
        actions = ['results_action']
        if 'grappelli' in settings.INSTALLED_APPS:
        search_fields = ['string', 'result_urls__url']
        actions = ['results_action']
        if 'grappelli' in settings.INSTALLED_APPS:
-               results_template = 'admin/sobol/search/grappelli_results.html'
-       else:
-               results_template = 'admin/sobol/search/results.html'
-       
-       def get_urls(self):
-               urlpatterns = super(SearchAdmin, self).get_urls()
-               
-               def wrap(view):
-                       def wrapper(*args, **kwargs):
-                               return self.admin_site.admin_view(view)(*args, **kwargs)
-                       return update_wrapper(wrapper, view)
-               
-               info = self.model._meta.app_label, self.model._meta.module_name
-               
-               urlpatterns = patterns('',
-                       url(r'^results/$', wrap(self.results_view), name="%s_%s_selected_results" % info),
-                       url(r'^(.+)/results/$', wrap(self.results_view), name="%s_%s_results" % info)
-               ) + urlpatterns
-               return urlpatterns
+               change_form_template = 'admin/sobol/search/grappelli_change_form.html'
        
        def unique_urls(self, obj):
                return obj.unique_urls
        
        def unique_urls(self, obj):
                return obj.unique_urls
@@ -60,41 +42,6 @@ class SearchAdmin(admin.ModelAdmin):
        def queryset(self, request):
                qs = super(SearchAdmin, self).queryset(request)
                return qs.annotate(total_clicks=Count('result_urls__clicks', distinct=True), unique_urls=Count('result_urls', distinct=True))
        def queryset(self, request):
                qs = super(SearchAdmin, self).queryset(request)
                return qs.annotate(total_clicks=Count('result_urls__clicks', distinct=True), unique_urls=Count('result_urls', distinct=True))
-       
-       def results_action(self, request, queryset):
-               info = self.model._meta.app_label, self.model._meta.module_name
-               if len(queryset) == 1:
-                       return HttpResponseRedirect(reverse("admin:%s_%s_results" % info, args=(queryset[0].pk,)))
-               else:
-                       url = reverse("admin:%s_%s_selected_results" % info)
-                       return HttpResponseRedirect("%s?ids=%s" % (url, ','.join([str(item.pk) for item in queryset])))
-       results_action.short_description = "View results for selected %(verbose_name_plural)s"
-       
-       def results_view(self, request, object_id=None, extra_context=None):
-               if object_id is not None:
-                       object_ids = [object_id]
-               else:
-                       object_ids = request.GET.get('ids').split(',')
-                       
-                       if object_ids is None:
-                               raise Http404
-               
-               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,
-                       'app_label': opts.app_label
-               }
-               return render_to_response(self.results_template, context, context_instance=RequestContext(request))
 
 
 class SearchViewAdmin(EntityAdmin):
 
 
 class SearchViewAdmin(EntityAdmin):
index 2761599..8dfba08 100644 (file)
@@ -10,9 +10,8 @@
                .favored td{
                        font-weight:bold;
                }
                .favored td{
                        font-weight:bold;
                }
-               #changelist{
-                       border:none;
-                       background:none;
+               #changelist table{
+                       width:100%;
                }
        </style>
 {% endblock %}
                }
        </style>
 {% endblock %}
@@ -36,9 +35,9 @@
                        </tbody>
                </table>
        </div>
                        </tbody>
                </table>
        </div>
-       <div class="module footer">
-               <ul class="submit-row">
-                       {% if not is_popup and has_delete_permission %}{% if change or show_delete %}<li class="left delete-link-container"><a href="delete/" class="delete-link">{% trans "Delete" %}</a></li>{% endif %}{% endif %}
-               </ul>
+       {% block submit_row %}
+       <div class="submit-row">
+               {% if not is_popup and has_delete_permission %}{% if change or show_delete %}<p class="deletelink-box"><a href="delete/" class="deletelink">{% trans "Delete" %}</a></p>{% endif %}{% endif %}
        </div>
        </div>
+       {% endblock %}
 {% endblock %}
\ No newline at end of file
 {% endblock %}
\ No newline at end of file
diff --git a/philo/contrib/sobol/templates/admin/sobol/search/grappelli_change_form.html b/philo/contrib/sobol/templates/admin/sobol/search/grappelli_change_form.html
new file mode 100644 (file)
index 0000000..c89f748
--- /dev/null
@@ -0,0 +1,23 @@
+{% extends 'admin/sobol/search/change_form.html' %}
+{% load i18n %}
+
+{% block extrastyle %}
+       <style type="text/css">
+               .favored td{
+                       font-weight:bold;
+               }
+               #changelist{
+                       border:none;
+                       background:none;
+               }
+               thead th{color:#444;font-weight:bold;}
+       </style>
+{% endblock %}
+
+{% block submit_row %}
+       <div class="module footer">
+               <ul class="submit-row">
+                       {% if not is_popup and has_delete_permission %}{% if change or show_delete %}<li class="left delete-link-container"><a href="delete/" class="delete-link">{% trans "Delete" %}</a></li>{% endif %}{% endif %}
+               </ul>
+       </div>
+{% endblock %}
\ No newline at end of file
diff --git a/philo/contrib/sobol/templates/admin/sobol/search/results.html b/philo/contrib/sobol/templates/admin/sobol/search/results.html
deleted file mode 100644 (file)
index 24442c7..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-{% 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 %}
-                       <fieldset class="module">
-                               <h2>{{ search.string }}</h2>
-                               <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