Ticket #4481: ticket4481.patch
File ticket4481.patch, 5.2 KB (added by , 17 years ago) |
---|
-
django/contrib/databrowse/datastructures.py
7 7 from django.utils import dateformat 8 8 from django.utils.text import capfirst 9 9 from django.utils.translation import get_date_formats 10 from django.core.paginator import ObjectPaginator 10 11 11 12 EMPTY_VALUE = '(None)' 12 13 13 14 class EasyModel(object): 14 def __init__(self, site, model ):15 def __init__(self, site, model, paginate_by=100, page=0): 15 16 self.site = site 16 17 self.model = model 17 18 self.model_list = site.registry.keys() 18 19 self.verbose_name = model._meta.verbose_name 19 20 self.verbose_name_plural = model._meta.verbose_name_plural 21 self.paginate_by = paginate_by 22 self.page = page 23 self.pagination = None 20 24 21 25 def __repr__(self): 22 26 return '<EasyModel for %s>' % self.model._meta.object_name … … 29 33 return '%s%s/%s/' % (self.site.root_url, self.model._meta.app_label, self.model._meta.module_name) 30 34 31 35 def objects(self, **kwargs): 32 for obj in self.model._default_manager.filter(**kwargs): 36 op = ObjectPaginator(self.model._default_manager.filter(**kwargs), self.paginate_by) 37 self.pagination = { 38 'hits' : op.hits, 39 'pages' : op.pages, 40 'has_next_page' : op.has_next_page(self.page), 41 'has_previous_page' : op.has_previous_page(self.page), 42 'first_on_page' : op.first_on_page(self.page), 43 'last_on_page' : op.last_on_page(self.page), 44 'next_page_url' : "%s?page=%d" % (self.url(), self.page+1), 45 'previous_page_url' : "%s?page=%d" % (self.url(), self.page-1), 46 } 47 for obj in op.get_page(self.page): 33 48 yield EasyInstance(self, obj) 34 49 35 50 def object_by_pk(self, pk): … … 85 100 return '<EasyInstance for %s (%s)>' % (self.model.model._meta.object_name, self.instance._get_pk_val()) 86 101 87 102 def __str__(self): 88 val = str(self.instance) 89 if len(val) > 30: 90 return val[:30] + '...' 91 return val 103 return str(self.instance) 92 104 93 105 def pk(self): 94 106 return self.instance._get_pk_val() -
django/contrib/databrowse/templates/databrowse/model_detail.html
16 16 {% endfor %} 17 17 </ul> 18 18 19 <div class="pagination"> 20 {% if model.pagination.has_previous_page %} 21 <a href="{{ model.pagination.previous_page_url }}" class="prev">← Previous Page</a> 22 {% endif %} 23 {% if model.pagination.has_next_page %} 24 <a href="{{ model.pagination.next_page_url }}" class="next">Next Page →</a> 25 {% endif %} 26 </div> 19 27 {% endblock %} -
django/contrib/databrowse/templates/databrowse/homepage.html
1 1 {% extends "databrowse/base.html" %} 2 {% load databrowse %} 2 3 3 4 {% block title %}Databrowse{% endblock %} 4 5 … … 11 12 <h2><a href="{{ model.url }}">{{ model.verbose_name_plural|capfirst }}</a></h2> 12 13 <p> 13 14 {% for object in model.sample_objects %} 14 <a href="{{ object.url }}">{{ object }}</a>,15 <a href="{{ object.url }}">{{ object|truncatechar:"30" }}</a>, 15 16 {% endfor %} 16 17 <a class="more" href="{{ model.url }}">More →</a> 17 18 </p> -
django/contrib/databrowse/templates/databrowse/base.html
47 47 #header a:hover { text-decoration:underline; } 48 48 /* CONTENT */ 49 49 #content { background:#fff; border-bottom:1px solid #ddd; padding:0 20px; } 50 /* PAGINATION */ 51 .pagination { width: 50%; margin-left: auto; margin-right: auto; font-size: 1.4em; } 52 .pagination a.prev { float: left; } 53 .pagination a.next { float: right; } 50 54 </style> 51 55 </head> 52 56 <body id="{% block bodyid %}page{% endblock %}"> -
django/contrib/databrowse/sites.py
59 59 return plugin.model_view(request, self, rest_of_url) 60 60 61 61 def main_view(self, request): 62 easy_model = EasyModel(self.site, self.model) 62 if "page" in request.GET: 63 page = int(request.GET['page']) 64 else: 65 page = 0 66 easy_model = EasyModel(self.site, self.model, page=page) 63 67 html_snippets = '\n'.join([p.model_index_html(request, self.model, self.site) for p in self.plugins.values()]) 64 68 return render_to_response('databrowse/model_detail.html', { 65 69 'model': easy_model,