Ticket #4125: databrowse_fixes.5.patch

File databrowse_fixes.5.patch, 14.6 KB (added by Chris Beaven, 12 years ago)

"x objects" on the main object list page too

  • django/contrib/databrowse/datastructures.py

     
    77from django.utils import dateformat
    88from django.utils.text import capfirst
    99from django.utils.translation import get_date_formats
     10from django.db.models.query import QuerySet
    1011
    1112EMPTY_VALUE = '(None)'
    1213
     
    2930        return '%s%s/%s/' % (self.site.root_url, self.model._meta.app_label, self.model._meta.module_name)
    3031
    3132    def objects(self, **kwargs):
    32         for obj in self.model._default_manager.filter(**kwargs):
    33             yield EasyInstance(self, obj)
     33        return self.get_query_set().filter(**kwargs)
    3434
     35    def get_query_set(self):
     36        easy_qs = self.model._default_manager.get_query_set()._clone(klass=EasyQuerySet)
     37        easy_qs._easymodel = self
     38        return easy_qs
     39
    3540    def object_by_pk(self, pk):
    3641        return EasyInstance(self, self.model._default_manager.get(pk=pk))
    3742
     
    190195        else:
    191196            lst = [(self.values()[0], None)]
    192197        return lst
     198
     199class EasyQuerySet(QuerySet):
     200    """
     201    When creating (or cloning to) an `EasyQuerySet`, make sure to set the
     202    `_easymodel` variable to the related `EasyModel`.
     203    """
     204    def iterator(self, *args, **kwargs):
     205        for obj in super(EasyQuerySet, self).iterator(*args, **kwargs):
     206            yield EasyInstance(self._easymodel, obj)
     207
     208    def _clone(self, *args, **kwargs):
     209        c = super(EasyQuerySet, self)._clone(*args, **kwargs)
     210        c._easymodel = self._easymodel
     211        return c
  • django/contrib/databrowse/plugins/calendars.py

     
    6363
    6464    def calendar_view(self, request, field, year=None, month=None, day=None):
    6565        easy_model = EasyModel(self.site, self.model)
     66        queryset = easy_model.get_query_set()
    6667        extra_context = {'root_url': self.site.root_url, 'model': easy_model, 'field': field}
    6768        if day is not None:
    68             # TODO: The objects in this template should be EasyInstances
    69             return date_based.archive_day(request, year, month, day, self.model.objects.all(), field.name,
     69            return date_based.archive_day(request, year, month, day, queryset, field.name,
    7070                template_name='databrowse/calendar_day.html', allow_empty=False, allow_future=True,
    7171                extra_context=extra_context)
    7272        elif month is not None:
    73             return date_based.archive_month(request, year, month, self.model.objects.all(), field.name,
     73            return date_based.archive_month(request, year, month, queryset, field.name,
    7474                template_name='databrowse/calendar_month.html', allow_empty=False, allow_future=True,
    7575                extra_context=extra_context)
    7676        elif year is not None:
    77             return date_based.archive_year(request, year, self.model.objects.all(), field.name,
     77            return date_based.archive_year(request, year, queryset, field.name,
    7878                template_name='databrowse/calendar_year.html', allow_empty=False, allow_future=True,
    7979                extra_context=extra_context)
    8080        else:
    81             return date_based.archive_index(request, self.model.objects.all(), field.name,
     81            return date_based.archive_index(request, queryset, field.name,
    8282                template_name='databrowse/calendar_main.html', allow_empty=True, allow_future=True,
    8383                extra_context=extra_context)
    8484        assert False, ('%s, %s, %s, %s' % (field, year, month, day))
  • django/contrib/databrowse/templates/databrowse/base.html

     
    22<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ LANGUAGE_CODE }}" xml:lang="{{ LANGUAGE_CODE }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
    33<head>
    44<title>{% block title %}{% endblock %}</title>
     5{% block style %}
    56<style type="text/css">
    67* { margin:0; padding:0; }
    78body { background:#eee; color:#333; font:76%/1.6 "Lucida Grande","Bitstream Vera Sans",Verdana,sans-serif; }
     
    4849/* CONTENT */
    4950#content { background:#fff; border-bottom:1px solid #ddd; padding:0 20px; }
    5051</style>
     52{% endblock %}
     53{% block extrahead %}{% endblock %}
    5154</head>
    5255<body id="{% block bodyid %}page{% endblock %}">
    53 <div id="header"><a href="{{ root_url }}">Databrowse</a></div>
     56<div id="header"><a href="{{ root_url }}">{% block databrowse_title %}Databrowse{% endblock %}</a></div>
    5457<div id="content">
    5558{% block content %}{% endblock %}
    5659</div>
  • django/contrib/databrowse/templates/databrowse/base_site.html

     
     1{% extends "databrowse/base.html" %}
  • django/contrib/databrowse/templates/databrowse/calendar_day.html

     
    1 {% extends "databrowse/base.html" %}
     1{% extends "databrowse/base_site.html" %}
    22
    33{% block title %}{{ model.verbose_name_plural|capfirst }} with {{ field.verbose_name }} {{ day|date:"F j, Y" }}{% endblock %}
    44
     
    66
    77<div id="breadcrumbs"><a href="{{ root_url }}">Home</a> / <a href="{{ model.url }}">{{ model.verbose_name_plural|capfirst }}</a> / <a href="../../../../">Calendars</a> / <a href="../../../">By {{ field.verbose_name }}</a> / <a href="../../">{{ day.year }}</a> / <a href="../">{{ day|date:"F" }}</a> / {{ day.day }}</div>
    88
    9 <h1>{{ model.verbose_name_plural|capfirst }} with {{ field.verbose_name }} on {{ day|date:"F j, Y" }}</h1>
     9<h1>{{ object_list.count }} {% if object_list.count|pluralize %}{{ model.verbose_name_plural|escape }}{% else %}{{ model.verbose_name|escape }}{% endif %} with {{ field.verbose_name }} on {{ day|date:"F j, Y" }}</h1>
    1010
    1111<ul class="objectlist">
    1212{% for object in object_list %}
    13 <li class="{% cycle odd,even %}"><a href="{{ object.url }}">{{ object }}</a></li>
     13<li class="{% cycle odd,even %}"><a href="{{ object.url }}">{{ object|escape }}</a></li>
    1414{% endfor %}
    1515</ul>
    1616
  • django/contrib/databrowse/templates/databrowse/calendar_homepage.html

     
    1 {% extends "databrowse/base.html" %}
     1{% extends "databrowse/base_site.html" %}
    22
    33{% block title %}Calendars{% endblock %}
    44
  • django/contrib/databrowse/templates/databrowse/calendar_main.html

     
    1 {% extends "databrowse/base.html" %}
     1{% extends "databrowse/base_site.html" %}
    22
    33{% block title %}{{ field.verbose_name|capfirst }} calendar{% endblock %}
    44
  • django/contrib/databrowse/templates/databrowse/calendar_month.html

     
    1 {% extends "databrowse/base.html" %}
     1{% extends "databrowse/base_site.html" %}
    22
    33{% block title %}{{ model.verbose_name_plural|capfirst }} with {{ field.verbose_name }} in {{ month|date:"F Y" }}{% endblock %}
    44
     
    66
    77<div id="breadcrumbs"><a href="{{ root_url }}">Home</a> / <a href="{{ model.url }}">{{ model.verbose_name_plural|capfirst }}</a> / <a href="../../../">Calendars</a> / <a href="../../">By {{ field.verbose_name }}</a> / <a href="../">{{ month.year }}</a> / {{ month|date:"F" }}</div>
    88
    9 <h1>{{ model.verbose_name_plural|capfirst }} with {{ field.verbose_name }} in {{ month|date:"F Y" }}</h1>
     9<h1>{{ object_list.count }} {% if object_list.count|pluralize %}{{ model.verbose_name_plural }}{% else %}{{ model.verbose_name }}{% endif %} with {{ field.verbose_name }} in {{ month|date:"F Y" }}</h1>
    1010
    1111<ul class="objectlist">
    1212{% for object in object_list %}
    13 <li class="{% cycle odd,even %}"><a href="{{ object.url }}">{{ object }}</a></li>
     13<li class="{% cycle odd,even %}"><a href="{{ object.url }}">{{ object|escape }}</a></li>
    1414{% endfor %}
    1515</ul>
    1616
  • django/contrib/databrowse/templates/databrowse/calendar_year.html

     
    1 {% extends "databrowse/base.html" %}
     1{% extends "databrowse/base_site.html" %}
    22
    33{% block title %}{{ model.verbose_name_plural|capfirst }} with {{ field.verbose_name }} in {{ year }}{% endblock %}
    44
  • django/contrib/databrowse/templates/databrowse/choice_detail.html

     
    1 {% extends "databrowse/base.html" %}
     1{% extends "databrowse/base_site.html" %}
    22
    33{% block title %}{{ model.verbose_name_plural|capfirst }} by {{ field.field.verbose_name }}: {{ value|escape }}{% endblock %}
    44
  • django/contrib/databrowse/templates/databrowse/choice_list.html

     
    1 {% extends "databrowse/base.html" %}
     1{% extends "databrowse/base_site.html" %}
    22
    33{% block title %}{{ model.verbose_name_plural|capfirst }} by {{ field.field.verbose_name }}{% endblock %}
    44
  • django/contrib/databrowse/templates/databrowse/fieldchoice_detail.html

     
    1 {% extends "databrowse/base.html" %}
     1{% extends "databrowse/base_site.html" %}
    22
    33{% block title %}{{ model.verbose_name_plural|capfirst|escape }} with {{ field.field.verbose_name|escape }} {{ value|escape }}{% endblock %}
    44
     
    66
    77<div id="breadcrumbs"><a href="{{ root_url }}">Home</a> / <a href="{{ model.url }}">{{ model.verbose_name_plural|capfirst }}</a> / <a href="../../">Fields</a> / <a href="../">By {{ field.field.verbose_name|escape }}</a> / {{ value|escape }}</div>
    88
    9 <h1>{{ model.verbose_name_plural|capfirst|escape }} with {{ field.field.verbose_name|escape }} {{ value|escape }}</h1>
     9<h1>{{ object_list.count }} {% if object_list.count|pluralize %}{{ model.verbose_name_plural|escape }}{% else %}{{ model.verbose_name|escape }}{% endif %} with {{ field.field.verbose_name|escape }} {{ value|escape }}</h1>
    1010
    1111<ul class="objectlist">
    1212{% for object in object_list %}
  • django/contrib/databrowse/templates/databrowse/fieldchoice_homepage.html

     
    1 {% extends "databrowse/base.html" %}
     1{% extends "databrowse/base_site.html" %}
    22
    33{% block title %}Browsable fields in {{ model.verbose_name_plural|escape }}{% endblock %}
    44
  • django/contrib/databrowse/templates/databrowse/fieldchoice_list.html

     
    1 {% extends "databrowse/base.html" %}
     1{% extends "databrowse/base_site.html" %}
    22
    33{% block title %}{{ model.verbose_name_plural|capfirst|escape }} by {{ field.field.verbose_name|escape }}{% endblock %}
    44
  • django/contrib/databrowse/templates/databrowse/homepage.html

     
    1 {% extends "databrowse/base.html" %}
     1{% extends "databrowse/base_site.html" %}
    22
    33{% block title %}Databrowse{% endblock %}
    44
  • django/contrib/databrowse/templates/databrowse/model_detail.html

     
    1 {% extends "databrowse/base.html" %}
     1{% extends "databrowse/base_site.html" %}
    22
    33{% block title %}{{ model.verbose_name_plural|capfirst }}{% endblock %}
    44
     
    66
    77<div id="breadcrumbs"><a href="{{ root_url }}">Home</a> / {{ model.verbose_name_plural|capfirst }}</div>
    88
    9 <h1>{{ model.verbose_name_plural|capfirst }}</h1>
     9<h1>{{ model.objects.count }} {% if model.objects.count|pluralize %}{{ model.verbose_name_plural }}{% else %}{{ model.verbose_name }}{% endif %}</h1>
    1010
    1111{{ plugin_html }}
    1212
  • django/contrib/databrowse/templates/databrowse/object_detail.html

     
    1 {% extends "databrowse/base.html" %}
     1{% extends "databrowse/base_site.html" %}
    22
    33{% block title %}{{ object.model.verbose_name|capfirst }}: {{ object }}{% endblock %}
    44
Back to Top