19 |
19 |
|
20 |
20 |
from django.shortcuts import resolve_url
|
21 |
21 |
from django.core.urlresolvers import reverse
|
22 |
|
from django.views.generic import TemplateView, View
|
|
22 |
from django.views.generic import ListView, View
|
23 |
23 |
from django.http import HttpResponse, HttpResponseRedirect
|
24 |
24 |
from django.utils.translation import ugettext as _
|
25 |
25 |
from django.contrib.auth import logout as auth_logout
|
... | ... | |
54 |
54 |
return redirect_to_login(request.build_absolute_uri())
|
55 |
55 |
|
56 |
56 |
|
57 |
|
class HomepageView(AuthorizationMixin, TemplateView):
|
|
57 |
class HomepageView(AuthorizationMixin, ListView):
|
58 |
58 |
template_name = 'bijoe/homepage.html'
|
|
59 |
model = Visualization
|
|
60 |
context_object_name = 'visualizations'
|
|
61 |
paginate_by = 20
|
59 |
62 |
|
60 |
63 |
def get_context_data(self, **kwargs):
|
61 |
64 |
ctx = super(HomepageView, self).get_context_data(**kwargs)
|
62 |
|
ctx['visualizations'] = Visualization.all_visualizations()
|
63 |
65 |
ctx['warehouses'] = sorted((Engine(w) for w in get_warehouses()),
|
64 |
66 |
key=lambda w: w.label)
|
65 |
67 |
return ctx
|
66 |
68 |
|
|
69 |
def get_queryset(self):
|
|
70 |
return self.model.all_visualizations()
|
|
71 |
|
67 |
72 |
def get(self, request, *args, **kwargs):
|
68 |
|
ctx = self.get_context_data()
|
69 |
|
if not len(ctx['visualizations']) and len(ctx['warehouses']) == 1:
|
|
73 |
if not len(self.get_queryset()) and len(get_warehouses()) == 1:
|
70 |
74 |
return HttpResponseRedirect(reverse('warehouse', kwargs={'warehouse': ctx['warehouses'][0].name}),
|
71 |
75 |
status=307)
|
72 |
76 |
return super(HomepageView, self).get(request, *args, **kwargs)
|