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:
parent
1773b69aa7
commit
75de76cf4c
@ -3,7 +3,7 @@ import datetime
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from pyi2phosts.postkey.models import i2phost
|
from pyi2phosts.postkey.models import i2phost
|
||||||
from pyi2phosts.lib.generic import HostsListsView
|
from pyi2phosts.lib.generic import LocalObjectList
|
||||||
|
|
||||||
def get_latest():
|
def get_latest():
|
||||||
now_date = datetime.datetime.utcnow()
|
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]
|
date_added__range=(start_date, now_date)).order_by("-date_added")[:settings.LATEST_HOSTS_COUNT]
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
class LatestHostsListsView(HostsListsView):
|
class LatestHostsListsView(LocalObjectList):
|
||||||
""" Renders list of latest active hosts added """
|
""" Renders list of latest active hosts added """
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
@ -26,5 +26,5 @@ class LatestHostsListsView(HostsListsView):
|
|||||||
|
|
||||||
queryset = get_latest()
|
queryset = get_latest()
|
||||||
template_name = 'latest.html'
|
template_name = 'latest.html'
|
||||||
template_object_name = 'host_list'
|
context_object_name = 'host_list'
|
||||||
paginate_by = 40
|
paginate_by = 40
|
||||||
|
@ -44,7 +44,23 @@ class FaqView(LocalObjectList):
|
|||||||
class HostsListsView(LocalObjectList):
|
class HostsListsView(LocalObjectList):
|
||||||
""" Renders list of active hosts """
|
""" Renders list of active hosts """
|
||||||
|
|
||||||
queryset = i2phost.objects.filter(activated=True).order_by("name")
|
def get_queryset(self):
|
||||||
template_name = 'browse.html'
|
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'
|
context_object_name = 'host_list'
|
||||||
paginate_by = 40
|
paginate_by = 40
|
||||||
|
@ -7,8 +7,10 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
{% block table_header %}
|
||||||
<table>
|
<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 %}
|
{% for host in host_list %}
|
||||||
<tr><td><a href="http://{{ host.name }}/?i2paddresshelper={{host.b64hash}}">{{ host.name }}</a></td><td>{{ host.last_seen }}</td>
|
<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>
|
<td>{{ host.date_added }}</td><td>{{ host.description }}</td></tr>
|
||||||
@ -19,14 +21,14 @@
|
|||||||
<div class="pager">
|
<div class="pager">
|
||||||
{% if page_obj.has_previous %}
|
{% if page_obj.has_previous %}
|
||||||
<span class="page">
|
<span class="page">
|
||||||
<a href="?page={{ page_obj.previous_page_number }}">< Prev</a>
|
<a href="?page={{ page_obj.previous_page_number }}&order={{ order }}">< Prev</a>
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<span class="current">Page {{ page_obj.number }} of {{ paginator.num_pages }}</span>
|
<span class="current">Page {{ page_obj.number }} of {{ paginator.num_pages }}</span>
|
||||||
|
|
||||||
{% if page_obj.has_next %}
|
{% if page_obj.has_next %}
|
||||||
<span class="page"><a href="?page={{ page_obj.next_page_number }}">Next ></a></span>
|
<span class="page"><a href="?page={{ page_obj.next_page_number }}&order={{ order }}">Next ></a></span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ paginator.count }} {% trans "hosts total" %}
|
{{ paginator.count }} {% trans "hosts total" %}
|
||||||
|
|
||||||
|
@ -7,3 +7,7 @@
|
|||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
<a href={% url 'latest-rss' %}><img src="/static/rss-grey-18.png" border="0" width="18" height="18" alt="rss"></a></h3>
|
<a href={% url 'latest-rss' %}><img src="/static/rss-grey-18.png" border="0" width="18" height="18" alt="rss"></a></h3>
|
||||||
{% endblock %}
|
{% 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 %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user