diff --git a/pyi2phosts/latest/views.py b/pyi2phosts/latest/views.py
index 8871c9b..54bcc0a 100644
--- a/pyi2phosts/latest/views.py
+++ b/pyi2phosts/latest/views.py
@@ -3,7 +3,7 @@ import datetime
from django.conf import settings
from pyi2phosts.postkey.models import i2phost
-from pyi2phosts.lib.generic import HostsListsView
+from pyi2phosts.lib.generic import LocalObjectList
def get_latest():
now_date = datetime.datetime.utcnow()
@@ -12,7 +12,7 @@ def get_latest():
date_added__range=(start_date, now_date)).order_by("-date_added")[:settings.LATEST_HOSTS_COUNT]
return qs
-class LatestHostsListsView(HostsListsView):
+class LatestHostsListsView(LocalObjectList):
""" Renders list of latest active hosts added """
def get_context_data(self, **kwargs):
@@ -26,5 +26,5 @@ class LatestHostsListsView(HostsListsView):
queryset = get_latest()
template_name = 'latest.html'
- template_object_name = 'host_list'
+ context_object_name = 'host_list'
paginate_by = 40
diff --git a/pyi2phosts/lib/generic.py b/pyi2phosts/lib/generic.py
index c794334..53ed292 100755
--- a/pyi2phosts/lib/generic.py
+++ b/pyi2phosts/lib/generic.py
@@ -44,7 +44,23 @@ class FaqView(LocalObjectList):
class HostsListsView(LocalObjectList):
""" Renders list of active hosts """
- queryset = i2phost.objects.filter(activated=True).order_by("name")
- template_name = 'browse.html'
+ def get_queryset(self):
+ allowed_orders = ['name', 'last_seen', 'date_added']
+ self.order_by = self.request.GET.get('order', 'name')
+ if self.order_by not in allowed_orders:
+ self.order_by = 'name'
+ qs = super(HostsListsView, self).get_queryset()
+ return qs.order_by(self.order_by)
+
+ def get_context_data(self, **kwargs):
+ """ we should pass order_by to template to not lose it while paginating """
+ context = super(LocalObjectList, self).get_context_data(**kwargs)
+ context.update({
+ 'order': self.order_by,
+ })
+ return context
+
+ queryset = i2phost.objects.filter(activated=True)
+ template_name = 'browse.html'
context_object_name = 'host_list'
paginate_by = 40
diff --git a/pyi2phosts/templates/browse.html b/pyi2phosts/templates/browse.html
index 781beec..b061cd6 100644
--- a/pyi2phosts/templates/browse.html
+++ b/pyi2phosts/templates/browse.html
@@ -7,8 +7,10 @@
{% endblock %}
{% block content %}
+{% block table_header %}