views: add pagination to visualizations list (#27410)
This commit is contained in:
parent
79a965f328
commit
6d790559a4
|
@ -172,5 +172,7 @@ BIJOE_SCHEMAS = []
|
|||
|
||||
BIJOE_CACHE = True
|
||||
|
||||
PAGE_LENGTH = 20
|
||||
|
||||
if 'BIJOE_SETTINGS_FILE' in os.environ:
|
||||
execfile(os.environ['BIJOE_SETTINGS_FILE'])
|
||||
|
|
|
@ -9,3 +9,4 @@
|
|||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% include "gadjo/pagination.html" %}
|
||||
|
|
|
@ -17,9 +17,10 @@
|
|||
import json
|
||||
import urllib
|
||||
|
||||
from django.conf import settings
|
||||
from django.shortcuts import resolve_url
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.views.generic import TemplateView, View
|
||||
from django.views.generic import ListView, View
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.contrib.auth import logout as auth_logout
|
||||
|
@ -54,20 +55,27 @@ class AuthorizationMixin(object):
|
|||
return redirect_to_login(request.build_absolute_uri())
|
||||
|
||||
|
||||
class HomepageView(AuthorizationMixin, TemplateView):
|
||||
class HomepageView(AuthorizationMixin, ListView):
|
||||
template_name = 'bijoe/homepage.html'
|
||||
model = Visualization
|
||||
context_object_name = 'visualizations'
|
||||
paginate_by = settings.PAGE_LENGTH
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super(HomepageView, self).get_context_data(**kwargs)
|
||||
ctx['visualizations'] = Visualization.all_visualizations()
|
||||
ctx['warehouses'] = sorted((Engine(w) for w in get_warehouses()),
|
||||
key=lambda w: w.label)
|
||||
ctx['request'] = self.request
|
||||
return ctx
|
||||
|
||||
def get_queryset(self):
|
||||
return self.model.all_visualizations()
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
ctx = self.get_context_data()
|
||||
if not len(ctx['visualizations']) and len(ctx['warehouses']) == 1:
|
||||
return HttpResponseRedirect(reverse('warehouse', kwargs={'warehouse': ctx['warehouses'][0].name}),
|
||||
warehouses = get_warehouses()
|
||||
if not len(self.get_queryset()) and len(warehouses) == 1:
|
||||
engine = Engine(warehouses[0])
|
||||
return HttpResponseRedirect(reverse('warehouse', kwargs={'warehouse': engine.name}),
|
||||
status=307)
|
||||
return super(HomepageView, self).get(request, *args, **kwargs)
|
||||
|
||||
|
|
|
@ -186,10 +186,16 @@ class VisualizationsView(views.AuthorizationMixin, ListView):
|
|||
template_name = 'bijoe/visualizations.html'
|
||||
model = models.Visualization
|
||||
context_object_name = 'visualizations'
|
||||
paginate_by = settings.PAGE_LENGTH
|
||||
|
||||
def get_queryset(self):
|
||||
return self.model.all_visualizations()
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super(VisualizationsView, self).get_context_data(**kwargs)
|
||||
ctx['request'] = self.request
|
||||
return ctx
|
||||
|
||||
|
||||
class RenameVisualization(views.AuthorizationMixin, UpdateView):
|
||||
model = models.Visualization
|
||||
|
|
|
@ -2,3 +2,4 @@ BIJOE_CACHE = False
|
|||
BIJOE_INIT_SQL = [
|
||||
'SET lc_time = \'fr_FR.UTF-8\'',
|
||||
]
|
||||
PAGE_LENGTH = 0
|
||||
|
|
Loading…
Reference in New Issue