1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-01-22 04:24:15 +00:00

Allow different ordering in /browse/

This commit is contained in:
Hidden Z 2015-10-26 18:45:39 +00:00
parent 1773b69aa7
commit 75de76cf4c
4 changed files with 30 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -7,8 +7,10 @@
{% endblock %}
{% block content %}
{% block table_header %}
<table>
<tr><td>{% trans "Host" %}</td><td>{% trans "Last seen" %}</td><td>{% trans "Date added" %}</td><td>{% trans "Description" %}</td></tr>
<tr><td><a href="?order=name">{% trans "Host" %}</a></td><td><a href="?order=last_seen">{% trans "Last seen" %}</a></td><td><a href="?order=date_added">{% trans "Date added" %}</a></td><td>{% trans "Description" %}</td></tr>
{% endblock table_header %}
{% for host in host_list %}
<tr><td><a href="http://{{ host.name }}/?i2paddresshelper={{host.b64hash}}">{{ host.name }}</a></td><td>{{ host.last_seen }}</td>
<td>{{ host.date_added }}</td><td>{{ host.description }}</td></tr>
@ -19,14 +21,14 @@
<div class="pager">
{% if page_obj.has_previous %}
<span class="page">
<a href="?page={{ page_obj.previous_page_number }}">&lt; Prev</a>
<a href="?page={{ page_obj.previous_page_number }}&order={{ order }}">&lt; Prev</a>
</span>
{% endif %}
<span class="current">Page {{ page_obj.number }} of {{ paginator.num_pages }}</span>
{% if page_obj.has_next %}
<span class="page"><a href="?page={{ page_obj.next_page_number }}">Next &gt;</a></span>
<span class="page"><a href="?page={{ page_obj.next_page_number }}&order={{ order }}">Next &gt;</a></span>
{% endif %}
{{ paginator.count }} {% trans "hosts total" %}

View File

@ -7,3 +7,7 @@
{% endblocktrans %}
<a href={% url 'latest-rss' %}><img src="/static/rss-grey-18.png" border="0" width="18" height="18" alt="rss"></a></h3>
{% endblock %}
{% block table_header %}
<table>
<tr><td>{% trans "Host" %}</td><td>{% trans "Last seen" %}</td><td>{% trans "Date added" %}</td><td>{% trans "Description" %}</td></tr>
{% endblock table_header %}